1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-08-07 23:02:56 +03:00

Add screensharing tests (#2598)

This commit is contained in:
Šimon Brandner
2022-08-18 10:42:03 +02:00
committed by GitHub
parent 9589a97952
commit 448a5c9a77
3 changed files with 110 additions and 1 deletions

View File

@@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import { IScreensharingOpts } from "../../src/webrtc/mediaHandler";
export const DUMMY_SDP = (
"v=0\r\n" +
"o=- 5022425983810148698 2 IN IP4 127.0.0.1\r\n" +
@@ -75,6 +77,7 @@ export class MockRTCPeerConnection {
private negotiationNeededListener: () => void;
private needsNegotiation = false;
localDescription: RTCSessionDescription;
signalingState: RTCSignalingState = "stable";
public static triggerAllNegotiations() {
for (const inst of this.instances) {
@@ -137,6 +140,26 @@ export class MockMediaStreamTrack {
constructor(public readonly id: string, public readonly kind: "audio" | "video", public enabled = true) { }
stop() { }
listeners: [string, (...args: any[]) => any][] = [];
public isStopped = false;
// XXX: Using EventTarget in jest doesn't seem to work, so we write our own
// implementation
dispatchEvent(eventType: string) {
this.listeners.forEach(([t, c]) => {
if (t !== eventType) return;
c();
});
}
addEventListener(eventType: string, callback: (...args: any[]) => any) {
this.listeners.push([eventType, callback]);
}
removeEventListener(eventType: string, callback: (...args: any[]) => any) {
this.listeners.filter(([t, c]) => {
return t !== eventType || c !== callback;
});
}
}
// XXX: Using EventTarget in jest doesn't seem to work, so we write our own
@@ -200,6 +223,17 @@ export class MockMediaHandler {
stopUserMediaStream(stream: MockMediaStream) {
stream.isStopped = true;
}
getScreensharingStream(opts?: IScreensharingOpts) {
const tracks = [new MockMediaStreamTrack("video_track", "video")];
if (opts?.audio) tracks.push(new MockMediaStreamTrack("audio_track", "audio"));
const stream = new MockMediaStream("mock_screen_stream_from_media_handler", tracks);
this.screensharingStreams.push(stream);
return stream;
}
stopScreensharingStream(stream: MockMediaStream) {
stream.isStopped = true;
}
hasAudioDevice() { return true; }
hasVideoDevice() { return true; }
stopAllStreams() {}