You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-12-02 17:02:31 +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:
17
CHANGELOG.md
17
CHANGELOG.md
@@ -1,3 +1,20 @@
|
||||
Changes in [12.2.0](https://github.com/vector-im/element-desktop/releases/tag/v12.2.0) (2021-07-02)
|
||||
===================================================================================================
|
||||
|
||||
## ✨ Features
|
||||
* Improve calculateRoomName performances by using Intl.Collator
|
||||
[\#1801](https://github.com/matrix-org/matrix-js-sdk/pull/1801)
|
||||
* Switch callEventHandler from listening on `event` to `Room.timeline`
|
||||
[\#1789](https://github.com/matrix-org/matrix-js-sdk/pull/1789)
|
||||
* Expose MatrixEvent's internal clearEvent as a function
|
||||
[\#1784](https://github.com/matrix-org/matrix-js-sdk/pull/1784)
|
||||
|
||||
## 🐛 Bug Fixes
|
||||
* Clean up Event.clearEvent handling to fix a bug where malformed events with falsey content wouldn't be considered decrypted
|
||||
[\#1807](https://github.com/matrix-org/matrix-js-sdk/pull/1807)
|
||||
* Standardise spelling and casing of homeserver, identity server, and integration manager
|
||||
[\#1782](https://github.com/matrix-org/matrix-js-sdk/pull/1782)
|
||||
|
||||
Changes in [12.1.0](https://github.com/matrix-org/matrix-js-sdk/releases/tag/v12.1.0) (2021-07-19)
|
||||
==================================================================================================
|
||||
[Full Changelog](https://github.com/matrix-org/matrix-js-sdk/compare/v12.1.0-rc.1...v12.1.0)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "matrix-js-sdk",
|
||||
"version": "12.1.0",
|
||||
"version": "12.2.0",
|
||||
"description": "Matrix Client-Server SDK for Javascript",
|
||||
"scripts": {
|
||||
"prepublishOnly": "yarn build",
|
||||
|
||||
@@ -493,4 +493,68 @@ describe("utils", function() {
|
||||
expect(deepSortedObjectEntries(input)).toMatchObject(output);
|
||||
});
|
||||
});
|
||||
|
||||
describe("recursivelyAssign", () => {
|
||||
it("doesn't override with null/undefined", () => {
|
||||
const result = utils.recursivelyAssign(
|
||||
{
|
||||
string: "Hello world",
|
||||
object: {},
|
||||
float: 0.1,
|
||||
}, {
|
||||
string: null,
|
||||
object: undefined,
|
||||
},
|
||||
true,
|
||||
);
|
||||
|
||||
expect(result).toStrictEqual({
|
||||
string: "Hello world",
|
||||
object: {},
|
||||
float: 0.1,
|
||||
});
|
||||
});
|
||||
|
||||
it("assigns recursively", () => {
|
||||
const result = utils.recursivelyAssign(
|
||||
{
|
||||
number: 42,
|
||||
object: {
|
||||
message: "Hello world",
|
||||
day: "Monday",
|
||||
langs: {
|
||||
compiled: ["c++"],
|
||||
},
|
||||
},
|
||||
thing: "string",
|
||||
}, {
|
||||
number: 2,
|
||||
object: {
|
||||
message: "How are you",
|
||||
day: "Friday",
|
||||
langs: {
|
||||
compiled: ["c++", "c"],
|
||||
},
|
||||
},
|
||||
thing: {
|
||||
aSubThing: "something",
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
expect(result).toStrictEqual({
|
||||
number: 2,
|
||||
object: {
|
||||
message: "How are you",
|
||||
day: "Friday",
|
||||
langs: {
|
||||
compiled: ["c++", "c"],
|
||||
},
|
||||
},
|
||||
thing: {
|
||||
aSubThing: "something",
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -321,16 +321,19 @@ describe('Call', function() {
|
||||
[SDPStreamMetadataKey]: {
|
||||
"stream_id": {
|
||||
purpose: SDPStreamMetadataPurpose.Usermedia,
|
||||
audio_muted: true,
|
||||
video_muted: false,
|
||||
},
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
call.pushRemoteFeed({ id: "stream_id" });
|
||||
expect(call.getFeeds().find((feed) => {
|
||||
return feed.stream.id === "stream_id";
|
||||
})?.purpose).toBe(SDPStreamMetadataPurpose.Usermedia);
|
||||
call.pushRemoteFeed({ id: "stream_id", getAudioTracks: () => ["track1"], getVideoTracks: () => ["track1"] });
|
||||
const feed = call.getFeeds().find((feed) => feed.stream.id === "stream_id");
|
||||
expect(feed?.purpose).toBe(SDPStreamMetadataPurpose.Usermedia);
|
||||
expect(feed?.isAudioMuted()).toBeTruthy();
|
||||
expect(feed?.isVideoMuted()).not.toBeTruthy();
|
||||
});
|
||||
|
||||
it("should fallback to replaceTrack() if the other side doesn't support SPDStreamMetadata", async () => {
|
||||
|
||||
@@ -53,6 +53,8 @@ export enum EventType {
|
||||
CallReject = "m.call.reject",
|
||||
CallSelectAnswer = "m.call.select_answer",
|
||||
CallNegotiate = "m.call.negotiate",
|
||||
CallSDPStreamMetadataChanged = "m.call.sdp_stream_metadata_changed",
|
||||
CallSDPStreamMetadataChangedPrefix = "org.matrix.call.sdp_stream_metadata_changed",
|
||||
CallReplaces = "m.call.replaces",
|
||||
CallAssertedIdentity = "m.call.asserted_identity",
|
||||
CallAssertedIdentityPrefix = "org.matrix.call.asserted_identity",
|
||||
|
||||
22
src/utils.ts
22
src/utils.ts
@@ -694,3 +694,25 @@ const collator = new Intl.Collator();
|
||||
export function compare(a: string, b: string): number {
|
||||
return collator.compare(a, b);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is similar to Object.assign() but it assigns recursively and
|
||||
* allows you to ignore nullish values from the source
|
||||
*
|
||||
* @param {Object} target
|
||||
* @param {Object} source
|
||||
* @returns the target object
|
||||
*/
|
||||
export function recursivelyAssign(target: Object, source: Object, ignoreNullish = false): any {
|
||||
for (const [sourceKey, sourceValue] of Object.entries(source)) {
|
||||
if (target[sourceKey] instanceof Object && sourceValue) {
|
||||
recursivelyAssign(target[sourceKey], sourceValue);
|
||||
continue;
|
||||
}
|
||||
if ((sourceValue !== null && sourceValue !== undefined) || !ignoreNullish) {
|
||||
target[sourceKey] = sourceValue;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -297,6 +297,18 @@ export class CallEventHandler {
|
||||
}
|
||||
|
||||
call.onAssertedIdentityReceived(event);
|
||||
} else if (
|
||||
event.getType() === EventType.CallSDPStreamMetadataChanged ||
|
||||
event.getType() === EventType.CallSDPStreamMetadataChangedPrefix
|
||||
) {
|
||||
if (!call) return;
|
||||
|
||||
if (event.getContent().party_id === call.ourPartyId) {
|
||||
// Ignore remote echo
|
||||
return;
|
||||
}
|
||||
|
||||
call.onSDPStreamMetadataChangedReceived(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@ export enum SDPStreamMetadataPurpose {
|
||||
|
||||
export interface SDPStreamMetadataObject {
|
||||
purpose: SDPStreamMetadataPurpose;
|
||||
audio_muted: boolean;
|
||||
video_muted: boolean;
|
||||
}
|
||||
|
||||
export interface SDPStreamMetadata {
|
||||
@@ -41,6 +43,10 @@ export interface MCallOfferNegotiate {
|
||||
[SDPStreamMetadataKey]: SDPStreamMetadata;
|
||||
}
|
||||
|
||||
export interface MCallSDPStreamMetadataChanged {
|
||||
[SDPStreamMetadataKey]: SDPStreamMetadata;
|
||||
}
|
||||
|
||||
export interface MCallReplacesTarget {
|
||||
id: string;
|
||||
display_name: string;
|
||||
|
||||
@@ -21,6 +21,7 @@ import { RoomMember } from "../models/room-member";
|
||||
|
||||
export enum CallFeedEvent {
|
||||
NewStream = "new_stream",
|
||||
MuteStateChanged = "mute_state_changed"
|
||||
}
|
||||
|
||||
export class CallFeed extends EventEmitter {
|
||||
@@ -30,6 +31,8 @@ export class CallFeed extends EventEmitter {
|
||||
public purpose: SDPStreamMetadataPurpose,
|
||||
private client: MatrixClient,
|
||||
private roomId: string,
|
||||
private audioMuted: boolean,
|
||||
private videoMuted: boolean,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
@@ -51,15 +54,13 @@ export class CallFeed extends EventEmitter {
|
||||
return this.userId === this.client.getUserId();
|
||||
}
|
||||
|
||||
// TODO: The two following methods should be later replaced
|
||||
// by something that will also check if the remote is muted
|
||||
/**
|
||||
* Returns true if audio is muted or if there are no audio
|
||||
* tracks, otherwise returns false
|
||||
* @returns {boolean} is audio muted?
|
||||
*/
|
||||
public isAudioMuted(): boolean {
|
||||
return this.stream.getAudioTracks().length === 0;
|
||||
return this.stream.getAudioTracks().length === 0 || this.audioMuted;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -69,7 +70,7 @@ export class CallFeed extends EventEmitter {
|
||||
*/
|
||||
public isVideoMuted(): boolean {
|
||||
// We assume only one video track
|
||||
return this.stream.getVideoTracks().length === 0;
|
||||
return this.stream.getVideoTracks().length === 0 || this.videoMuted;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,4 +82,14 @@ export class CallFeed extends EventEmitter {
|
||||
this.stream = newStream;
|
||||
this.emit(CallFeedEvent.NewStream, this.stream);
|
||||
}
|
||||
|
||||
public setAudioMuted(muted: boolean): void {
|
||||
this.audioMuted = muted;
|
||||
this.emit(CallFeedEvent.MuteStateChanged, this.audioMuted, this.videoMuted);
|
||||
}
|
||||
|
||||
public setVideoMuted(muted: boolean): void {
|
||||
this.videoMuted = muted;
|
||||
this.emit(CallFeedEvent.MuteStateChanged, this.audioMuted, this.videoMuted);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user