Skip to content

Instantly share code, notes, and snippets.

@darui00kara
Last active August 29, 2015 14:22
Show Gist options
  • Save darui00kara/0c874d31b9bd43ffcd54 to your computer and use it in GitHub Desktop.
Save darui00kara/0c874d31b9bd43ffcd54 to your computer and use it in GitHub Desktop.
import {Socket} from "phoenix"
// let socket = new Socket("/ws")
// socket.connect()
// let chan = socket.chan("topic:subtopic", {})
// chan.join().receive("ok", chan => {
// console.log("Success!")
// })
let chatInput = $("#chat-input")
let messagesContainer = $("#messages")
let socket = new Socket("/ws")
socket.connect()
let chan = socket.chan("rooms:lobby", {})
chatInput.on("keypress", event => {
if(event.keyCode === 13){
chan.push("new_msg", {body: chatInput.val()})
chatInput.val("")
}
})
chan.on("new_msg", payload => {
messagesContainer.append(`<br/>[${Date()}] ${payload.body}`)
})
chan.join().receive("ok", chan => {
console.log("Welcome to Phoenix Chat!")
})
let App = {
}
export default App
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment