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

43 lines
1.2 KiB
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 })
})
2020-01-30 07:22:50 +00:00
socket.on('game_connected', (data) => {
console.log(data)
console.log('game_connected received')
2020-02-01 06:22:43 +00:00
dispatch({ type: 'GAMES', message: 'UPDATE_BOARD', body: data })
})
socket.on('update_board', (data) => {
console.log(data)
console.log('update_board received')
dispatch({ type: 'GAMES', message: 'UPDATE_BOARD', body: data.board })
2020-01-30 07:22:50 +00:00
})
return socket;
}
export {
launch
}