Skip to content

Commit

Permalink
Add Protoo failure logging and lower the retries.
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo committed Mar 31, 2021
1 parent aff3db9 commit 0d2817e
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions src/naf-dialog-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
Expand All @@ -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}`);
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 0d2817e

Please sign in to comment.