You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-08-06 12:02:40 +03:00
Test disabling screenshare in group calls (#2634)
Also add a few more types
This commit is contained in:
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import { IScreensharingOpts } from "../../src/webrtc/mediaHandler";
|
||||
import { IScreensharingOpts, MediaHandler } from "../../src/webrtc/mediaHandler";
|
||||
|
||||
export const DUMMY_SDP = (
|
||||
"v=0\r\n" +
|
||||
@@ -241,20 +241,22 @@ export class MockMediaHandler {
|
||||
stopUserMediaStream(stream: MockMediaStream) {
|
||||
stream.isStopped = true;
|
||||
}
|
||||
getScreensharingStream(opts?: IScreensharingOpts) {
|
||||
getScreensharingStream = jest.fn((opts?: IScreensharingOpts) => {
|
||||
const tracks = [new MockMediaStreamTrack("video_track", "video")];
|
||||
if (opts?.audio) tracks.push(new MockMediaStreamTrack("audio_track", "audio"));
|
||||
|
||||
const stream = new MockMediaStream(SCREENSHARE_STREAM_ID, tracks);
|
||||
this.screensharingStreams.push(stream);
|
||||
return stream;
|
||||
}
|
||||
});
|
||||
stopScreensharingStream(stream: MockMediaStream) {
|
||||
stream.isStopped = true;
|
||||
}
|
||||
hasAudioDevice() { return true; }
|
||||
hasVideoDevice() { return true; }
|
||||
stopAllStreams() {}
|
||||
|
||||
typed(): MediaHandler { return this as unknown as MediaHandler; }
|
||||
}
|
||||
|
||||
export function installWebRTCMocks() {
|
||||
|
@@ -98,35 +98,37 @@ const createAndEnterGroupCall = async (cli: MatrixClient, room: Room): Promise<G
|
||||
};
|
||||
|
||||
class MockCallMatrixClient extends TypedEventEmitter<CallEventHandlerEvent.Incoming, CallEventHandlerEventHandlerMap> {
|
||||
public mediaHandler: MediaHandler = new MockMediaHandler() as unknown as MediaHandler;
|
||||
public mediaHandler = new MockMediaHandler();
|
||||
|
||||
constructor(public userId: string, public deviceId: string, public sessionId: string) {
|
||||
super();
|
||||
}
|
||||
|
||||
groupCallEventHandler = {
|
||||
groupCalls: new Map(),
|
||||
groupCalls: new Map<string, GroupCall>(),
|
||||
};
|
||||
|
||||
callEventHandler = {
|
||||
calls: new Map(),
|
||||
calls: new Map<string, MatrixCall>(),
|
||||
};
|
||||
|
||||
sendStateEvent = jest.fn();
|
||||
sendToDevice = jest.fn();
|
||||
|
||||
getMediaHandler() { return this.mediaHandler; }
|
||||
getMediaHandler(): MediaHandler { return this.mediaHandler.typed(); }
|
||||
|
||||
getUserId() { return this.userId; }
|
||||
getUserId(): string { return this.userId; }
|
||||
|
||||
getDeviceId() { return this.deviceId; }
|
||||
getSessionId() { return this.sessionId; }
|
||||
getDeviceId(): string { return this.deviceId; }
|
||||
getSessionId(): string { return this.sessionId; }
|
||||
|
||||
getTurnServers = () => [];
|
||||
isFallbackICEServerAllowed = () => false;
|
||||
reEmitter = new ReEmitter(new TypedEventEmitter());
|
||||
getUseE2eForGroupCall = () => false;
|
||||
checkTurnServers = () => null;
|
||||
|
||||
typed(): MatrixClient { return this as unknown as MatrixClient; }
|
||||
}
|
||||
|
||||
class MockCall {
|
||||
@@ -732,15 +734,16 @@ describe('Group Call', function() {
|
||||
});
|
||||
|
||||
describe("screensharing", () => {
|
||||
let typedMockClient: MockCallMatrixClient;
|
||||
let mockClient: MatrixClient;
|
||||
let room: Room;
|
||||
let groupCall: GroupCall;
|
||||
|
||||
beforeEach(async () => {
|
||||
const typedMockClient = new MockCallMatrixClient(
|
||||
typedMockClient = new MockCallMatrixClient(
|
||||
FAKE_USER_ID_1, FAKE_DEVICE_ID_1, FAKE_SESSION_ID_1,
|
||||
);
|
||||
mockClient = typedMockClient as unknown as MatrixClient;
|
||||
mockClient = typedMockClient.typed();
|
||||
|
||||
room = new Room(FAKE_ROOM_ID, mockClient, FAKE_USER_ID_1);
|
||||
room.getMember = jest.fn().mockImplementation((userId) => ({ userId }));
|
||||
@@ -761,7 +764,10 @@ describe('Group Call', function() {
|
||||
return call.gotLocalOffer;
|
||||
});
|
||||
|
||||
await groupCall.setScreensharingEnabled(true);
|
||||
let enabledResult;
|
||||
enabledResult = await groupCall.setScreensharingEnabled(true);
|
||||
expect(enabledResult).toEqual(true);
|
||||
expect(typedMockClient.mediaHandler.getScreensharingStream).toHaveBeenCalled();
|
||||
MockRTCPeerConnection.triggerAllNegotiations();
|
||||
|
||||
expect(groupCall.screenshareFeeds).toHaveLength(1);
|
||||
@@ -770,6 +776,17 @@ describe('Group Call', function() {
|
||||
});
|
||||
onNegotiationNeededArray.forEach(f => expect(f).toHaveBeenCalled());
|
||||
|
||||
// Enabling it again should do nothing
|
||||
typedMockClient.mediaHandler.getScreensharingStream.mockClear();
|
||||
enabledResult = await groupCall.setScreensharingEnabled(true);
|
||||
expect(enabledResult).toEqual(true);
|
||||
expect(typedMockClient.mediaHandler.getScreensharingStream).not.toHaveBeenCalled();
|
||||
|
||||
// Should now be able to disable it
|
||||
enabledResult = await groupCall.setScreensharingEnabled(false);
|
||||
expect(enabledResult).toEqual(false);
|
||||
expect(groupCall.screenshareFeeds).toHaveLength(0);
|
||||
|
||||
groupCall.terminate();
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user