You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-26 17:03:12 +03:00
Make test pass
Don't send events all the way via the mock HTTP backend: we're not trying to test that here. This meant we weren't actually getting into the right state because the request to send the invite never actually returned. Now this works, we need to clear the invite timer otherwise jest has a timer hanging around at the end of the test (plus we should be doing it anyway).
This commit is contained in:
@@ -15,7 +15,7 @@ limitations under the License.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {TestClient} from '../../TestClient';
|
import {TestClient} from '../../TestClient';
|
||||||
import {MatrixCall} from '../../../src/webrtc/call';
|
import {MatrixCall, CallErrorCode} from '../../../src/webrtc/call';
|
||||||
|
|
||||||
const DUMMY_SDP = (
|
const DUMMY_SDP = (
|
||||||
"v=0\r\n" +
|
"v=0\r\n" +
|
||||||
@@ -78,6 +78,7 @@ class MockRTCPeerConnection {
|
|||||||
setLocalDescription() {
|
setLocalDescription() {
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
close() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('Call', function() {
|
describe('Call', function() {
|
||||||
@@ -118,6 +119,9 @@ describe('Call', function() {
|
|||||||
global.document = {};
|
global.document = {};
|
||||||
|
|
||||||
client = new TestClient("@alice:foo", "somedevice", "token", undefined, {});
|
client = new TestClient("@alice:foo", "somedevice", "token", undefined, {});
|
||||||
|
// We just stub out sendEvent: we're not interested in testing the client's
|
||||||
|
// event sending code here
|
||||||
|
client.client.sendEvent = () => {};
|
||||||
call = new MatrixCall({
|
call = new MatrixCall({
|
||||||
client: client.client,
|
client: client.client,
|
||||||
roomId: '!foo:bar',
|
roomId: '!foo:bar',
|
||||||
@@ -135,12 +139,16 @@ describe('Call', function() {
|
|||||||
|
|
||||||
it('should ignore candidate events from non-matching party ID', async function() {
|
it('should ignore candidate events from non-matching party ID', async function() {
|
||||||
await call.placeVoiceCall();
|
await call.placeVoiceCall();
|
||||||
await call.receivedAnswer({
|
await call.onAnswerReceived({
|
||||||
version: 0,
|
getContent: () => {
|
||||||
call_id: call.callId,
|
return {
|
||||||
party_id: 'the_correct_party_id',
|
version: 0,
|
||||||
answer: {
|
call_id: call.callId,
|
||||||
sdp: DUMMY_SDP,
|
party_id: 'the_correct_party_id',
|
||||||
|
answer: {
|
||||||
|
sdp: DUMMY_SDP,
|
||||||
|
},
|
||||||
|
};
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -178,5 +186,8 @@ describe('Call', function() {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
expect(call.peerConn.addIceCandidate.mock.calls.length).toBe(1);
|
expect(call.peerConn.addIceCandidate.mock.calls.length).toBe(1);
|
||||||
|
|
||||||
|
// Hangup to stop timers
|
||||||
|
call.hangup(CallErrorCode.UserHangup, true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -236,6 +236,7 @@ export class MatrixCall extends EventEmitter {
|
|||||||
// The party ID of the other side: undefined if we haven't chosen a partner
|
// The party ID of the other side: undefined if we haven't chosen a partner
|
||||||
// yet, null if we have but they didn't send a party ID.
|
// yet, null if we have but they didn't send a party ID.
|
||||||
private opponentPartyId: string;
|
private opponentPartyId: string;
|
||||||
|
private inviteTimeout;
|
||||||
|
|
||||||
constructor(opts: CallOpts) {
|
constructor(opts: CallOpts) {
|
||||||
super();
|
super();
|
||||||
@@ -941,7 +942,8 @@ export class MatrixCall extends EventEmitter {
|
|||||||
try {
|
try {
|
||||||
await this.sendVoipEvent(EventType.CallInvite, content);
|
await this.sendVoipEvent(EventType.CallInvite, content);
|
||||||
this.setState(CallState.InviteSent);
|
this.setState(CallState.InviteSent);
|
||||||
setTimeout(() => {
|
this.inviteTimeout = setTimeout(() => {
|
||||||
|
this.inviteTimeout = null;
|
||||||
if (this.state === CallState.InviteSent) {
|
if (this.state === CallState.InviteSent) {
|
||||||
this.hangup(CallErrorCode.InviteTimeout, false);
|
this.hangup(CallErrorCode.InviteTimeout, false);
|
||||||
}
|
}
|
||||||
@@ -1165,6 +1167,11 @@ export class MatrixCall extends EventEmitter {
|
|||||||
private terminate(hangupParty: CallParty, hangupReason: CallErrorCode, shouldEmit: boolean) {
|
private terminate(hangupParty: CallParty, hangupReason: CallErrorCode, shouldEmit: boolean) {
|
||||||
if (this.state === CallState.Ended) return;
|
if (this.state === CallState.Ended) return;
|
||||||
|
|
||||||
|
if (this.inviteTimeout) {
|
||||||
|
clearTimeout(this.inviteTimeout);
|
||||||
|
this.inviteTimeout = null;
|
||||||
|
}
|
||||||
|
|
||||||
const remoteVid = this.getRemoteVideoElement();
|
const remoteVid = this.getRemoteVideoElement();
|
||||||
const remoteAud = this.getRemoteAudioElement();
|
const remoteAud = this.getRemoteAudioElement();
|
||||||
const localVid = this.getLocalVideoElement();
|
const localVid = this.getLocalVideoElement();
|
||||||
|
|||||||
Reference in New Issue
Block a user