7. Javascript SDK

With the javascript SDK you can easily integrate Spreaker with your website.

What's this?

The SDK enables cross site XHR communication from your website and the Spreaker API. It's a cross browser implementation based on HTML5 ( on supported browser ) and Flash ( oldest browser ).

Features:
  • allows you to make HTTP requests to the Spreaker API in a very simple way (see Api calls)
  • allows you to make API calls on behalf of your website visitors (see Spreaker Connect)
  • allows you to listen any show or radio on Spreaker and building your own player (see Station Player)

Getting Started

Add the code to load the javascript library in your page:

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

    <script>
         function onLoad() {
             // Add your code here ...
        }
     </script>

</head>
<body onload="onLoad()">

    <div id="sp-root"></div>
    <script type="text/javascript" src="http://static.spreaker.net/js/sdk_client.js"></script>

</body>
</html>


Please, note two requirements:
  1. You must add an empty div whose id is sp-root (we suggest you to put this code right before the closing </body> tag)
  2. You can use SP.* functions only after the ready dom event. This is because the sdk initializes itself and becomes ready to use only after the "ready" dom event (implementation provided by most javascript library). If you don't use any javascript library, you can register a callback on the body.onload event (see the example above).


Info

To obtain information about the Javascript SDK, you only need to call the method SP.info()

Example:
console.debug(SP.info());

Output:
{ version: "20110131-000"}


Comments