Skip to content

Commit

Permalink
Merge pull request #423 from shinyoshiaki:maintain/fix-dtls-start
Browse files Browse the repository at this point in the history
Fix bug in RTCDtlsTransport class
  • Loading branch information
shinyoshiaki authored Oct 13, 2024
2 parents 3f5c392 + e6b048c commit 091da2a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ assignees: ''

---

Pull requests are always welcome.

**Describe the bug**
A clear and concise description of what the bug is.

Expand Down
14 changes: 10 additions & 4 deletions packages/webrtc/src/transport/dtls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,12 @@ export class RTCDtlsTransport {
}

async start() {
if (this.state !== "new") throw new Error();
if (this.remoteParameters?.fingerprints.length === 0) throw new Error();
if (this.state !== "new") {
throw new Error("state must be new");
}
if (this.remoteParameters?.fingerprints.length === 0) {
throw new Error("remote fingerprint not exist");
}

if (this.role === "auto") {
if (this.iceTransport.role === "controlling") {
Expand All @@ -119,7 +123,7 @@ export class RTCDtlsTransport {

this.setState("connecting");

await new Promise<void>(async (r) => {
await new Promise<void>(async (r, f) => {
if (this.role === "server") {
this.dtls = new DtlsServer({
cert: this.localCertificate?.certPem,
Expand Down Expand Up @@ -153,16 +157,18 @@ export class RTCDtlsTransport {
this.setState("closed");
});
this.dtls.onConnect.once(r);
this.dtls.onError.subscribe((error) => {
this.dtls.onError.once((error) => {
this.setState("failed");
log("dtls failed", error);
f(error);
});

if (this.dtls instanceof DtlsClient) {
await setTimeout(100);
this.dtls.connect().catch((error) => {
this.setState("failed");
log("dtls connect failed", error);
f(error);
});
}
});
Expand Down

0 comments on commit 091da2a

Please sign in to comment.