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.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { IScreensharingOpts } from "../../src/webrtc/mediaHandler";
|
import { IScreensharingOpts, MediaHandler } from "../../src/webrtc/mediaHandler";
|
||||||
|
|
||||||
export const DUMMY_SDP = (
|
export const DUMMY_SDP = (
|
||||||
"v=0\r\n" +
|
"v=0\r\n" +
|
||||||
@@ -241,20 +241,22 @@ export class MockMediaHandler {
|
|||||||
stopUserMediaStream(stream: MockMediaStream) {
|
stopUserMediaStream(stream: MockMediaStream) {
|
||||||
stream.isStopped = true;
|
stream.isStopped = true;
|
||||||
}
|
}
|
||||||
getScreensharingStream(opts?: IScreensharingOpts) {
|
getScreensharingStream = jest.fn((opts?: IScreensharingOpts) => {
|
||||||
const tracks = [new MockMediaStreamTrack("video_track", "video")];
|
const tracks = [new MockMediaStreamTrack("video_track", "video")];
|
||||||
if (opts?.audio) tracks.push(new MockMediaStreamTrack("audio_track", "audio"));
|
if (opts?.audio) tracks.push(new MockMediaStreamTrack("audio_track", "audio"));
|
||||||
|
|
||||||
const stream = new MockMediaStream(SCREENSHARE_STREAM_ID, tracks);
|
const stream = new MockMediaStream(SCREENSHARE_STREAM_ID, tracks);
|
||||||
this.screensharingStreams.push(stream);
|
this.screensharingStreams.push(stream);
|
||||||
return stream;
|
return stream;
|
||||||
}
|
});
|
||||||
stopScreensharingStream(stream: MockMediaStream) {
|
stopScreensharingStream(stream: MockMediaStream) {
|
||||||
stream.isStopped = true;
|
stream.isStopped = true;
|
||||||
}
|
}
|
||||||
hasAudioDevice() { return true; }
|
hasAudioDevice() { return true; }
|
||||||
hasVideoDevice() { return true; }
|
hasVideoDevice() { return true; }
|
||||||
stopAllStreams() {}
|
stopAllStreams() {}
|
||||||
|
|
||||||
|
typed(): MediaHandler { return this as unknown as MediaHandler; }
|
||||||
}
|
}
|
||||||
|
|
||||||
export function installWebRTCMocks() {
|
export function installWebRTCMocks() {
|
||||||
|
@@ -98,35 +98,37 @@ const createAndEnterGroupCall = async (cli: MatrixClient, room: Room): Promise<G
|
|||||||
};
|
};
|
||||||
|
|
||||||
class MockCallMatrixClient extends TypedEventEmitter<CallEventHandlerEvent.Incoming, CallEventHandlerEventHandlerMap> {
|
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) {
|
constructor(public userId: string, public deviceId: string, public sessionId: string) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
groupCallEventHandler = {
|
groupCallEventHandler = {
|
||||||
groupCalls: new Map(),
|
groupCalls: new Map<string, GroupCall>(),
|
||||||
};
|
};
|
||||||
|
|
||||||
callEventHandler = {
|
callEventHandler = {
|
||||||
calls: new Map(),
|
calls: new Map<string, MatrixCall>(),
|
||||||
};
|
};
|
||||||
|
|
||||||
sendStateEvent = jest.fn();
|
sendStateEvent = jest.fn();
|
||||||
sendToDevice = 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; }
|
getDeviceId(): string { return this.deviceId; }
|
||||||
getSessionId() { return this.sessionId; }
|
getSessionId(): string { return this.sessionId; }
|
||||||
|
|
||||||
getTurnServers = () => [];
|
getTurnServers = () => [];
|
||||||
isFallbackICEServerAllowed = () => false;
|
isFallbackICEServerAllowed = () => false;
|
||||||
reEmitter = new ReEmitter(new TypedEventEmitter());
|
reEmitter = new ReEmitter(new TypedEventEmitter());
|
||||||
getUseE2eForGroupCall = () => false;
|
getUseE2eForGroupCall = () => false;
|
||||||
checkTurnServers = () => null;
|
checkTurnServers = () => null;
|
||||||
|
|
||||||
|
typed(): MatrixClient { return this as unknown as MatrixClient; }
|
||||||
}
|
}
|
||||||
|
|
||||||
class MockCall {
|
class MockCall {
|
||||||
@@ -732,15 +734,16 @@ describe('Group Call', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("screensharing", () => {
|
describe("screensharing", () => {
|
||||||
|
let typedMockClient: MockCallMatrixClient;
|
||||||
let mockClient: MatrixClient;
|
let mockClient: MatrixClient;
|
||||||
let room: Room;
|
let room: Room;
|
||||||
let groupCall: GroupCall;
|
let groupCall: GroupCall;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
const typedMockClient = new MockCallMatrixClient(
|
typedMockClient = new MockCallMatrixClient(
|
||||||
FAKE_USER_ID_1, FAKE_DEVICE_ID_1, FAKE_SESSION_ID_1,
|
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 = new Room(FAKE_ROOM_ID, mockClient, FAKE_USER_ID_1);
|
||||||
room.getMember = jest.fn().mockImplementation((userId) => ({ userId }));
|
room.getMember = jest.fn().mockImplementation((userId) => ({ userId }));
|
||||||
@@ -761,7 +764,10 @@ describe('Group Call', function() {
|
|||||||
return call.gotLocalOffer;
|
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();
|
MockRTCPeerConnection.triggerAllNegotiations();
|
||||||
|
|
||||||
expect(groupCall.screenshareFeeds).toHaveLength(1);
|
expect(groupCall.screenshareFeeds).toHaveLength(1);
|
||||||
@@ -770,6 +776,17 @@ describe('Group Call', function() {
|
|||||||
});
|
});
|
||||||
onNegotiationNeededArray.forEach(f => expect(f).toHaveBeenCalled());
|
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();
|
groupCall.terminate();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user