Keep active peer connections after server restart
This commit is contained in:
parent
cd4979c3be
commit
aa7a6927f8
@ -98,7 +98,7 @@ class PeerHandler {
|
||||
const { dispatch, getState, user } = this
|
||||
const state = getState()
|
||||
const message = JSON.parse(new window.TextDecoder('utf-8').decode(buffer))
|
||||
debug('peer: %s, message: %o', user.id, buffer)
|
||||
debug('peer: %s, message: %o', user.id, message)
|
||||
switch (message.type) {
|
||||
case 'file':
|
||||
dispatch(ChatActions.addMessage({
|
||||
|
||||
@ -59,7 +59,7 @@ describe('SocketActions', () => {
|
||||
expect(instances.length).toBe(1)
|
||||
})
|
||||
|
||||
it('adds a peer for each new user and destroys missing peers', () => {
|
||||
it('adds a peer for each new user and keeps active connections', () => {
|
||||
const payload = {
|
||||
users: [userA, userC],
|
||||
initiator: userC.userId,
|
||||
@ -68,7 +68,7 @@ describe('SocketActions', () => {
|
||||
|
||||
// then
|
||||
expect(instances.length).toBe(2)
|
||||
expect((instances[0].destroy as jest.Mock).mock.calls.length).toBe(1)
|
||||
expect((instances[0].destroy as jest.Mock).mock.calls.length).toBe(0)
|
||||
expect((instances[1].destroy as jest.Mock).mock.calls.length).toBe(0)
|
||||
})
|
||||
})
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import * as NotifyActions from '../actions/NotifyActions'
|
||||
import * as PeerActions from '../actions/PeerActions'
|
||||
import * as constants from '../constants'
|
||||
import keyBy from 'lodash/keyBy'
|
||||
import _debug from 'debug'
|
||||
import { Dispatch, GetState } from '../store'
|
||||
import { ClientSocket } from '../socket'
|
||||
@ -46,6 +45,7 @@ class SocketHandler {
|
||||
debug('socket users: %o', users)
|
||||
this.dispatch(NotifyActions.info('Connected users: {0}', users.length))
|
||||
const { peers } = this.getState()
|
||||
debug('active peers: %o', Object.keys(peers))
|
||||
|
||||
users
|
||||
.filter(
|
||||
@ -60,11 +60,6 @@ class SocketHandler {
|
||||
initiator,
|
||||
stream,
|
||||
})(dispatch, getState))
|
||||
|
||||
const newUsersMap = keyBy(users, 'userId')
|
||||
Object.keys(peers)
|
||||
.filter(id => !newUsersMap[id])
|
||||
.forEach(id => peers[id].destroy())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -40,7 +40,7 @@ export default function handleSocket(
|
||||
|
||||
const users = getUsers(room)
|
||||
|
||||
debug('ready: %s, room: %s, users: %o', room, users)
|
||||
debug('ready: %s, room: %s, users: %o', userId, room, users)
|
||||
|
||||
io.to(room).emit('users', {
|
||||
initiator: userId,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user