From 720e26a5dd68261c66547580bc166e4c675ee13f Mon Sep 17 00:00:00 2001 From: Jerko Steiner Date: Tue, 10 Mar 2020 13:14:31 +0100 Subject: [PATCH] Fix CallActions.test.ts --- src/client/actions/CallActions.test.ts | 2 ++ src/client/actions/CallActions.ts | 23 +++++++++++++---------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/client/actions/CallActions.test.ts b/src/client/actions/CallActions.test.ts index 75174af..de6aeb6 100644 --- a/src/client/actions/CallActions.test.ts +++ b/src/client/actions/CallActions.test.ts @@ -74,6 +74,8 @@ describe('CallActions', () => { message: 'Connected to server socket', type: 'warning', }, + }, { + type: constants.INIT, }, { type: constants.NOTIFY, payload: { diff --git a/src/client/actions/CallActions.ts b/src/client/actions/CallActions.ts index 11bbe82..6fd0da0 100644 --- a/src/client/actions/CallActions.ts +++ b/src/client/actions/CallActions.ts @@ -19,15 +19,18 @@ const initialize = (): InitializeAction => ({ export const init = (): ThunkResult> => async (dispatch, getState) => { - socket.on('connect', () => { - dispatch(NotifyActions.warning('Connected to server socket')) - dispatch(SocketActions.handshake({ - socket, - roomName: callId, - })) - dispatch(initialize()) - }) - socket.on('disconnect', () => { - dispatch(NotifyActions.error('Server socket disconnected')) + return new Promise(resolve => { + socket.on('connect', () => { + dispatch(NotifyActions.warning('Connected to server socket')) + dispatch(SocketActions.handshake({ + socket, + roomName: callId, + })) + dispatch(initialize()) + resolve() + }) + socket.on('disconnect', () => { + dispatch(NotifyActions.error('Server socket disconnected')) + }) }) }