wenlele
2 years ago
14 changed files with 79 additions and 74 deletions
@ -1,9 +1,9 @@ |
|||||
'use strict'; |
'use strict'; |
||||
|
|
||||
import * as global from './global' |
import * as global from './global' |
||||
import * as socket from './webSocket'; |
// import * as socket from './webSocket';
|
||||
|
|
||||
export default { |
export default { |
||||
...global, |
...global, |
||||
...socket, |
// ...socket,
|
||||
}; |
}; |
@ -1,33 +1,33 @@ |
|||||
'use strict'; |
'use strict'; |
||||
import io from 'socket.io-client'; |
import io from 'socket.io-client'; |
||||
|
|
||||
export const INIT_WEB_SOCKET = 'INIT_WEB_SOCKET' |
// export const INIT_WEB_SOCKET = 'INIT_WEB_SOCKET'
|
||||
export function initWebSocket ({ ioUrl, token }) { |
// export function initWebSocket ({ ioUrl, token }) {
|
||||
if (!ioUrl) { |
// if (!ioUrl) {
|
||||
ioUrl = localStorage.getItem('apiRoot') |
// ioUrl = localStorage.getItem('apiRoot')
|
||||
} |
// }
|
||||
if (!token) { |
// if (!token) {
|
||||
const user = sessionStorage.getItem('user') |
// const user = sessionStorage.getItem('user')
|
||||
if (user) { |
// if (user) {
|
||||
token = JSON.parse(user).token |
// token = JSON.parse(user).token
|
||||
} |
// }
|
||||
} |
// }
|
||||
if (!ioUrl || !token) { |
// if (!ioUrl || !token) {
|
||||
return { |
// return {
|
||||
type: '', |
// type: '',
|
||||
} |
// }
|
||||
} |
// }
|
||||
return dispatch => { |
// return dispatch => {
|
||||
const socket = io(ioUrl, { |
// const socket = io(ioUrl, {
|
||||
query: { |
// query: {
|
||||
token: token |
// token: token
|
||||
}, |
// },
|
||||
}); |
// });
|
||||
dispatch({ |
// dispatch({
|
||||
type: INIT_WEB_SOCKET, |
// type: INIT_WEB_SOCKET,
|
||||
payload: { |
// payload: {
|
||||
socket: socket |
// socket: socket
|
||||
} |
// }
|
||||
}) |
// })
|
||||
} |
// }
|
||||
} |
// }
|
@ -1,21 +1,21 @@ |
|||||
'use strict'; |
// 'use strict';
|
||||
import * as actionTypes from '../actions/webSocket'; |
// import * as actionTypes from '../actions/webSocket';
|
||||
import Immutable from 'immutable'; |
// import Immutable from 'immutable';
|
||||
|
|
||||
const initState = { |
// const initState = {
|
||||
socket: null, |
// socket: null,
|
||||
}; |
// };
|
||||
|
|
||||
function webSocket (state = initState, action) { |
// function webSocket (state = initState, action) {
|
||||
const payload = action.payload; |
// const payload = action.payload;
|
||||
switch (action.type) { |
// switch (action.type) {
|
||||
case actionTypes.INIT_WEB_SOCKET: |
// case actionTypes.INIT_WEB_SOCKET:
|
||||
return Immutable.fromJS(state).merge({ |
// return Immutable.fromJS(state).merge({
|
||||
socket: payload.socket, |
// socket: payload.socket,
|
||||
}).toJS(); |
// }).toJS();
|
||||
default: |
// default:
|
||||
return state; |
// return state;
|
||||
} |
// }
|
||||
} |
// }
|
||||
|
|
||||
export default webSocket; |
// export default webSocket;
|
Loading…
Reference in new issue