Skip to content
This repository has been archived by the owner on Nov 13, 2022. It is now read-only.

Commit

Permalink
Guard against multiple SipProviders
Browse files Browse the repository at this point in the history
This change adds ID attribute to audio element when attaching to document, checks against existence of one such element during component mounting and properly removes audio element when SipProvider is unmounted.
  • Loading branch information
Steveb-p authored Jul 26, 2018
1 parent fdf80be commit 9582d07
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/components/SipProvider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,14 @@ export default class SipProvider extends React.Component {
}

componentDidMount() {
// TODO check against having two instances of SipProvider in one app, which is not allowed

if (window.document.getElementById('sip-provider-audio')) {
throw new Error(`Creating two SipProviders in one application is forbidden. If that's not the case `
+`then check if you're using "sip-provider-audio" as id attribute for any existing `
+`element`);
}

this.remoteAudio = window.document.createElement('audio');
this.remoteAudio.id = 'sip-provider-audio';
window.document.body.appendChild(this.remoteAudio);

this.reconfigureDebug();
Expand All @@ -137,6 +142,7 @@ export default class SipProvider extends React.Component {
}

componentWillUnmount() {
this.remoteAudio.parentNode.removeChild(this.remoteAudio);
delete this.remoteAudio;
if (this.ua) {
this.ua.stop();
Expand Down

0 comments on commit 9582d07

Please sign in to comment.