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

Guard against multiple SipProviders #22

Merged
merged 1 commit into from
Aug 4, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/components/SipProvider/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,16 @@ 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 +183,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