Skip to content

Commit

Permalink
use polling fallback when socket server fails in SocketConnection com…
Browse files Browse the repository at this point in the history
…ponent.
  • Loading branch information
ivanjiang5628 committed Oct 1, 2021
1 parent 67c641e commit 21cf57a
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 14 deletions.
5 changes: 4 additions & 1 deletion lang/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,10 @@
"youMayTest": "You may test your audio and video while you wait.",
"callWillBegin": "Your call will automatically begin momentarily.",
"authenticationExpired": "Your appointment booking has expired",
"minutes": "{{duration}} Minutes"
"minutes": "{{duration}} Minutes",
"errorTitleKey": "Waiting area error.",
"socketFailed": "Unable to connect to websocket.",
"socketFallback": "Fallback to polling."
},
"preCallMessage": {
"sitBack": "Sit back, relax and take a moment for yourself.",
Expand Down
2 changes: 2 additions & 0 deletions react/features/jane-waiting-area/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
SET_JANE_WAITING_AREA_AUTH_STATE
} from './actionTypes';
import {
updateParticipantReadyStatus,
detectLegacyMobileApp,
getAudioTrack,
getVideoTrack, hasRemoteParticipantInBeginStatus
Expand Down Expand Up @@ -74,6 +75,7 @@ export function initJaneWaitingArea(tracks: Object[], errors: Object) {

export function joinConference() {
return function(dispatch: Function) {
updateParticipantReadyStatus('joined');
dispatch(setJaneWaitingAreaPageVisibility(false));
dispatch(startConference());
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@ import { Component } from 'react';

import { Socket } from '../../../../service/Websocket/socket';
import {
createWaitingAreaModalEvent,
createWaitingAreaParticipantStatusChangedEvent,
createWaitingAreaSocketEvent,
sendAnalytics
} from '../../analytics';
import {
redirectToStaticPage
} from '../../app/actions';
import { getLocalParticipantInfoFromJwt, getLocalParticipantType } from '../../base/participants/functions';
import { connect } from '../../base/redux';
import { playSound as playSoundAction } from '../../base/sounds';
import { sleep } from '../../base/util/helpers';
import { showErrorNotification as showErrorNotificationAction,
showNotification as showNotificationAction } from '../../notifications';
import {
setJaneWaitingAreaAuthState as setJaneWaitingAreaAuthStateAction,
updateRemoteParticipantsStatuses as updateRemoteParticipantsStatusesAction,
Expand Down Expand Up @@ -40,16 +46,24 @@ type Props = {
playSound: Function,
joinConference: Function,
setJaneWaitingAreaAuthState: Function,
remoteParticipantsStatuses: any
remoteParticipantsStatuses: any,
showErrorNotification: Function,
showNotification: Function
};

class SocketConnection extends Component<Props> {

socket: Object;

interval: ?IntervalID;

pollingRetries: number;

constructor(props) {
super(props);
this.socket = null;
this.interval = undefined;
this.pollingRetries = 0;
}

componentDidMount() {
Expand Down Expand Up @@ -89,6 +103,10 @@ class SocketConnection extends Component<Props> {
}

componentWillUnmount() {
if (this.interval) {
clearInterval(this.interval);
this.interval = undefined;
}
this.socket && this.socket.disconnect();
}

Expand Down Expand Up @@ -117,19 +135,59 @@ class SocketConnection extends Component<Props> {
}

_connectionStatusListener(status) {
const { isRNWebViewPage, joinConference } = this.props;
const { showNotification } = this.props;

if (isRNWebViewPage) {
sendMessageToIosApp({ message: status });
}
if (status && status.error) {
joinConference();
sendAnalytics(createWaitingAreaSocketEvent('error', status.error));
sendAnalytics(createWaitingAreaModalEvent('start.polling'));

showNotification({
descriptionKey: 'janeWaitingArea.socketFallback',
titleKey: 'janeWaitingArea.socketFailed'
});
this._polling();
}
}

_polling() {
const { participantType, updateRemoteParticipantsStatuses, showErrorNotification, setJaneWaitingAreaAuthState, isRNWebViewPage } = this.props;

this.interval
= setInterval(
async () => {
try {
const response = await checkRoomStatus();
const remoteParticipantsStatuses = getRemoteParticipantsStatuses(response.participant_statuses, participantType);

updateRemoteParticipantsStatuses(remoteParticipantsStatuses);
} catch (error) {
if (this.pollingRetries === 3) {
if (isRNWebViewPage) {
sendMessageToIosApp({ message: error });
} else if (error && error.error === 'Signature has expired') {
setJaneWaitingAreaAuthState('failed');
}
showErrorNotification({
description: error && error.error,
titleKey: 'janeWaitingArea.errorTitleKey'
});
sendAnalytics(createWaitingAreaModalEvent('polling.stoped'));
clearInterval(this.interval);
throw Error(error);
}
this.pollingRetries++;
}
},
3000);
}

async _connectSocket() {
const { participantType, isRNWebViewPage, updateRemoteParticipantsStatuses, joinConference, setJaneWaitingAreaAuthState } = this.props;
const { participantType,
isRNWebViewPage,
updateRemoteParticipantsStatuses,
setJaneWaitingAreaAuthState,
showErrorNotification,
redirectToWelcomePage } = this.props;

try {
const response = await checkRoomStatus();
Expand All @@ -149,9 +207,15 @@ class SocketConnection extends Component<Props> {
sendMessageToIosApp({ message: error });
} else if (error && error.error === 'Signature has expired') {
setJaneWaitingAreaAuthState('failed');
} else {
joinConference();
}
showErrorNotification({
description: error && error.error,
titleKey: 'janeWaitingArea.errorTitleKey'
});
console.error(error);

// redirect user to the welcome page
redirectToWelcomePage();
}
}

Expand Down Expand Up @@ -191,6 +255,15 @@ function mapDispatchToProps(dispatch) {
},
setJaneWaitingAreaAuthState(state) {
dispatch(setJaneWaitingAreaAuthStateAction(state));
},
showErrorNotification(error) {
dispatch(showErrorNotificationAction(error));
},
showNotification(error) {
dispatch(showNotificationAction(error));
},
redirectToWelcomePage() {
dispatch(redirectToStaticPage('/'));
}
};
}
Expand Down
4 changes: 1 addition & 3 deletions react/features/jane-waiting-area/components/modal/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ import {
joinConference as joinConferenceAction
} from '../../actions';
import {
checkLocalParticipantCanJoin,
updateParticipantReadyStatus
checkLocalParticipantCanJoin
} from '../../functions';
import ActionButton from '../buttons/ActionButton';

Expand Down Expand Up @@ -114,7 +113,6 @@ class Modal extends Component<Props> {
_joinConference() {
const { joinConference } = this.props;

updateParticipantReadyStatus('joined');
joinConference();
}

Expand Down
2 changes: 1 addition & 1 deletion react/features/jane-waiting-area/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export function updateParticipantReadyStatus(status: string): void {
sendAnalytics(createWaitingAreaParticipantStatusChangedEvent('failed'));
window.APP.store.dispatch(showErrorNotification({
descriptionKey: error,
titleKey: 'Waiting area error'
titleKey: 'janeWaitingArea.errorTitleKey'
}));
console.error(error);
});
Expand Down

0 comments on commit 21cf57a

Please sign in to comment.