Skip to content

Commit

Permalink
fix: use beforeunload to clear webphone connection (#463)
Browse files Browse the repository at this point in the history
  • Loading branch information
embbnux authored Dec 14, 2020
1 parent e0ed79c commit a2c5c73
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/modules/Phone/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import Softphone from 'ringcentral-integration/modules/Softphone';
import Storage from 'ringcentral-integration/modules/Storage';
import Subscription from 'ringcentral-integration/modules/Subscription';
import TabManager from 'ringcentral-integration/modules/TabManager';
import Webphone from 'ringcentral-integration/modules/Webphone';
// import Webphone from 'ringcentral-integration/modules/Webphone';
import Feedback from 'ringcentral-integration/modules/Feedback';
import Conference from 'ringcentral-integration/modules/Conference';
import RecentMessages from 'ringcentral-integration/modules/RecentMessages';
Expand Down Expand Up @@ -109,6 +109,7 @@ import CallingSettings from '../CallingSettings';
import CallLog from '../CallLog';
import Meeting from '../Meeting';
import { MessageSender } from '../MessageSender';
import Webphone from '../Webphone';

import MeetingInviteModalUI from '../MeetingInviteModalUI';
import MeetingHistoryUI from '../MeetingHistoryUI';
Expand Down
40 changes: 40 additions & 0 deletions src/modules/Webphone/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import WebphoneBase from 'ringcentral-integration/modules/Webphone';
import { Module } from 'ringcentral-integration/lib/di';

@Module({
name: 'Webphone',
deps: []
})
export default class Webphone extends WebphoneBase {
// override initialize to instead unload with beforeunload
initialize() {
if (typeof window !== 'undefined' && typeof document !== 'undefined') {
if (document.readyState === 'loading') {
window.addEventListener('load', () => {
this._prepareVideoElement();
});
} else {
this._prepareVideoElement();
}
window.addEventListener('beforeunload', () => {
if (this.connected) {
// set timeout to reconnect web phone is before unload cancel
setTimeout(() => {
this.connect({
force: true,
skipConnectDelay: true,
skipDLCheck: true,
});
}, 3000);
}
this._disconnect();
this._removeCurrentInstanceFromActiveWebphone();
});
}
this.store.subscribe(() => this._onStateChange());
this._auth.addBeforeLogoutHandler(async () => {
await this._disconnect();
});
this._createOtherWebphoneInstanceListener();
}
}

0 comments on commit a2c5c73

Please sign in to comment.