import Ember from 'ember';
export default Ember.Controller.extend({
cableService: Ember.inject.service('cable'),
consumer: null,
setupConsumer: Ember.on('init', function() {
var consumer = this.get('cableService').createConsumer('ws://localhost:4200/cable');
consumer.subscriptions.create("NotificationChannel", {
connected() {
this.perform('hello', { foo: 'bar' });
this.perform('hello');
},
received(data) {
Ember.debug( "received(data) -> " + Ember.inspect(data) );
},
disconnected() {
Ember.debug("NotificationChannel#disconnected");
}
});
const subscription = consumer.subscriptions.create({ channel: 'NotificationChannel', room: 'Best Room' }, {
received: (data) => {
this.updateRecord(data);
}
});
var channelMixin = Ember.Mixin.create({
store: Ember.inject.service(),
received(data) {
this.get("store").pushPayload(data);
}
});
consumer.subscriptions.create({ channel: 'NotificationChannel' }, channelMixin);
subscription.perform("your_channel_action", { hey: "hello" });
this.set('consumer', consumer);
}),
updateRecord(data) {
Ember.debug( "updateRecord(data) -> " + Ember.inspect(data) );
},
isConnecting: Ember.computed.readOnly('consumer.isConnecting'),
nextConnectionAt: Ember.computed.readOnly('consumer.nextConnectionAt'),
});