fix: clean up old rtcPeerConnections
This commit is contained in:
parent
a4b7c8e9ce
commit
38509019fd
@ -71,12 +71,15 @@ export const useConnectionTest = () => {
|
||||
setHasRelay(false)
|
||||
console.error(e)
|
||||
}
|
||||
|
||||
return connectionTest
|
||||
}
|
||||
|
||||
;(async () => {
|
||||
while (true) {
|
||||
await checkConnection()
|
||||
const connectionTest = await checkConnection()
|
||||
await sleep(pollInterval)
|
||||
connectionTest.destroy()
|
||||
}
|
||||
})()
|
||||
}, [])
|
||||
|
@ -15,16 +15,18 @@ export class ConnectionTest extends EventTarget {
|
||||
hasPeerReflexive = false
|
||||
hasServerReflexive = false
|
||||
|
||||
rtcPeerConnection?: RTCPeerConnection
|
||||
|
||||
async runRtcPeerConnectionTest() {
|
||||
if (typeof RTCPeerConnection === 'undefined') return
|
||||
|
||||
const { iceServers } = rtcConfig
|
||||
|
||||
const rtcPeerConnection = new RTCPeerConnection({
|
||||
this.rtcPeerConnection = new RTCPeerConnection({
|
||||
iceServers,
|
||||
})
|
||||
|
||||
rtcPeerConnection.addEventListener('icecandidate', event => {
|
||||
this.rtcPeerConnection.addEventListener('icecandidate', event => {
|
||||
if (event.candidate?.candidate.length) {
|
||||
const parsedCandidate = parseCandidate(event.candidate.candidate)
|
||||
let eventType: ConnectionTestEvents | undefined
|
||||
@ -65,13 +67,17 @@ export class ConnectionTest extends EventTarget {
|
||||
|
||||
// Kick off the connection test
|
||||
try {
|
||||
const rtcSessionDescription = await rtcPeerConnection.createOffer({
|
||||
const rtcSessionDescription = await this.rtcPeerConnection.createOffer({
|
||||
offerToReceiveAudio: true,
|
||||
})
|
||||
|
||||
rtcPeerConnection.setLocalDescription(rtcSessionDescription)
|
||||
this.rtcPeerConnection.setLocalDescription(rtcSessionDescription)
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
destroy() {
|
||||
this.rtcPeerConnection?.close()
|
||||
}
|
||||
}
|
||||
|
||||
export const connectionTest = new ConnectionTest()
|
||||
|
Loading…
x
Reference in New Issue
Block a user