You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-12-01 04:43:29 +03:00
Merge remote-tracking branch 'upstream/develop' into task/cleanup
Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
This commit is contained in:
@@ -36,6 +36,7 @@ import {
|
||||
SDPStreamMetadataPurpose,
|
||||
SDPStreamMetadata,
|
||||
SDPStreamMetadataKey,
|
||||
MCallSDPStreamMetadataChanged,
|
||||
} from './callEventTypes';
|
||||
import { CallFeed } from './callFeed';
|
||||
|
||||
@@ -350,8 +351,6 @@ export class MatrixCall extends EventEmitter {
|
||||
this.makingOffer = false;
|
||||
|
||||
this.remoteOnHold = false;
|
||||
this.micMuted = false;
|
||||
this.vidMuted = false;
|
||||
|
||||
this.feeds = [];
|
||||
|
||||
@@ -399,6 +398,14 @@ export class MatrixCall extends EventEmitter {
|
||||
return this.remoteAssertedIdentity;
|
||||
}
|
||||
|
||||
public get localUsermediaFeed(): CallFeed {
|
||||
return this.getLocalFeeds().find((feed) => feed.purpose === SDPStreamMetadataPurpose.Usermedia);
|
||||
}
|
||||
|
||||
private getFeedByStreamId(streamId: string): CallFeed {
|
||||
return this.getFeeds().find((feed) => feed.stream.id === streamId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of all CallFeeds
|
||||
* @returns {Array<CallFeed>} CallFeeds
|
||||
@@ -428,10 +435,12 @@ export class MatrixCall extends EventEmitter {
|
||||
* @returns {SDPStreamMetadata} localSDPStreamMetadata
|
||||
*/
|
||||
private getLocalSDPStreamMetadata(): SDPStreamMetadata {
|
||||
const metadata = {};
|
||||
const metadata: SDPStreamMetadata = {};
|
||||
for (const localFeed of this.getLocalFeeds()) {
|
||||
metadata[localFeed.stream.id] = {
|
||||
purpose: localFeed.purpose,
|
||||
audio_muted: localFeed.isAudioMuted(),
|
||||
video_muted: localFeed.isVideoMuted(),
|
||||
};
|
||||
}
|
||||
logger.debug("Got local SDPStreamMetadata", metadata);
|
||||
@@ -456,6 +465,8 @@ export class MatrixCall extends EventEmitter {
|
||||
|
||||
const userId = this.getOpponentMember().userId;
|
||||
const purpose = this.remoteSDPStreamMetadata[stream.id].purpose;
|
||||
const audioMuted = this.remoteSDPStreamMetadata[stream.id].audio_muted;
|
||||
const videoMuted = this.remoteSDPStreamMetadata[stream.id].video_muted;
|
||||
|
||||
if (!purpose) {
|
||||
logger.warn(`Ignoring stream with id ${stream.id} because we didn't get any metadata about it`);
|
||||
@@ -468,7 +479,7 @@ export class MatrixCall extends EventEmitter {
|
||||
if (existingFeed) {
|
||||
existingFeed.setNewStream(stream);
|
||||
} else {
|
||||
this.feeds.push(new CallFeed(stream, userId, purpose, this.client, this.roomId));
|
||||
this.feeds.push(new CallFeed(stream, userId, purpose, this.client, this.roomId, audioMuted, videoMuted));
|
||||
this.emit(CallEvent.FeedsChanged, this.feeds);
|
||||
}
|
||||
|
||||
@@ -495,11 +506,11 @@ export class MatrixCall extends EventEmitter {
|
||||
|
||||
// Try to find a feed with the same stream id as the new stream,
|
||||
// if we find it replace the old stream with the new one
|
||||
const feed = this.feeds.find((feed) => feed.stream.id === stream.id);
|
||||
const feed = this.getFeedByStreamId(stream.id);
|
||||
if (feed) {
|
||||
feed.setNewStream(stream);
|
||||
} else {
|
||||
this.feeds.push(new CallFeed(stream, userId, purpose, this.client, this.roomId));
|
||||
this.feeds.push(new CallFeed(stream, userId, purpose, this.client, this.roomId, false, false));
|
||||
this.emit(CallEvent.FeedsChanged, this.feeds);
|
||||
}
|
||||
|
||||
@@ -514,7 +525,7 @@ export class MatrixCall extends EventEmitter {
|
||||
if (existingFeed) {
|
||||
existingFeed.setNewStream(stream);
|
||||
} else {
|
||||
this.feeds.push(new CallFeed(stream, userId, purpose, this.client, this.roomId));
|
||||
this.feeds.push(new CallFeed(stream, userId, purpose, this.client, this.roomId, false, false));
|
||||
this.emit(CallEvent.FeedsChanged, this.feeds);
|
||||
}
|
||||
|
||||
@@ -552,7 +563,7 @@ export class MatrixCall extends EventEmitter {
|
||||
private deleteFeedByStream(stream: MediaStream) {
|
||||
logger.debug(`Removing feed with stream id ${stream.id}`);
|
||||
|
||||
const feed = this.feeds.find((feed) => feed.stream.id === stream.id);
|
||||
const feed = this.getFeedByStreamId(stream.id);
|
||||
if (!feed) {
|
||||
logger.warn(`Didn't find the feed with stream id ${stream.id} to delete`);
|
||||
return;
|
||||
@@ -602,7 +613,7 @@ export class MatrixCall extends EventEmitter {
|
||||
|
||||
const sdpStreamMetadata = invite[SDPStreamMetadataKey];
|
||||
if (sdpStreamMetadata) {
|
||||
this.remoteSDPStreamMetadata = sdpStreamMetadata;
|
||||
this.updateRemoteSDPStreamMetadata(sdpStreamMetadata);
|
||||
} else {
|
||||
logger.debug("Did not get any SDPStreamMetadata! Can not send/receive multiple streams");
|
||||
}
|
||||
@@ -888,7 +899,7 @@ export class MatrixCall extends EventEmitter {
|
||||
* @param {boolean} muted True to mute the outbound video.
|
||||
*/
|
||||
setLocalVideoMuted(muted: boolean) {
|
||||
this.vidMuted = muted;
|
||||
this.localUsermediaFeed?.setVideoMuted(muted);
|
||||
this.updateMuteStatus();
|
||||
}
|
||||
|
||||
@@ -902,8 +913,7 @@ export class MatrixCall extends EventEmitter {
|
||||
* (including if the call is not set up yet).
|
||||
*/
|
||||
isLocalVideoMuted(): boolean {
|
||||
if (this.type === CallType.Voice) return true;
|
||||
return this.vidMuted;
|
||||
return this.localUsermediaFeed?.isVideoMuted();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -911,7 +921,7 @@ export class MatrixCall extends EventEmitter {
|
||||
* @param {boolean} muted True to mute the mic.
|
||||
*/
|
||||
setMicrophoneMuted(muted: boolean) {
|
||||
this.micMuted = muted;
|
||||
this.localUsermediaFeed?.setAudioMuted(muted);
|
||||
this.updateMuteStatus();
|
||||
}
|
||||
|
||||
@@ -925,7 +935,7 @@ export class MatrixCall extends EventEmitter {
|
||||
* is not set up yet).
|
||||
*/
|
||||
isMicrophoneMuted(): boolean {
|
||||
return this.micMuted;
|
||||
return this.localUsermediaFeed?.isAudioMuted();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -988,14 +998,14 @@ export class MatrixCall extends EventEmitter {
|
||||
}
|
||||
|
||||
private updateMuteStatus() {
|
||||
if (!this.localUsermediaStream) {
|
||||
return;
|
||||
}
|
||||
this.sendVoipEvent(EventType.CallSDPStreamMetadataChangedPrefix, {
|
||||
[SDPStreamMetadataKey]: this.getLocalSDPStreamMetadata(),
|
||||
});
|
||||
|
||||
const micShouldBeMuted = this.localUsermediaFeed?.isAudioMuted() || this.remoteOnHold;
|
||||
const vidShouldBeMuted = this.localUsermediaFeed?.isVideoMuted() || this.remoteOnHold;
|
||||
|
||||
const micShouldBeMuted = this.micMuted || this.remoteOnHold;
|
||||
setTracksEnabled(this.localUsermediaStream.getAudioTracks(), !micShouldBeMuted);
|
||||
|
||||
const vidShouldBeMuted = this.vidMuted || this.remoteOnHold;
|
||||
setTracksEnabled(this.localUsermediaStream.getVideoTracks(), !vidShouldBeMuted);
|
||||
}
|
||||
|
||||
@@ -1211,7 +1221,7 @@ export class MatrixCall extends EventEmitter {
|
||||
|
||||
const sdpStreamMetadata = event.getContent()[SDPStreamMetadataKey];
|
||||
if (sdpStreamMetadata) {
|
||||
this.remoteSDPStreamMetadata = sdpStreamMetadata;
|
||||
this.updateRemoteSDPStreamMetadata(sdpStreamMetadata);
|
||||
} else {
|
||||
logger.warn("Did not get any SDPStreamMetadata! Can not send/receive multiple streams");
|
||||
}
|
||||
@@ -1286,9 +1296,9 @@ export class MatrixCall extends EventEmitter {
|
||||
|
||||
const prevLocalOnHold = this.isLocalOnHold();
|
||||
|
||||
const metadata = event.getContent()[SDPStreamMetadataKey];
|
||||
if (metadata) {
|
||||
this.remoteSDPStreamMetadata = metadata;
|
||||
const sdpStreamMetadata = event.getContent()[SDPStreamMetadataKey];
|
||||
if (sdpStreamMetadata) {
|
||||
this.updateRemoteSDPStreamMetadata(sdpStreamMetadata);
|
||||
} else {
|
||||
logger.warn("Received negotiation event without SDPStreamMetadata!");
|
||||
}
|
||||
@@ -1318,6 +1328,22 @@ export class MatrixCall extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
private updateRemoteSDPStreamMetadata(metadata: SDPStreamMetadata): void {
|
||||
this.remoteSDPStreamMetadata = utils.recursivelyAssign(this.remoteSDPStreamMetadata || {}, metadata, true);
|
||||
for (const feed of this.getRemoteFeeds()) {
|
||||
const streamId = feed.stream.id;
|
||||
feed.setAudioMuted(this.remoteSDPStreamMetadata[streamId]?.audio_muted);
|
||||
feed.setVideoMuted(this.remoteSDPStreamMetadata[streamId]?.video_muted);
|
||||
feed.purpose = this.remoteSDPStreamMetadata[streamId]?.purpose;
|
||||
}
|
||||
}
|
||||
|
||||
public onSDPStreamMetadataChangedReceived(event: MatrixEvent): void {
|
||||
const content = event.getContent<MCallSDPStreamMetadataChanged>();
|
||||
const metadata = content[SDPStreamMetadataKey];
|
||||
this.updateRemoteSDPStreamMetadata(metadata);
|
||||
}
|
||||
|
||||
async onAssertedIdentityReceived(event: MatrixEvent) {
|
||||
if (!event.getContent().asserted_identity) return;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user