node-go/packages/server/play-node-go/src/io.js

31 lines
854 B
JavaScript
Raw Normal View History

import socketIOClient from 'socket.io-client';
import config from './config';
const launch = (nsp, dispatch) => {
const socket = socketIOClient(`${config.socketAddress}/${nsp}`);
2020-01-28 22:33:54 +00:00
socket.on('connected', () => {
dispatch({ type:'SOCKET', message:'CONNECTED', body:{nsp: socket.nsp} });
});
socket.on('connect_error', err => {
dispatch({ type: 'ERR', message:'SOCKET_ERROR', body: { socketError: err }});
});
socket.on('error', err => {
dispatch({ type: 'ERR', message:'SOCKET_ERROR', body: { socketError: err } });
});
2020-01-28 22:33:54 +00:00
socket.on('room_connected', (data) => {
2020-01-28 22:33:54 +00:00
dispatch({ type: 'ROOMS', message: 'CONNECT_ROOM', body: data });
});
2020-01-28 22:33:54 +00:00
socket.on('new_user', (data) => {
console.log('new_user received')
2020-01-28 22:33:54 +00:00
dispatch({ type: 'ROOMS', message: 'NEW_USER', body: data })
})
return socket;
}
export {
launch
}