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

Revert "Add the call object to Call events" #3236

Merged
merged 1 commit into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 0 additions & 7 deletions spec/test-utils/webrtc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ export class MockRTCPeerConnection {
public iceCandidateListener?: (e: RTCPeerConnectionIceEvent) => void;
public iceConnectionStateChangeListener?: () => void;
public onTrackListener?: (e: RTCTrackEvent) => void;
public onDataChannelListener?: (ev: RTCDataChannelEvent) => void;
public needsNegotiation = false;
public readyToNegotiate: Promise<void>;
private onReadyToNegotiate?: () => void;
Expand Down Expand Up @@ -169,8 +168,6 @@ export class MockRTCPeerConnection {
this.iceConnectionStateChangeListener = listener;
} else if (type == "track") {
this.onTrackListener = listener;
} else if (type == "datachannel") {
this.onDataChannelListener = listener;
}
}
public createDataChannel(label: string, opts: RTCDataChannelInit) {
Expand Down Expand Up @@ -235,10 +232,6 @@ export class MockRTCPeerConnection {
this.negotiationNeededListener();
}
}

public triggerIncomingDataChannel(): void {
this.onDataChannelListener?.({ channel: {} } as RTCDataChannelEvent);
}
}

export class MockRTCRtpSender {
Expand Down
62 changes: 2 additions & 60 deletions spec/unit/webrtc/call.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,33 +431,6 @@ describe("Call", function () {
expect(transceivers.get("m.usermedia:video")!.sender.track!.id).toBe("usermedia_video_track");
});

it("should handle error on call upgrade", async () => {
const onError = jest.fn();
call.on(CallEvent.Error, onError);

await startVoiceCall(client, call);

await call.onAnswerReceived(
makeMockEvent("@test:foo", {
version: 1,
call_id: call.callId,
party_id: "party_id",
answer: {
sdp: DUMMY_SDP,
},
[SDPStreamMetadataKey]: {},
}),
);

const mockGetUserMediaStream = jest.fn().mockRejectedValue(new Error("Test error"));
client.client.getMediaHandler().getUserMediaStream = mockGetUserMediaStream;

// then unmute which should cause an upgrade
await call.setLocalVideoMuted(false);

expect(onError).toHaveBeenCalled();
});

it("should unmute video after upgrading to video call", async () => {
// Regression test for https://github.com/vector-im/element-call/issues/925
await startVoiceCall(client, call);
Expand Down Expand Up @@ -764,22 +737,11 @@ describe("Call", function () {

const dataChannel = call.createDataChannel("data_channel_label", { id: 123 });

expect(dataChannelCallback).toHaveBeenCalledWith(dataChannel, call);
expect(dataChannelCallback).toHaveBeenCalledWith(dataChannel);
expect(dataChannel.label).toBe("data_channel_label");
expect(dataChannel.id).toBe(123);
});

it("should emit a data channel event when the other side adds a data channel", async () => {
await startVoiceCall(client, call);

const dataChannelCallback = jest.fn();
call.on(CallEvent.DataChannel, dataChannelCallback);

(call.peerConn as unknown as MockRTCPeerConnection).triggerIncomingDataChannel();

expect(dataChannelCallback).toHaveBeenCalled();
});

describe("supportsMatrixCall", () => {
it("should return true when the environment is right", () => {
expect(supportsMatrixCall()).toBe(true);
Expand Down Expand Up @@ -1642,7 +1604,7 @@ describe("Call", function () {
hasAdvancedBy += advanceBy;

expect(lengthChangedListener).toHaveBeenCalledTimes(hasAdvancedBy);
expect(lengthChangedListener).toHaveBeenCalledWith(hasAdvancedBy, call);
expect(lengthChangedListener).toHaveBeenCalledWith(hasAdvancedBy);
}
});

Expand Down Expand Up @@ -1672,24 +1634,4 @@ describe("Call", function () {
expect(call.hangup).not.toHaveBeenCalled();
});
});

describe("Call replace", () => {
it("Fires event when call replaced", async () => {
const onReplace = jest.fn();
call.on(CallEvent.Replaced, onReplace);

await call.placeVoiceCall();

const call2 = new MatrixCall({
client: client.client,
roomId: FAKE_ROOM_ID,
});
call2.on(CallEvent.Error, errorListener);
await fakeIncomingCall(client, call2);

call.replacedBy(call2);

expect(onReplace).toHaveBeenCalled();
});
});
});
2 changes: 1 addition & 1 deletion spec/unit/webrtc/callFeed.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe("CallFeed", () => {
[CallState.Connected, true],
[CallState.Connecting, false],
])("should react to call state, when !isLocal()", (state: CallState, expected: Boolean) => {
call.emit(CallEvent.State, state, CallState.InviteSent, call.typed());
call.emit(CallEvent.State, state);

expect(feed.connected).toBe(expected);
});
Expand Down
6 changes: 3 additions & 3 deletions spec/unit/webrtc/groupCall.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ describe("Group Call", function () {
call.isLocalVideoMuted = jest.fn().mockReturnValue(true);
call.setLocalVideoMuted = jest.fn();

call.emit(CallEvent.State, CallState.Connected, CallState.InviteSent, call);
call.emit(CallEvent.State, CallState.Connected);

expect(call.setMicrophoneMuted).toHaveBeenCalledWith(false);
expect(call.setLocalVideoMuted).toHaveBeenCalledWith(false);
Expand Down Expand Up @@ -1154,7 +1154,7 @@ describe("Group Call", function () {
});

it("handles regular case", () => {
oldMockCall.emit(CallEvent.Replaced, newMockCall.typed(), oldMockCall.typed());
oldMockCall.emit(CallEvent.Replaced, newMockCall.typed());

expect(oldMockCall.hangup).toHaveBeenCalled();
expect(callChangedListener).toHaveBeenCalledWith(newCallsMap);
Expand All @@ -1165,7 +1165,7 @@ describe("Group Call", function () {
it("handles case where call is missing from the calls map", () => {
// @ts-ignore
groupCall.calls = new Map();
oldMockCall.emit(CallEvent.Replaced, newMockCall.typed(), oldMockCall.typed());
oldMockCall.emit(CallEvent.Replaced, newMockCall.typed());

expect(oldMockCall.hangup).toHaveBeenCalled();
expect(callChangedListener).toHaveBeenCalledWith(newCallsMap);
Expand Down
Loading