ensure all member streams are cloned

so we can stop them without affecting the main one
also, only stop them when disconnecting from the member, rather then
when the peer call ends, as we might want to retry connecting to
the peer with the same stream.
This commit is contained in:
Bruno Windels 2022-04-14 13:44:11 +02:00
parent bc118b5c0b
commit ff856d843c
4 changed files with 7 additions and 6 deletions

View file

@ -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();

View file

@ -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') {

View file

@ -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();
}

View file

@ -104,6 +104,7 @@ export class Member {
this.peerCall?.close(undefined, log);
this.peerCall?.dispose();
this.peerCall = undefined;
this.localMedia?.dispose();
this.localMedia = undefined;
});
}