diff --git a/src/matrix/calls/LocalMedia.ts b/src/matrix/calls/LocalMedia.ts index 6622f641..6564adac 100644 --- a/src/matrix/calls/LocalMedia.ts +++ b/src/matrix/calls/LocalMedia.ts @@ -37,10 +37,10 @@ export class LocalMedia { return new LocalMedia(this.userMedia, this.screenShare, options); } - clone() { + clone(): LocalMedia { return new LocalMedia(this.userMedia?.clone(), this.screenShare?.clone(), this.dataChannelOptions); } - + dispose() { this.userMedia?.audioTrack?.stop(); this.userMedia?.videoTrack?.stop(); diff --git a/src/matrix/calls/PeerCall.ts b/src/matrix/calls/PeerCall.ts index 78ffc818..5b6e2ca8 100644 --- a/src/matrix/calls/PeerCall.ts +++ b/src/matrix/calls/PeerCall.ts @@ -814,7 +814,6 @@ export class PeerCall implements IDisposable { this.hangupParty = hangupParty; this._hangupReason = hangupReason; this.setState(CallState.Ended, log); - this.localMedia?.dispose(); this.localMedia = undefined; if (this.peerConnection && this.peerConnection.signalingState !== 'closed') { diff --git a/src/matrix/calls/group/GroupCall.ts b/src/matrix/calls/group/GroupCall.ts index 47d87e5e..d077f27c 100644 --- a/src/matrix/calls/group/GroupCall.ts +++ b/src/matrix/calls/group/GroupCall.ts @@ -118,7 +118,7 @@ export class GroupCall extends EventEmitter<{change: never}> { this.emitChange(); // send invite to all members that are < my userId for (const [,member] of this._members) { - member.connect(this._localMedia); + member.connect(this._localMedia!.clone()); } }); } @@ -218,6 +218,7 @@ export class GroupCall extends EventEmitter<{change: never}> { ); this._members.add(memberKey, member); if (this._state === GroupCallState.Joining || this._state === GroupCallState.Joined) { + // Safari can't send a MediaStream to multiple sources, so clone it member.connect(this._localMedia!.clone()); } } @@ -267,11 +268,11 @@ export class GroupCall extends EventEmitter<{change: never}> { private removeOwnDevice(log: ILogItem) { if (this._state === GroupCallState.Joined) { log.set("leave_own", true); - this._localMedia?.dispose(); - this._localMedia = undefined; for (const [,member] of this._members) { member.disconnect(); } + this._localMedia?.dispose(); + this._localMedia = undefined; this._state = GroupCallState.Created; this.emitChange(); } diff --git a/src/matrix/calls/group/Member.ts b/src/matrix/calls/group/Member.ts index 110aba6d..1305fcf1 100644 --- a/src/matrix/calls/group/Member.ts +++ b/src/matrix/calls/group/Member.ts @@ -104,6 +104,7 @@ export class Member { this.peerCall?.close(undefined, log); this.peerCall?.dispose(); this.peerCall = undefined; + this.localMedia?.dispose(); this.localMedia = undefined; }); }