HTML and CSS Reference
In-Depth Information
<body>
<h1>Testing Pusher</h1>
<div id="connection_state">&dash;</div>
<p>
This is a simple demo of how easy it is to integrate Pusher
into an application.
</p>
<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;
} );
</script>
</body>
</html>
For each connection state change, the function that is passed as the second parameter to the bind function is
called. We can then update the page to show what the current connection state is.
Now that we know how to detect our connection state, we can look at subscribing to a channel. as mentioned
earlier, channels are identified purely by a name: a string . You don't need to do anything to create a channel or
provision it within pusher. simply by subscribing to it, it exists. You don't even need to worry about using up too
many channels since they're actually just a way of routing data from a publisher (which we've yet to cover) to a
subscriber. so, let's subscribe to a channel and bind to an event on it:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Realtime Web Apps &ndash; Exercise 3-2</title>
</head>
<body>
<h1>Testing Pusher</h1>
<div id="connection_state">&dash;</div>
<p>
This is a simple demo of how easy it is to integrate Pusher
into an application.
</p>
 
Search WWH ::




Custom Search