Skip to content

Commit 8375638

Browse files
committed
Fix tests
Bit of a re-organisation so a peerconnection exists when the tests go to mock things out. placeCall methods return promises to make this possible.
1 parent 51e817a commit 8375638

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

spec/unit/webrtc/call.spec.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class MockRTCPeerConnection {
7979
return Promise.resolve();
8080
}
8181
close() {}
82+
getStats() { return []; }
8283
}
8384

8485
describe('Call', function() {
@@ -122,6 +123,7 @@ describe('Call', function() {
122123
// We just stub out sendEvent: we're not interested in testing the client's
123124
// event sending code here
124125
client.client.sendEvent = () => {};
126+
client.httpBackend.when("GET", "/voip/turnServer").respond(200, {});
125127
call = new MatrixCall({
126128
client: client.client,
127129
roomId: '!foo:bar',
@@ -138,7 +140,9 @@ describe('Call', function() {
138140
});
139141

140142
it('should ignore candidate events from non-matching party ID', async function() {
141-
await call.placeVoiceCall();
143+
const callPromise = call.placeVoiceCall();
144+
await client.httpBackend.flush();
145+
await callPromise;
142146
await call.onAnswerReceived({
143147
getContent: () => {
144148
return {
@@ -192,7 +196,9 @@ describe('Call', function() {
192196
});
193197

194198
it('should add candidates received before answer if party ID is correct', async function() {
195-
await call.placeVoiceCall();
199+
const callPromise = call.placeVoiceCall();
200+
await client.httpBackend.flush();
201+
await callPromise;
196202
call.peerConn.addIceCandidate = jest.fn();
197203

198204
call.onRemoteIceCandidatesReceived({

src/webrtc/call.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -333,11 +333,11 @@ export class MatrixCall extends EventEmitter {
333333
* Place a voice call to this room.
334334
* @throws If you have not specified a listener for 'error' events.
335335
*/
336-
placeVoiceCall() {
336+
async placeVoiceCall() {
337337
logger.debug("placeVoiceCall");
338338
this.checkForErrorListener();
339339
const constraints = getUserMediaContraints(ConstraintsType.Audio);
340-
this.placeCallWithConstraints(constraints);
340+
await this.placeCallWithConstraints(constraints);
341341
this.type = CallType.Voice;
342342
}
343343

@@ -349,13 +349,13 @@ export class MatrixCall extends EventEmitter {
349349
* to render the local camera preview.
350350
* @throws If you have not specified a listener for 'error' events.
351351
*/
352-
placeVideoCall(remoteVideoElement: HTMLVideoElement, localVideoElement: HTMLVideoElement) {
352+
async placeVideoCall(remoteVideoElement: HTMLVideoElement, localVideoElement: HTMLVideoElement) {
353353
logger.debug("placeVideoCall");
354354
this.checkForErrorListener();
355355
this.localVideoElement = localVideoElement;
356356
this.remoteVideoElement = remoteVideoElement;
357357
const constraints = getUserMediaContraints(ConstraintsType.Video);
358-
this.placeCallWithConstraints(constraints);
358+
await this.placeCallWithConstraints(constraints);
359359
this.type = CallType.Video;
360360
}
361361

@@ -864,7 +864,6 @@ export class MatrixCall extends EventEmitter {
864864

865865
// why do we enable audio (and only audio) tracks here? -- matthew
866866
setTracksEnabled(stream.getAudioTracks(), true);
867-
this.peerConn = this.createPeerConnection();
868867

869868
for (const audioTrack of stream.getAudioTracks()) {
870869
logger.info("Adding audio track with id " + audioTrack.id);
@@ -1677,11 +1676,10 @@ export class MatrixCall extends EventEmitter {
16771676
logger.warn("Failed to get TURN credentials! Proceeding with call anyway...");
16781677
}
16791678

1680-
// It would be really nice if we could start gathering candidates at this point
1681-
// so the ICE agent could be gathering while we open our media devices: we already
1682-
// know the type of the call and therefore what tracks we want to send.
1683-
// Perhaps we could do this by making fake tracks now and then using replaceTrack()
1684-
// once we have the actual tracks? (Can we make fake tracks?)
1679+
// create the peer connection now so it can be gathering candidates while we get user
1680+
// media (assuming a candidate pool size is configured)
1681+
this.peerConn = this.createPeerConnection();
1682+
16851683
try {
16861684
const mediaStream = await navigator.mediaDevices.getUserMedia(constraints);
16871685
this.gotUserMediaForInvite(mediaStream);

0 commit comments

Comments
 (0)