'use strict'; import io from 'socket.io-client'; export const INIT_WEB_SOCKET = 'INIT_WEB_SOCKET' export function initWebSocket ({ ioUrl, token }) { if (!ioUrl) { ioUrl = localStorage.getItem('apiRoot') } if (!token) { const user = sessionStorage.getItem('user') if (user) { token = JSON.parse(user).token } } if (!ioUrl || !token) { return { type: '', } } return dispatch => { const socket = io(ioUrl, { query: { token: token }, }); dispatch({ type: INIT_WEB_SOCKET, payload: { socket: socket } }) } }