Skip to content

Commit

Permalink
handle error
Browse files Browse the repository at this point in the history
  • Loading branch information
shinyoshiaki committed Nov 10, 2023
1 parent 2ec055b commit ba4ae2b
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions packages/ice/src/ice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
});
}
}

Expand Down
4 changes: 3 additions & 1 deletion packages/ice/src/stun/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand Down
9 changes: 6 additions & 3 deletions packages/ice/src/turn/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/ice/src/types/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ export interface Protocol {
responseMessage?: string;
close?: () => Promise<void>;
connectionMade: (...args: any) => Promise<void>;
sendStun: (message: Message, addr: Address) => void;
sendStun: (message: Message, addr: Address) => Promise<void>;
sendData: (data: Buffer, addr: Address) => Promise<void>;
}
2 changes: 1 addition & 1 deletion packages/ice/tests/ice/ice.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
Expand Down
2 changes: 1 addition & 1 deletion packages/ice/tests/stun/stun.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/webrtc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "werift",
"version": "0.18.11",
"version": "0.18.13",
"description": "WebRTC Implementation for TypeScript (Node.js)",
"keywords": [
"WebRTC",
Expand Down

0 comments on commit ba4ae2b

Please sign in to comment.