-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use beforeunload to clear webphone connection (#463)
- Loading branch information
Showing
2 changed files
with
42 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |