From ba4ae2b08991c5f170aed6a04821601b297c21e9 Mon Sep 17 00:00:00 2001 From: shinyoshiaki Date: Fri, 10 Nov 2023 12:42:53 +0900 Subject: [PATCH] handle error --- package-lock.json | 2 +- packages/ice/src/ice.ts | 8 ++++++-- packages/ice/src/stun/transaction.ts | 4 +++- packages/ice/src/turn/protocol.ts | 9 ++++++--- packages/ice/src/types/model.ts | 2 +- packages/ice/tests/ice/ice.test.ts | 2 +- packages/ice/tests/stun/stun.test.ts | 2 +- packages/webrtc/package.json | 2 +- 8 files changed, 20 insertions(+), 11 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7daf43b21..d1ed12ae8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6377,7 +6377,7 @@ }, "packages/webrtc": { "name": "werift", - "version": "0.18.11", + "version": "0.18.13", "license": "MIT", "dependencies": { "@fidm/x509": "^1.2.1", diff --git a/packages/ice/src/ice.ts b/packages/ice/src/ice.ts index ab39d3d06..44f389b40 100644 --- a/packages/ice/src/ice.ts +++ b/packages/ice/src/ice.ts @@ -633,7 +633,9 @@ export class Connection { .setAttribute("XOR-MAPPED-ADDRESS", addr) .addMessageIntegrity(Buffer.from(this.localPassword, "utf8")) .addFingerprint(); - protocol.sendStun(response, addr); + protocol.sendStun(response, addr).catch((e) => { + log("sendStun error", e); + }); // todo fix // if (this.checkList.length === 0) { @@ -996,7 +998,9 @@ export class Connection { .setAttribute("ERROR-CODE", errorCode) .addMessageIntegrity(Buffer.from(this.localPassword, "utf8")) .addFingerprint(); - protocol.sendStun(response, addr); + protocol.sendStun(response, addr).catch((e) => { + log("sendStun error", e); + }); } } diff --git a/packages/ice/src/stun/transaction.ts b/packages/ice/src/stun/transaction.ts index 19021f8f4..109e66241 100644 --- a/packages/ice/src/stun/transaction.ts +++ b/packages/ice/src/stun/transaction.ts @@ -62,7 +62,9 @@ export class Transaction { this.onResponse.error(new TransactionTimeout()); return; } - this.protocol.sendStun(this.request, this.addr); + this.protocol.sendStun(this.request, this.addr).catch((e) => { + log("send stun failed", e); + }); this.timeoutHandle = setTimeout(this.retry, this.timeoutDelay); this.timeoutDelay *= 2; this.tries++; diff --git a/packages/ice/src/turn/protocol.ts b/packages/ice/src/turn/protocol.ts index ccce781f2..a0664a914 100644 --- a/packages/ice/src/turn/protocol.ts +++ b/packages/ice/src/turn/protocol.ts @@ -266,7 +266,10 @@ class TurnClient implements Protocol { this.channel = { number: this.channelNumber++, address: addr }; this.channelBinding = this.channelBind(this.channel.number, addr); - await this.channelBinding; + await this.channelBinding.catch((e) => { + log("channelBind error", e); + throw e; + }); this.channelBinding = undefined; log("channelBind", this.channel); } @@ -284,8 +287,8 @@ class TurnClient implements Protocol { } } - sendStun(message: Message, addr: Address) { - this.transport.send(message.bytes, addr); + async sendStun(message: Message, addr: Address) { + await this.transport.send(message.bytes, addr); } } diff --git a/packages/ice/src/types/model.ts b/packages/ice/src/types/model.ts index c3b939b61..ce81e1fb6 100644 --- a/packages/ice/src/types/model.ts +++ b/packages/ice/src/types/model.ts @@ -17,6 +17,6 @@ export interface Protocol { responseMessage?: string; close?: () => Promise; connectionMade: (...args: any) => Promise; - sendStun: (message: Message, addr: Address) => void; + sendStun: (message: Message, addr: Address) => Promise; sendData: (data: Buffer, addr: Address) => Promise; } diff --git a/packages/ice/tests/ice/ice.test.ts b/packages/ice/tests/ice/ice.test.ts index 51aaf1fd6..8b285d892 100644 --- a/packages/ice/tests/ice/ice.test.ts +++ b/packages/ice/tests/ice/ice.test.ts @@ -24,7 +24,7 @@ class ProtocolMock implements Protocol { request = async () => { return null as any; }; - sendStun = (message: Message) => { + sendStun = async (message: Message) => { this.sentMessage = message; }; async connectionMade() {} diff --git a/packages/ice/tests/stun/stun.test.ts b/packages/ice/tests/stun/stun.test.ts index 469bdda1c..72357ac62 100644 --- a/packages/ice/tests/stun/stun.test.ts +++ b/packages/ice/tests/stun/stun.test.ts @@ -122,7 +122,7 @@ describe("stun", () => { test( "test_timeout", async () => { - const DummyProtocol: any = { sendStun: () => {} }; + const DummyProtocol: any = { sendStun: async () => {} }; const request = new Message(methods.BINDING, classes.REQUEST); const transaction = new Transaction( request, diff --git a/packages/webrtc/package.json b/packages/webrtc/package.json index c33644d30..2d5e9eb2f 100644 --- a/packages/webrtc/package.json +++ b/packages/webrtc/package.json @@ -1,6 +1,6 @@ { "name": "werift", - "version": "0.18.11", + "version": "0.18.13", "description": "WebRTC Implementation for TypeScript (Node.js)", "keywords": [ "WebRTC",