Last active
June 25, 2025 14:55
-
-
Save kryptykphysh/2aef769205d3599ad3c3d314c2f190b1 to your computer and use it in GitHub Desktop.
simple chat
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
import ActionCable from "actioncable"; | |
export default Ember.Component.extend({ | |
setupSubscription: Ember.on('init', function () { | |
const consumer = ActionCable.createConsumer("ws://app.rails.localhost:3000/cable"); | |
console.log(consumer); | |
const subscription = consumer.subscriptions.create({ | |
channel: 'MessageChannel', | |
room: 'messages' | |
}, { | |
received: (data) => { | |
console.log(data); | |
this.get('messages').pushObject({ | |
username: data.username, | |
body: data.body, | |
}); | |
}, | |
}); | |
this.set('subscription', subscription); | |
}), | |
actions: { | |
sendMessage() { | |
this.get('subscription').send({ | |
username: this.get('username'), | |
body: this.get('body'), | |
}); | |
}, | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment