O'Reilly logo

Ember.js Cookbook by Erik Hanchett

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using Ember with Sockets

WebSockets make it possible to open a communication session with a server. Ember.js does not handle this natively. However, there are some easy-to-use add-ons that can be used to make this possible.

How to do it...

  1. In a new application, generate a new route and install the WebSockets add-on:
    $ ember install ember-websockets
    $ ember g component w-s
    $ ember g route ws
    

    This will install the component route and add-on that we need to begin.

  2. In the components template folder, edit the w-s.hbs file:
    // app/templates/components/w-s.hbs
    Welcome Chat!<br><br>
    
    Received Message: {{message}}<br>
    <button id="sendButtonPressed" {{action "sendButtonPressed"}}>Press Me</button>

    In this template, we have a message property and button that sends ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required