Last active
August 29, 2015 14:22
-
-
Save darui00kara/0c874d31b9bd43ffcd54 to your computer and use it in GitHub Desktop.
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 {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