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 and Paweł Niedzielski committed Aug 4, 2018
1 parent 798a77d commit 362c7a4
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/components/SipProvider/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,14 @@ export default class SipProvider extends React.Component<
}

public 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 @@ -176,6 +181,7 @@ export default class SipProvider extends React.Component<
}

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

0 comments on commit 362c7a4

Please sign in to comment.