2016-10-21 13:29:04 +00:00
|
|
|
const {
|
2016-10-19 00:29:21 +00:00
|
|
|
// server sendable, client receivable
|
2016-10-21 13:29:04 +00:00
|
|
|
JUNTO_UPDATED,
|
2016-10-19 00:29:21 +00:00
|
|
|
|
|
|
|
// server receivable, client sendable
|
2016-10-21 13:29:04 +00:00
|
|
|
JOIN_CALL,
|
|
|
|
LEAVE_CALL,
|
2016-10-19 00:29:21 +00:00
|
|
|
JOIN_MAP,
|
2017-01-03 21:12:58 +00:00
|
|
|
LEAVE_MAP
|
2018-03-05 00:30:17 +00:00
|
|
|
} = require('../src/Metamaps/Realtime/events')
|
2016-10-19 00:29:21 +00:00
|
|
|
|
2016-11-07 20:25:08 +00:00
|
|
|
module.exports = function(io, store) {
|
2016-10-21 13:29:04 +00:00
|
|
|
store.subscribe(() => {
|
|
|
|
console.log(store.getState())
|
|
|
|
io.sockets.emit(JUNTO_UPDATED, store.getState())
|
|
|
|
})
|
2016-10-19 00:29:21 +00:00
|
|
|
|
2016-11-07 20:25:08 +00:00
|
|
|
io.on('connection', function(socket) {
|
2016-10-21 13:29:04 +00:00
|
|
|
io.sockets.emit(JUNTO_UPDATED, store.getState())
|
2016-10-19 00:29:21 +00:00
|
|
|
|
2016-10-21 13:29:04 +00:00
|
|
|
socket.on(JOIN_MAP, data => store.dispatch({ type: JOIN_MAP, payload: data }))
|
|
|
|
socket.on(LEAVE_MAP, () => store.dispatch({ type: LEAVE_MAP, payload: socket }))
|
|
|
|
socket.on(JOIN_CALL, data => store.dispatch({ type: JOIN_CALL, payload: data }))
|
|
|
|
socket.on(LEAVE_CALL, () => store.dispatch({ type: LEAVE_CALL, payload: socket }))
|
|
|
|
socket.on('disconnect', () => store.dispatch({ type: 'DISCONNECT', payload: socket }))
|
2016-10-19 00:29:21 +00:00
|
|
|
})
|
|
|
|
}
|