always send new metadata after calling setMedia

This commit is contained in:
Bruno Windels 2022-04-21 10:15:57 +02:00
parent 55c6dcf613
commit 10a6269147

View file

@ -217,24 +217,14 @@ export class PeerCall implements IDisposable {
log.set("userMedia_video_muted", localMedia.cameraMuted); log.set("userMedia_video_muted", localMedia.cameraMuted);
log.set("screenShare_video", !!localMedia.screenShare?.videoTrack); log.set("screenShare_video", !!localMedia.screenShare?.videoTrack);
log.set("datachannel", !!localMedia.dataChannelOptions); log.set("datachannel", !!localMedia.dataChannelOptions);
await this.updateLocalMedia(localMedia, log);
const oldMetaData = this.getSDPMetadata(); const content: MCallSDPStreamMetadataChanged<MCallBase> = {
const willRenegotiate = await this.updateLocalMedia(localMedia, log); call_id: this.callId,
// TODO: if we will renegotiate, we don't bother sending the metadata changed event version: 1,
// because the renegotiate event will send new metadata anyway, but is that the right seq: this.seq++,
// call? [SDPStreamMetadataKey]: this.getSDPMetadata()
if (!willRenegotiate) { };
const newMetaData = this.getSDPMetadata(); await this.sendSignallingMessage({type: EventType.SDPStreamMetadataChangedPrefix, content}, log);
if (JSON.stringify(oldMetaData) !== JSON.stringify(newMetaData)) {
const content: MCallSDPStreamMetadataChanged<MCallBase> = {
call_id: this.callId,
version: 1,
seq: this.seq++,
[SDPStreamMetadataKey]: newMetaData
};
await this.sendSignallingMessage({type: EventType.SDPStreamMetadataChangedPrefix, content}, log);
}
}
}); });
} }
@ -856,8 +846,8 @@ export class PeerCall implements IDisposable {
const streamSender = this.peerConnection.localStreams.get(streamId); const streamSender = this.peerConnection.localStreams.get(streamId);
metadata[streamId] = { metadata[streamId] = {
purpose: SDPStreamMetadataPurpose.Usermedia, purpose: SDPStreamMetadataPurpose.Usermedia,
audio_muted: !(streamSender?.audioSender?.enabled && streamSender?.audioSender?.track?.enabled), audio_muted: this.localMedia.microphoneMuted || !this.localMedia.userMedia.audioTrack,
video_muted: !(streamSender?.videoSender?.enabled && streamSender?.videoSender?.track?.enabled), video_muted: this.localMedia.cameraMuted || !this.localMedia.userMedia.videoTrack,
}; };
} }
if (this.localMedia?.screenShare) { if (this.localMedia?.screenShare) {
@ -889,9 +879,8 @@ export class PeerCall implements IDisposable {
this.options.emitUpdate(this, undefined); this.options.emitUpdate(this, undefined);
} }
private updateLocalMedia(localMedia: LocalMedia, logItem: ILogItem): Promise<boolean> { private updateLocalMedia(localMedia: LocalMedia, logItem: ILogItem): Promise<void> {
return logItem.wrap("updateLocalMedia", async log => { return logItem.wrap("updateLocalMedia", async log => {
let willRenegotiate = false;
const oldMedia = this.localMedia; const oldMedia = this.localMedia;
this.localMedia = localMedia; this.localMedia = localMedia;
const applyStream = async (oldStream: Stream | undefined, stream: Stream | undefined, oldMuteSettings: LocalMedia | undefined, mutedSettings: LocalMedia | undefined, logLabel: string) => { const applyStream = async (oldStream: Stream | undefined, stream: Stream | undefined, oldMuteSettings: LocalMedia | undefined, mutedSettings: LocalMedia | undefined, logLabel: string) => {
@ -920,13 +909,11 @@ export class PeerCall implements IDisposable {
log.wrap(`adding and removing ${logLabel} ${track.kind} track`, log => { log.wrap(`adding and removing ${logLabel} ${track.kind} track`, log => {
this.peerConnection.removeTrack(sender); this.peerConnection.removeTrack(sender);
this.peerConnection.addTrack(track); this.peerConnection.addTrack(track);
willRenegotiate = true;
}); });
} }
} else { } else {
log.wrap(`adding ${logLabel} ${track.kind} track`, log => { log.wrap(`adding ${logLabel} ${track.kind} track`, log => {
this.peerConnection.addTrack(track); this.peerConnection.addTrack(track);
willRenegotiate = true;
}); });
} }
} else { } else {
@ -937,20 +924,17 @@ export class PeerCall implements IDisposable {
log.wrap(`removing ${logLabel} ${sender.track.kind} track`, log => { log.wrap(`removing ${logLabel} ${sender.track.kind} track`, log => {
sender.track.enabled = false; sender.track.enabled = false;
this.peerConnection.removeTrack(sender); this.peerConnection.removeTrack(sender);
willRenegotiate = true;
}); });
} }
} }
} else if (track) { } else if (track) {
log.log({l: "checking mute status", muted, wasMuted, wasCameraMuted: oldMedia?.cameraMuted, sender: !!sender, streamSender: !!streamSender, oldStream: oldStream?.id, stream: stream?.id}); log.log({l: "checking mute status", muted, wasMuted, wasCameraMuted: oldMedia?.cameraMuted, sender: !!sender, streamSender: !!streamSender, oldStream: oldStream?.id, stream: stream?.id});
if (sender && muted !== wasMuted) { if (sender && muted !== wasMuted) {
// TODO: why does unmuting not work? wasMuted is false
log.wrap(`${logLabel} ${track.kind} ${muted ? "muting" : "unmuting"}`, log => { log.wrap(`${logLabel} ${track.kind} ${muted ? "muting" : "unmuting"}`, log => {
// sender.track.enabled = !muted; // sender.track.enabled = !muted;
// This doesn't always seem to trigger renegotiation?? // This doesn't always seem to trigger renegotiation??
// We should probably always send the new metadata first ... // We should probably always send the new metadata first ...
sender.enable(!muted); sender.enable(!muted);
willRenegotiate = true;
}); });
} else { } else {
log.log(`${logLabel} ${track.kind} track hasn't changed`); log.log(`${logLabel} ${track.kind} track hasn't changed`);
@ -964,7 +948,6 @@ export class PeerCall implements IDisposable {
await applyStream(oldMedia?.userMedia, localMedia?.userMedia, oldMedia, localMedia, "userMedia"); await applyStream(oldMedia?.userMedia, localMedia?.userMedia, oldMedia, localMedia, "userMedia");
await applyStream(oldMedia?.screenShare, localMedia?.screenShare, undefined, undefined, "screenShare"); await applyStream(oldMedia?.screenShare, localMedia?.screenShare, undefined, undefined, "screenShare");
return willRenegotiate;
// TODO: datachannel, but don't do it here as we don't want to do it from answer, rather in different method // TODO: datachannel, but don't do it here as we don't want to do it from answer, rather in different method
}); });
} }