Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement