Skip to content

Commit

Permalink
Improve ice and webrtc connection to use
Browse files Browse the repository at this point in the history
Promise.allSettled
  • Loading branch information
shinyoshiaki committed Nov 10, 2023
1 parent 5f160ec commit 2ec055b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
15 changes: 11 additions & 4 deletions packages/ice/src/ice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export class Connection {
) {
let candidates: Candidate[] = [];

await Promise.all(
await Promise.allSettled(
addresses.map(async (address) => {
// # create transport
const protocol = new StunProtocol(this);
Expand Down Expand Up @@ -257,9 +257,16 @@ export class Connection {
candidatePromises.push(turnCandidate);
}

const extraCandidates = (await Promise.all(candidatePromises)).filter(
(v): v is Candidate => typeof v !== "undefined"
);
const extraCandidates = [...(await Promise.allSettled(candidatePromises))]
.filter(
(
v
): v is PromiseFulfilledResult<
Awaited<typeof candidatePromises[number]>
> => v.status === "fulfilled"
)
.map((v) => v.value)
.filter((v): v is Candidate => typeof v !== "undefined");

candidates.push(...extraCandidates);

Expand Down
6 changes: 3 additions & 3 deletions packages/webrtc/src/peerConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ export class RTCPeerConnection extends EventTarget {
// no need to gather ice candidates on an existing bundled connection
await connected.iceGather.gather();
} else {
await Promise.all(
await Promise.allSettled(
this.iceTransports.map((iceTransport) =>
iceTransport.iceGather.gather()
)
Expand Down Expand Up @@ -755,7 +755,7 @@ export class RTCPeerConnection extends EventTarget {

this.setConnectionState("connecting");

await Promise.all(
await Promise.allSettled(
this.dtlsTransports.map(async (dtlsTransport) => {
const { iceTransport } = dtlsTransport;
await iceTransport.start().catch((err) => {
Expand Down Expand Up @@ -995,7 +995,7 @@ export class RTCPeerConnection extends EventTarget {
// no need to gather ice candidates on an existing bundled connection
await connected.iceGather.gather();
} else {
await Promise.all(
await Promise.allSettled(
transports.map((iceTransport) => iceTransport.iceGather.gather())
);
}
Expand Down

0 comments on commit 2ec055b

Please sign in to comment.