diff --git a/src/naf-dialog-adapter.js b/src/naf-dialog-adapter.js index 7ddb8b9f3a..65a79e8fd8 100644 --- a/src/naf-dialog-adapter.js +++ b/src/naf-dialog-adapter.js @@ -287,9 +287,28 @@ export default class DialogAdapter extends EventEmitter { urlWithParams.searchParams.append("roomId", this._roomId); urlWithParams.searchParams.append("peerId", this._clientId); - const protooTransport = new protooClient.WebSocketTransport(urlWithParams.toString()); + const protooTransport = new protooClient.WebSocketTransport(urlWithParams.toString(), { + retry: { + retries: 3 + } + }); this._protoo = new protooClient.Peer(protooTransport); + this._protoo.on("disconnected", () => { + this.emitRTCEvent("info", "Signaling", () => `Diconnected`); + this.disconnect(); + }); + + this._protoo.on("close", () => { + this.emitRTCEvent("error", "Signaling", () => `Closed`); + this.disconnect(); + this.emit("closed", "Signaling has been closed."); + }); + + this._protoo.on("failed", attempt => { + this.emitRTCEvent("error", "Signaling", () => `Failed: ${attempt}`); + }); + await new Promise((resolve, reject) => { this._protoo.on("open", async () => { this.emitRTCEvent("info", "Signaling", () => `Open`); @@ -304,17 +323,6 @@ export default class DialogAdapter extends EventEmitter { }); }); - this._protoo.on("disconnected", () => { - this.emitRTCEvent("info", "Signaling", () => `Diconnected`); - this.disconnect(); - }); - - this._protoo.on("close", () => { - this.emitRTCEvent("error", "Signaling", () => `Closed`); - this.disconnect(); - this.emit("closed", "Signaling has been closed."); - }); - // eslint-disable-next-line no-unused-vars this._protoo.on("request", async (request, accept, reject) => { this.emitRTCEvent("info", "Signaling", () => `Request [${request.method}]: ${request.data?.id}`); @@ -651,7 +659,7 @@ export default class DialogAdapter extends EventEmitter { this._videoProducer = null; } - if (!this._sendTransport?._closed) { + if (this._sendTransport && !this._sendTransport._closed) { this._sendTransport.close(); } @@ -720,7 +728,7 @@ export default class DialogAdapter extends EventEmitter { } async closeRecvTransport() { - if (!this._recvTransport?._closed) { + if (this._recvTransport && !this._recvTransport._closed) { this._recvTransport.close(); } if (this._protoo.connected) {