Skip to content

Commit

Permalink
fix: Should not fail to generate sdp due to the mapping failure
Browse files Browse the repository at this point in the history
  • Loading branch information
ci010 committed Dec 10, 2023
1 parent 15c3487 commit 5c9e0b0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 3 additions & 1 deletion xmcl-runtime/peer/PeerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,9 @@ export class PeerService extends StatefulService<PeerState> implements IPeerServ
const [ip, port] = parseCandidate(candidate.candidate)
if (ip && port) {
const state = await natService.getNatState()
await mapLocalPort(natService, state.localIp, privatePort, Number(port), this)
await mapLocalPort(natService, state.localIp, privatePort, Number(port), this).catch((e) => {
this.error(e)
})
}
}
if (remoteId) {
Expand Down
10 changes: 9 additions & 1 deletion xmcl-runtime/peer/mapAndGetPortCanidate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,15 @@ export async function mapLocalPort(natService: NatService, ip: string, priv: num
const candidates = getUnmapCandidates(currentMappings, mappings)
console.log(candidates)
for (const c of candidates) {
await natService.unmap(c)
await natService.unmap(c).catch(() => {})
}
await Promise.all(mappings.map(n => natService.map(n)))
} else if (err.detail.UPnPError && err.detail.UPnPError.errorCode === 718) {
// Conflict
const candidates = getUnmapCandidates(currentMappings, mappings)
console.log(candidates)
for (const c of candidates) {
await natService.unmap(c).catch(() => {})
}
await Promise.all(mappings.map(n => natService.map(n)))
} else {
Expand Down

0 comments on commit 5c9e0b0

Please sign in to comment.