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.
38 lines
784 B
38 lines
784 B
3 years ago
|
'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')
|
||
|
ioUrl = JSON.parse(ioUrl).root
|
||
|
}
|
||
|
if (!token) {
|
||
|
const user = sessionStorage.getItem('vcmpUser')
|
||
|
if (user) {
|
||
|
token = JSON.parse(user).token
|
||
|
}
|
||
|
}
|
||
|
if (!ioUrl || !token) {
|
||
|
return {
|
||
|
type: '',
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return dispatch => {
|
||
|
const socket = io(
|
||
|
ioUrl
|
||
|
// 'http://10.8.30.7:4000'
|
||
|
, {
|
||
|
query: {
|
||
|
token: token
|
||
|
},
|
||
|
});
|
||
|
dispatch({
|
||
|
type: INIT_WEB_SOCKET,
|
||
|
payload: {
|
||
|
socket: socket
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
}
|