HTML and CSS Reference
In-Depth Information
Figure 10-7. The answer event in the console
Implementing Realtime on the Front End
Now that the back end of the app is triggering events, the front end needs to listen for them.
Subscribing to the Channel
The first step is to create a JavaScript Pusher object and use it to subscribe to the room's channel.
Determining the Channel Name
Before subscribing to the channel, you first need to create a new template variable that holds the proper channel
name. In index.php , add the following bold code to generate the channel name:
require_once SYS_PATH . '/inc/';
// Configures the Pusher channel if we're in a room
$channel = !empty($uri_array[0]) ? 'room_' . $uri_array[0] : 'default';
require_once SYS_PATH . '/inc/';
Adding the Channel Subscription JavaScript
Now that the channel name is determined, create a new Pusher object and subscribe to the channel by adding the
following bold code in system/inc/ :
<script src=""></script >
<script src=""></script >
Search WWH ::

Custom Search