Make socket automatically do the handshake on each reconnect
This commit is contained in:
parent
46a0b1f7ea
commit
8c0377bdaf
@ -1,7 +1,6 @@
|
|||||||
import socket from '../socket'
|
import socket from '../socket'
|
||||||
import { Dispatch, ThunkResult } from '../store'
|
import { ThunkResult } from '../store'
|
||||||
import { callId } from '../window'
|
import { callId } from '../window'
|
||||||
import { ClientSocket } from '../socket'
|
|
||||||
import * as NotifyActions from './NotifyActions'
|
import * as NotifyActions from './NotifyActions'
|
||||||
import * as SocketActions from './SocketActions'
|
import * as SocketActions from './SocketActions'
|
||||||
|
|
||||||
@ -20,26 +19,15 @@ const initialize = (): InitializeAction => ({
|
|||||||
|
|
||||||
export const init = (): ThunkResult<Promise<void>> =>
|
export const init = (): ThunkResult<Promise<void>> =>
|
||||||
async (dispatch, getState) => {
|
async (dispatch, getState) => {
|
||||||
const socket = await dispatch(connect())
|
socket.on('connect', () => {
|
||||||
|
dispatch(NotifyActions.warning('Connected to server socket'))
|
||||||
dispatch(SocketActions.handshake({
|
dispatch(SocketActions.handshake({
|
||||||
socket,
|
socket,
|
||||||
roomName: callId,
|
roomName: callId,
|
||||||
}))
|
}))
|
||||||
|
dispatch(initialize())
|
||||||
dispatch(initialize())
|
})
|
||||||
}
|
socket.on('disconnect', () => {
|
||||||
|
dispatch(NotifyActions.error('Server socket disconnected'))
|
||||||
export const connect = () => (dispatch: Dispatch) => {
|
|
||||||
return new Promise<ClientSocket>(resolve => {
|
|
||||||
socket.once('connect', () => {
|
|
||||||
resolve(socket)
|
|
||||||
})
|
|
||||||
socket.on('connect', () => {
|
|
||||||
dispatch(NotifyActions.warning('Connected to server socket'))
|
|
||||||
})
|
|
||||||
socket.on('disconnect', () => {
|
|
||||||
dispatch(NotifyActions.error('Server socket disconnected'))
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@ -88,6 +88,10 @@ export function handshake (options: HandshakeOptions) {
|
|||||||
getState,
|
getState,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// remove listeneres to make seocket reusable
|
||||||
|
socket.removeListener(constants.SOCKET_EVENT_SIGNAL, handler.handleSignal)
|
||||||
|
socket.removeListener(constants.SOCKET_EVENT_USERS, handler.handleUsers)
|
||||||
|
|
||||||
socket.on(constants.SOCKET_EVENT_SIGNAL, handler.handleSignal)
|
socket.on(constants.SOCKET_EVENT_SIGNAL, handler.handleSignal)
|
||||||
socket.on(constants.SOCKET_EVENT_USERS, handler.handleUsers)
|
socket.on(constants.SOCKET_EVENT_USERS, handler.handleUsers)
|
||||||
|
|
||||||
|
|||||||
@ -43,6 +43,7 @@ function addStream (
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (userStreams.streams.map(s => s.stream).indexOf(stream) >= 0) {
|
if (userStreams.streams.map(s => s.stream).indexOf(stream) >= 0) {
|
||||||
|
console.log('stream already found')
|
||||||
return state
|
return state
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user