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.
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.
In the
components
template folder, edit thew-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 an action,sendButtonPressed
. When the action is triggered, a message is sent to the server. Themessage
property will display any messages returned from the server.Update the
w-s.js
component file so that it can...