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/header.inc.php';
$controller->output_view();
// 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/footer.inc.php';
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/footer.inc.php :
</footer>
<script src=" http://js.pusher.com/1.12/pusher.min.js"></script >
<script src=" http://code.jquery.com/jquery-1.8.2.min.js"></script >
 
Search WWH ::




Custom Search