HTML and CSS Reference
In-Depth Information
< script >
var APP_KEY = ' <?php echo ( APP_KEY ); ?> ' ;
& lt ; / script & gt ;
The first thing you need to do when adding Pusher to a Web application is include the Pusher
JavaScript library and connect to Pusher. To connect you'll need to use the key which you
grabbed from the Pusher dashboard. Below you can see all that is required to hook up the
front-end application to Pusher.
Include the Pusher JavaScript library after the app.js include:
< script src =" "></ script >
< script src =" "></ script >
< script src =" js/app.js "></ script >
Add the Pusher functionality to app.js :
var pusher = new Pusher ( APP_KEY );
var channel = pusher . subscribe ( 'comments-' + $ ( '#comment_post_ID' ). val ());
channel . bind ( 'new_comment' , displayComment );
This probably looks too easy to be true, so here are the details about what the above code
Creates a new instance of a Pusher object and in doing so connects you to Pusher.
The application to use is defined by the APP_KEY value that you pass in and that we set
up earlier.
Channels provide a great way of organizing streams of real-time data. Here we
are subscribing to comments for the current blog post, uniquely identified by the value of
the comment_post_ID hidden form input element.
Search WWH ::

Custom Search