1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2026-01-03 23:22:30 +03:00

Provide better error for ICE Server SyntaxError (#3694)

* Provide better error for ICE Server SyntaxError

* Refactor

* Add test
This commit is contained in:
Michael Telatynski
2023-09-05 15:18:30 +01:00
committed by GitHub
parent d7831f9e5b
commit 8e0ef98bcc
2 changed files with 53 additions and 3 deletions

View File

@@ -47,6 +47,7 @@ import {
} from "../../test-utils/webrtc";
import { CallFeed } from "../../../src/webrtc/callFeed";
import { EventType, IContent, ISendEventResponse, MatrixEvent, Room } from "../../../src";
import { emitPromise } from "../../test-utils/test-utils";
const FAKE_ROOM_ID = "!foo:bar";
const CALL_LIFETIME = 60000;
@@ -1812,4 +1813,30 @@ describe("Call", function () {
expect(call.peerConn?.setRemoteDescription).toHaveBeenCalled();
});
});
it("should emit IceFailed error on the successor call if RTCPeerConnection throws", async () => {
// @ts-ignore - writing to window as we are simulating browser edge-cases
global.window = {};
Object.defineProperty(global.window, "RTCPeerConnection", {
get: () => {
throw Error("Secure mode, naaah!");
},
});
const call = new MatrixCall({
client: client.client,
roomId: "!room_id",
});
const successor = new MatrixCall({
client: client.client,
roomId: "!room_id",
});
call.replacedBy(successor);
const prom = emitPromise(successor, CallEvent.Error);
call.placeCall(true, true);
const err = await prom;
expect(err.code).toBe(CallErrorCode.IceFailed);
});
});

View File

@@ -2220,7 +2220,7 @@ export class MatrixCall extends TypedEventEmitter<CallEvent, CallEventHandlerMap
CallEvent.Error,
new CallError(
CallErrorCode.NoUserMedia,
"Couldn't start capturing media! Is your microphone set up and " + "does this app have permission?",
"Couldn't start capturing media! Is your microphone set up and does this app have permission?",
err,
),
this,
@@ -2228,6 +2228,22 @@ export class MatrixCall extends TypedEventEmitter<CallEvent, CallEventHandlerMap
this.terminate(CallParty.Local, CallErrorCode.NoUserMedia, false);
};
private placeCallFailed = (err: Error): void => {
if (this.successor) {
this.successor.placeCallFailed(err);
return;
}
logger.warn(`Call ${this.callId} placeCallWithCallFeeds() failed - ending call`, err);
this.emit(
CallEvent.Error,
new CallError(CallErrorCode.IceFailed, "Couldn't start call! Invalid ICE server configuration.", err),
this,
);
this.terminate(CallParty.Local, CallErrorCode.IceFailed, false);
};
private onIceConnectionStateChanged = (): void => {
if (this.callHasEnded()) {
return; // because ICE can still complete as we're ending the call
@@ -2775,6 +2791,7 @@ export class MatrixCall extends TypedEventEmitter<CallEvent, CallEventHandlerMap
}
this.state = CallState.WaitLocalMedia;
let callFeed: CallFeed;
try {
const stream = await this.client.getMediaHandler().getUserMediaStream(audio, video);
@@ -2783,7 +2800,7 @@ export class MatrixCall extends TypedEventEmitter<CallEvent, CallEventHandlerMap
setTracksEnabled(stream.getAudioTracks(), true);
setTracksEnabled(stream.getVideoTracks(), true);
const callFeed = new CallFeed({
callFeed = new CallFeed({
client: this.client,
roomId: this.roomId,
userId: this.client.getUserId()!,
@@ -2793,11 +2810,17 @@ export class MatrixCall extends TypedEventEmitter<CallEvent, CallEventHandlerMap
audioMuted: false,
videoMuted: false,
});
await this.placeCallWithCallFeeds([callFeed]);
} catch (e) {
this.getUserMediaFailed(<Error>e);
return;
}
try {
await this.placeCallWithCallFeeds([callFeed]);
} catch (e) {
this.placeCallFailed(<Error>e);
return;
}
}
/**