Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't expose calls on GroupCall #2941

Merged
merged 8 commits into from
Dec 5, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 52 additions & 1 deletion spec/test-utils/webrtc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { EventEmitter } from "stream";
SimonBrandner marked this conversation as resolved.
Show resolved Hide resolved

import {
ClientEvent,
ClientEventHandlerMap,
Expand All @@ -26,14 +28,15 @@ import {
MatrixClient,
MatrixEvent,
Room,
RoomMember,
RoomState,
RoomStateEvent,
RoomStateEventHandlerMap,
} from "../../src";
import { TypedEventEmitter } from "../../src/models/typed-event-emitter";
import { ReEmitter } from "../../src/ReEmitter";
import { SyncState } from "../../src/sync";
import { CallEvent, CallEventHandlerMap, MatrixCall } from "../../src/webrtc/call";
import { CallEvent, CallEventHandlerMap, CallState, MatrixCall } from "../../src/webrtc/call";
import { CallEventHandlerEvent, CallEventHandlerEventHandlerMap } from "../../src/webrtc/callEventHandler";
import { CallFeed } from "../../src/webrtc/callFeed";
import { GroupCallEventHandlerMap } from "../../src/webrtc/groupCall";
Expand Down Expand Up @@ -83,6 +86,17 @@ export const DUMMY_SDP = (
export const USERMEDIA_STREAM_ID = "mock_stream_from_media_handler";
export const SCREENSHARE_STREAM_ID = "mock_screen_stream_from_media_handler";

export const FAKE_ROOM_ID = "!fake:test.dummy";
export const FAKE_CONF_ID = "fakegroupcallid";

export const FAKE_USER_ID_1 = "@alice:test.dummy";
export const FAKE_DEVICE_ID_1 = "@AAAAAA";
export const FAKE_SESSION_ID_1 = "alice1";
export const FAKE_USER_ID_2 = "@bob:test.dummy";
export const FAKE_DEVICE_ID_2 = "@BBBBBB";
export const FAKE_SESSION_ID_2 = "bob1";
export const FAKE_USER_ID_3 = "@charlie:test.dummy";

class MockMediaStreamAudioSourceNode {
public connect() {}
}
Expand Down Expand Up @@ -431,6 +445,43 @@ export class MockCallMatrixClient extends TypedEventEmitter<EmittedEvents, Emitt
}
}

export class MockMatrixCall extends EventEmitter {
constructor(public roomId: string, public groupCallId?: string) {
super();
}

public state = CallState.Ringing;
public opponentUserId = FAKE_USER_ID_1;
public opponentDeviceId = FAKE_DEVICE_ID_1;
public opponentMember = { userId: this.opponentUserId };
public callId = "1";
public localUsermediaFeed = {
setAudioVideoMuted: jest.fn<void, [boolean, boolean]>(),
stream: new MockMediaStream("stream"),
};
public remoteUsermediaFeed?: CallFeed;
public remoteScreensharingFeed?: CallFeed;

public reject = jest.fn<void, []>();
public answerWithCallFeeds = jest.fn<void, [CallFeed[]]>();
public hangup = jest.fn<void, []>();

public sendMetadataUpdate = jest.fn<void, []>();

public on = jest.fn();
public removeListener = jest.fn();

public getOpponentMember(): Partial<RoomMember> {
return this.opponentMember;
}

public getOpponentDeviceId(): string | undefined {
return this.opponentDeviceId;
}

public typed(): MatrixCall { return this as unknown as MatrixCall; }
}

export class MockCallFeed {
constructor(
public userId: string,
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/webrtc/call.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1392,7 +1392,7 @@ describe('Call', function() {
it("ends call on onHangupReceived() if state is ringing", async () => {
expect(call.callHasEnded()).toBe(false);

call.state = CallState.Ringing;
(call as any).state = CallState.Ringing;
call.onHangupReceived({} as MCallHangupReject);

expect(call.callHasEnded()).toBe(true);
Expand Down Expand Up @@ -1424,7 +1424,7 @@ describe('Call', function() {
)("ends call on onRejectReceived() if in correct state (state=%s)", async (state: CallState) => {
expect(call.callHasEnded()).toBe(false);

call.state = state;
(call as any).state = state;
call.onRejectReceived({} as MCallHangupReject);

expect(call.callHasEnded()).toBe(
Expand Down
54 changes: 37 additions & 17 deletions spec/unit/webrtc/callFeed.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,37 @@ limitations under the License.
import { SDPStreamMetadataPurpose } from "../../../src/webrtc/callEventTypes";
import { CallFeed } from "../../../src/webrtc/callFeed";
import { TestClient } from "../../TestClient";
import { MockMediaStream, MockMediaStreamTrack } from "../../test-utils/webrtc";
import { MockMatrixCall, MockMediaStream, MockMediaStreamTrack } from "../../test-utils/webrtc";
import { CallEvent, CallState } from "../../../src/webrtc/call";

describe("CallFeed", () => {
let client;
const roomId = "room1";
let client: TestClient;
let call: MockMatrixCall;
let feed: CallFeed;

beforeEach(() => {
client = new TestClient("@alice:foo", "somedevice", "token", undefined, {});
call = new MockMatrixCall(roomId);

feed = new CallFeed({
client: client.client,
call: call.typed(),
roomId,
userId: "user1",
// @ts-ignore Mock
stream: new MockMediaStream("stream1"),
purpose: SDPStreamMetadataPurpose.Usermedia,
audioMuted: false,
videoMuted: false,
});
});

afterEach(() => {
client.stop();
});

describe("muting", () => {
let feed: CallFeed;

beforeEach(() => {
feed = new CallFeed({
client,
roomId: "room1",
userId: "user1",
// @ts-ignore Mock
stream: new MockMediaStream("stream1"),
purpose: SDPStreamMetadataPurpose.Usermedia,
audioMuted: false,
videoMuted: false,
});
});

describe("muting by default", () => {
it("should mute audio by default", () => {
expect(feed.isAudioMuted()).toBeTruthy();
Expand Down Expand Up @@ -86,4 +88,22 @@ describe("CallFeed", () => {
});
});
});

describe("connected", () => {
it.each([true, false])("should always be connected, if isLocal()", (val: boolean) => {
(feed as any)._connected = val;
jest.spyOn(feed, "isLocal").mockReturnValue(true);

expect(feed.connected).toBeTruthy();
});

it.each([
[CallState.Connected, true],
[CallState.Connecting, false],
])("should react to call state, when !isLocal()", (state: CallState, expected: Boolean) => {
call.emit(CallEvent.State, state);

expect(feed.connected).toBe(expected);
});
});
});
Loading