|
|
|
@ -3,9 +3,9 @@ |
|
|
|
|
|
|
|
|
|
// To use Phoenix channels, the first step is to import Socket
|
|
|
|
|
// and connect at the socket path in "lib/web/endpoint.ex":
|
|
|
|
|
import {Socket} from "phoenix" |
|
|
|
|
import {Socket} from 'phoenix' |
|
|
|
|
|
|
|
|
|
let socket = new Socket("/socket", {params: {token: window.userToken}}) |
|
|
|
|
let socket = new Socket('/socket', {params: {token: window.userToken}}) |
|
|
|
|
|
|
|
|
|
// When you connect, you'll often need to authenticate the client.
|
|
|
|
|
// For example, imagine you have an authentication plug, `MyAuth`,
|
|
|
|
@ -54,9 +54,9 @@ let socket = new Socket("/socket", {params: {token: window.userToken}}) |
|
|
|
|
socket.connect() |
|
|
|
|
|
|
|
|
|
// Now that you are connected, you can join channels with a topic:
|
|
|
|
|
let channel = socket.channel("topic:subtopic", {}) |
|
|
|
|
let channel = socket.channel('topic:subtopic', {}) |
|
|
|
|
channel.join() |
|
|
|
|
.receive("ok", resp => { console.log("Joined successfully", resp) }) |
|
|
|
|
.receive("error", resp => { console.log("Unable to join", resp) }) |
|
|
|
|
.receive('ok', resp => { console.log('Joined successfully', resp) }) |
|
|
|
|
.receive('error', resp => { console.log('Unable to join', resp) }) |
|
|
|
|
|
|
|
|
|
export default socket |
|
|
|
|