HTML and CSS Reference
In-Depth Information
•
channel.bind('new_comment',displayComment);
Events
are used to further filter data and are ideal for linking updates to
21
changes in the UI. In this case we want to bind to an event which is triggered whenever a
new comment is added and display it. Because we've already created the
displayComment
function we can just pass in a reference to the call to
bind
.
SENDING REAL-TIME EVENTS USING THE EVENT CREATOR
We can also test out this functionality without writing any server-side code by using the
Event
Creator
for your app which can also be found in the Pusher dashboard. The Event Creator
lets you publish events on a channel through a simple user interface. From the code above we
can see that we want to publish an event named
"new_comment"
on the
"comments-1"
channel. From the earlier test function we also have an example of the test data we can
publish.
REAL-TIME PHP
Again, we've proven that our client-side functionality works without having to write any
server-side code. Now lets add the PHP code we need to trigger the new comment event as
soon as a comment is posted in our comment system.
22
Pusher offers a number of
server-side libraries
which make it easy to publish events in
addition to helping with functionality such as
private channe
l
authentication and providing
23