Skip to content

Instantly share code, notes, and snippets.

@NullVoxPopuli
Last active July 8, 2016 13:21
Show Gist options
  • Save NullVoxPopuli/81f0b9528c3ddd608737af4261f4b737 to your computer and use it in GitHub Desktop.
Save NullVoxPopuli/81f0b9528c3ddd608737af4261f4b737 to your computer and use it in GitHub Desktop.
// npm install --save actioncable
import * as ActionCable from 'actioncable/lib/assets/compiled/action_cable';
let myUid = '123';
let url = `ws://mesh-relay-in-us-1.herokuapp.com?uid=${myUid}`;
const cable = ActionCable.createConsumer(url);
const channel = cable.subscriptions.create({ channel: 'MeshRelayChannel', }, {
connected: () => {
console.log('connected');
},
disconnected: (data) => {
console.log(data);
console.log('disconnected');
},
rejected: (data) => {
console.log(data);
console.log('rejected');
},
received: (data) => {
console.log(data);
console.log('received');
}
});
setTimeout(() => {
channel.send({ to: myUid, message: 'test message', action: 'chat' });
}, 5000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment