|
| 1 | +/* |
| 2 | +Copyright 2022 The Matrix.org Foundation C.I.C. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +import { MediaHandler } from "../../../src/webrtc/mediaHandler"; |
| 18 | +import { TestClient } from "../../TestClient"; |
| 19 | +import { MockMediaDevices } from "../../test-utils/webrtc"; |
| 20 | + |
| 21 | +describe("MediaHandler", () => { |
| 22 | + let client: TestClient; |
| 23 | + let mediaHandler: MediaHandler; |
| 24 | + |
| 25 | + beforeEach(() => { |
| 26 | + client = new TestClient("@alice:foo", "somedevice", "token", undefined, {}); |
| 27 | + mediaHandler = new MediaHandler(client.client); |
| 28 | + client.client["mediaHandler"] = mediaHandler; |
| 29 | + |
| 30 | + // @ts-ignore Mock |
| 31 | + global.navigator = { mediaDevices: new MockMediaDevices() }; |
| 32 | + }); |
| 33 | + |
| 34 | + afterEach(() => { |
| 35 | + mediaHandler.stopAllStreams(); |
| 36 | + client.stop(); |
| 37 | + }); |
| 38 | + |
| 39 | + describe("getUserMediaStream", () => { |
| 40 | + it("should provide audio/video streams with appropriate defaults", async () => { |
| 41 | + const stream = await mediaHandler.getUserMediaStream(true, true); |
| 42 | + expect(stream.getAudioTracks().length).toBeGreaterThan(0); |
| 43 | + expect(stream.getVideoTracks().length).toBeGreaterThan(0); |
| 44 | + |
| 45 | + expect(() => { mediaHandler.stopUserMediaStream(stream); }).not.toThrow(); |
| 46 | + }); |
| 47 | + |
| 48 | + it("should provide media stream with advanced audio settings when requested", async () => { |
| 49 | + await mediaHandler.setAudioSettings({ |
| 50 | + autoGainControl: false, |
| 51 | + echoCancellation: true, |
| 52 | + noiseSuppression: false, |
| 53 | + }); |
| 54 | + |
| 55 | + const stream = await mediaHandler.getUserMediaStream(true, true); |
| 56 | + expect(stream.getAudioTracks().length).toBeGreaterThan(0); |
| 57 | + |
| 58 | + const actualAudioSettings = stream.getAudioTracks()[0].getSettings(); |
| 59 | + expect(actualAudioSettings).toHaveProperty("autoGainControl.ideal", false); |
| 60 | + expect(actualAudioSettings).toHaveProperty("echoCancellation.ideal", true); |
| 61 | + expect(actualAudioSettings).toHaveProperty("noiseSuppression.ideal", false); |
| 62 | + }); |
| 63 | + }); |
| 64 | +}); |
0 commit comments