HTML and CSS Reference
In-Depth Information
<script src=" http://js.pusher.com/1.12/pusher.min.js"></script >
<script>
var pusher = new Pusher( '079be339124bac43c45c' );
pusher.connection.bind( 'state_change', function( change ) {
document.getElementById( 'connection_state' ).innerHTML = change.current;
} );
var channel = pusher.subscribe( 'test_channel' );
channel.bind( 'my_event', function( data ) {
alert( data );
} );
</script>
</body>
</html>
as with handling connection events, the event handler is as simple as they come: when the event is triggered,
the message being sent is displayed in an alert box.
Navigate to your htML file in one browser window; within another, go to the event Creator, which can be found
within the pusher Dashboard for your app. You'll be presented with the event Creator form. enter details that
correspond to the Javascript code we've just written; the channel name should be test_channel, and the event
name should be my_event. enter some text into the event Data text area and click the send event button
(see Figure 3-3 ).
Figure 3-3. Pusher Event Creator
 
Search WWH ::




Custom Search