Developer's Guide
Down to the details
Embedding the client
To enable Beaconpush on your web site you need to include our JavaScript client. The client will connect to Beaconpush using the best transport it see fit - be it WebSockets, Comet or Flash. With a connection established, your web page's visitors will start receiving messages sent through Beaconpush.
Use the API test page or integrate Beaconpush into your favorite web framework. It's all REST, you know! For the duration of your users on the web page, the connection will remain open.
A descriptive example
Include the line below before the closing </body> tag on your web page. We recommend you serving this client from our servers to ensure compatibility between updates.
<script type="text/javascript" src="http://cdn.beaconpush.com/clients/client-1.js"></script>
The second step is to configure the JavaScript client.
<script type="text/javascript">
Beacon.connect('b58ae219', ['frontpage', 'chat'], {log: true});
Beacon.listen(function (message) { alert(message); });
</script>
In short, this will connect to Beaconpush using the API key 'b58ae219', listening to the channels 'frontpage' and 'chat'. Logging will be enabled as you can see by the last argument. A callback function is also attached to get notified when new messages arrive. Simple, eh?
JavaScript API
Beacon.connect(apiKey, channels, options)
Connects to Beaconpush and starts listening for messages. Usually the first function to get called.
apiKey: Your API key (found under Settings).
channels: Array of channels you want to subscribe to. Each entry should a string with a valid channel name.
options: Object of options. Supports 'log' and 'user'. You can set 'log' to 'true' to enable Firebug logging.
'user' can also be set to a string, overriding the generated user ID.
Beacon.listen(handler)
Registers a callback handler that will get called when new messages arrive.
You can attach multiple listeners by calling this method multiple times.
handler: A JavaScript function with the 'function (message)' signature.