ember install ember-phoenix
You can import phoenix framework client-side utilities as an ES6 module
import { Socket } from 'ember-phoenix';
let socket = new Socket('/socket', {
logger: ((kind, msg, data) => {
console.log(`${kind}: ${msg}`, data);
})
});
Build a service around a socket (you will usually have only one, since phoenix multiplexes for you)
import PhoenixSocket from 'ember-phoenix/services/phoenix-socket';
export default PhoenixSocket.extend({
init() {
// You may listen to open, "close" and "error"
this.on('open', () => {
console.log('Socket was opened!');
})
},
connect(/*url, options*/) {
const myjwt = "abacnwih12eh12...";
// connect the socket
this._super("wss://myhost.com/socket/mysocket", {
params: {token: myjwt}
});
// join a channel
const channel = this.joinChannel("room:123", {
nickname: "Mike"
});
// add message handlers
channel.on("notification", () => _onNotification(...arguments));
},
_onNotification(message) {
alert(`Notification: ${message}`);
}
});
git clone
this repositorynpm install
bower install
ember server
- Visit your app at http://localhost:4200.
npm test
(Runsember try:testall
to test your addon against multiple Ember versions)ember test
ember test --server
ember build
For more information on using ember-cli, visit http://www.ember-cli.com/.
(c) 2016 Levanto Financial