You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
674 B
33 lines
674 B
'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
|
|
}
|
|
})
|
|
}
|
|
}
|