Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
run: function(drab_return) {
this.drab_return = drab_return
this.self = this
this.myid = uuid.v1()
this.onload_launched = false
this.already_connected = false
this.path = location.pathname
// disable all the Drab-related objects
// they will be re-enable on connection
this.disable_drab_objects(true)
let socket = new Socket("/drab/socket", {params: {token: window.userToken}})
socket.connect()
this.channel = socket.channel(
`drab:${this.path}`,
{
path: this.path,
drab_return: this.drab_return
})
this.channel.join()
.receive("error", resp => { console.log("Unable to join", resp) })
.receive("ok", resp => this.connected(resp, this))
// socket.onError(function(ev) {console.log("SOCKET ERROR", ev);});
// socket.onClose(function(ev) {console.log("SOCKET CLOSE", ev);});
socket.onClose((event) => {
// on disconnect
this.disable_drab_objects(true)
})
// NOTE: The contents of this file will only be executed if
// you uncomment its entry in "assets/js/app.js".
// 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";
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`,
// which authenticates the session and assigns a `:current_user`.
// If the current user exists you can assign the user's token in
// the connection for use in the layout.
//
// In your "lib/web/router.ex":
//
// pipeline :browser do
// ...
// plug MyAuth
// plug :put_user_token
// end
//
// defp put_user_token(conn, _) do
static init(){
let socket = new Socket("/socket", {
logger: ((kind, msg, data) => { console.log(`${kind}: ${msg}`, data) })
})
socket.connect({user_id: "123"})
var $status = $("#status")
var $messages = $("#messages")
var $input = $("#message-input")
var $username = $("#username")
socket.onOpen( ev => console.log("OPEN", ev) )
socket.onError( ev => console.log("ERROR", ev) )
socket.onClose( e => console.log("CLOSE", e))
var chan = socket.channel("rooms:lobby", {})
chan.join().receive("ignore", () => console.log("auth error"))
.receive("ok", () => console.log("join ok"))
const initConnection = (): void => {
const socket = new Socket(SOCKET_URL, { params: {} });
socket.connect();
const connChannel = socket.channel('room:'.concat(props.roomId));
connChannel
.join(TIMEOUT_DURATION)
.receive(ChannelResponse.OK, handleConnect)
.receive(ChannelResponse.ERROR, ({ reason }) => console.log(CHANNEL_JOIN_ERROR, reason))
.receive(ChannelResponse.TIMEOUT, () => console.log(CHANNEL_JOIN_TIMEOUT));
setChannel(connChannel);
};
async authenticate(email, signal) {
const reticulumServer = RETICULUM_SERVER;
const socketUrl = `wss://${reticulumServer}/socket`;
const socket = new Socket(socketUrl, { params: { session_id: uuid() } });
socket.connect();
const channel = socket.channel(`auth:${uuid()}`);
const onAbort = () => socket.disconnect();
signal.addEventListener("abort", onAbort);
await new Promise((resolve, reject) =>
channel
.join()
.receive("ok", resolve)
.receive("error", err => {
signal.removeEventListener("abort", onAbort);
reject(err);
})
return dispatch => {
//Set a clientId for the client
let clientId = localStorage.getItem('thorium_clientId');
if (!clientId) {
clientId = guid();
localStorage.setItem('thorium_clientId',clientId);
}
let socket = new Socket('/socket', {params: {client_id: clientId}});
socket.connect();
let presence = socket.channel("presence:topic");
presence.join();
presence.on("presence_state", state => {
dispatch(presenceState(state));
});
presence.on("presence_diff", diff => {
dispatch(presenceDiff(diff));
});
};
}
connect() {
this.socket = new Socket(this.url(), {params: {token: this.token, client: 'atom'}})
this.socket.connect()
this.joinChannel()
}
connect() {
const { state, jwt } = this.context;
const token = state.get('jwt') || jwt.get();
if (!socket) {
socket = new Socket(`wss://${document.location.host}/socket`, {
params: {
guardian_token: token,
},
});
socket.connect();
window.socket = socket;
debug('Connecting to socket', socket);
}
},