You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-07-30 04:23:07 +03:00
Add MockMediaStream
Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
This commit is contained in:
@ -83,6 +83,17 @@ class MockRTCPeerConnection {
|
|||||||
getStats() { return []; }
|
getStats() { return []; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class MockMediaStream {
|
||||||
|
constructor(
|
||||||
|
public id,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
getTracks() { return []; }
|
||||||
|
getAudioTracks() { return [{ enabled: true }]; }
|
||||||
|
getVideoTracks() { return [{ enabled: true }]; }
|
||||||
|
addEventListener() {}
|
||||||
|
}
|
||||||
|
|
||||||
describe('Call', function() {
|
describe('Call', function() {
|
||||||
let client;
|
let client;
|
||||||
let call;
|
let call;
|
||||||
@ -98,13 +109,7 @@ describe('Call', function() {
|
|||||||
global.navigator = {
|
global.navigator = {
|
||||||
mediaDevices: {
|
mediaDevices: {
|
||||||
// @ts-ignore Mock
|
// @ts-ignore Mock
|
||||||
getUserMedia: () => {
|
getUserMedia: () => new MockMediaStream("local_stream"),
|
||||||
return {
|
|
||||||
getTracks: () => [],
|
|
||||||
getAudioTracks: () => [],
|
|
||||||
getVideoTracks: () => [],
|
|
||||||
};
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -115,7 +120,7 @@ describe('Call', function() {
|
|||||||
RTCSessionDescription: {},
|
RTCSessionDescription: {},
|
||||||
// @ts-ignore Mock
|
// @ts-ignore Mock
|
||||||
RTCIceCandidate: {},
|
RTCIceCandidate: {},
|
||||||
getUserMedia: {},
|
getUserMedia: () => new MockMediaStream("local_stream"),
|
||||||
};
|
};
|
||||||
// @ts-ignore Mock
|
// @ts-ignore Mock
|
||||||
global.document = {};
|
global.document = {};
|
||||||
@ -319,7 +324,7 @@ describe('Call', function() {
|
|||||||
sdp: DUMMY_SDP,
|
sdp: DUMMY_SDP,
|
||||||
},
|
},
|
||||||
[SDPStreamMetadataKey]: {
|
[SDPStreamMetadataKey]: {
|
||||||
"stream_id": {
|
"remote_stream": {
|
||||||
purpose: SDPStreamMetadataPurpose.Usermedia,
|
purpose: SDPStreamMetadataPurpose.Usermedia,
|
||||||
audio_muted: true,
|
audio_muted: true,
|
||||||
video_muted: false,
|
video_muted: false,
|
||||||
@ -329,8 +334,8 @@ describe('Call', function() {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
call.pushRemoteFeed({ id: "stream_id", getAudioTracks: () => ["track1"], getVideoTracks: () => ["track1"] });
|
call.pushRemoteFeed(new MockMediaStream("remote_stream"));
|
||||||
const feed = call.getFeeds().find((feed) => feed.stream.id === "stream_id");
|
const feed = call.getFeeds().find((feed) => feed.stream.id === "remote_stream");
|
||||||
expect(feed?.purpose).toBe(SDPStreamMetadataPurpose.Usermedia);
|
expect(feed?.purpose).toBe(SDPStreamMetadataPurpose.Usermedia);
|
||||||
expect(feed?.isAudioMuted()).toBeTruthy();
|
expect(feed?.isAudioMuted()).toBeTruthy();
|
||||||
expect(feed?.isVideoMuted()).not.toBeTruthy();
|
expect(feed?.isVideoMuted()).not.toBeTruthy();
|
||||||
|
Reference in New Issue
Block a user