@libp2p/webrtc
Advanced tools
Comparing version 1.1.7 to 1.1.8
@@ -22,3 +22,4 @@ import { logger } from '@libp2p/logger'; | ||
} | ||
this.timeline.close = new Date().getTime(); | ||
log.trace('closing connection'); | ||
this.timeline.close = Date.now(); | ||
this.peerConnection.close(); | ||
@@ -25,0 +26,0 @@ } |
@@ -94,3 +94,3 @@ import { symbol } from '@libp2p/interface-transport'; | ||
peerConnection: pc, | ||
timeline: { open: (new Date()).getTime() }, | ||
timeline: { open: Date.now() }, | ||
remoteAddr: webrtcMultiaddr | ||
@@ -97,0 +97,0 @@ }), { |
import type { DeferredPromise } from 'p-defer'; | ||
import * as pb from './pb/index.js'; | ||
export declare const isFirefox: boolean; | ||
interface MessageStream { | ||
@@ -4,0 +5,0 @@ read: () => Promise<pb.Message>; |
@@ -5,3 +5,3 @@ import { logger } from '@libp2p/logger'; | ||
const browser = detect(); | ||
const isFirefox = ((browser != null) && browser.name === 'firefox'); | ||
export const isFirefox = ((browser != null) && browser.name === 'firefox'); | ||
const log = logger('libp2p:webrtc:peer:util'); | ||
@@ -8,0 +8,0 @@ export const readCandidatesUntilConnected = async (connectedPromise, pc, stream) => { |
@@ -15,2 +15,3 @@ import { noise as Noise } from '@chainsafe/libp2p-noise'; | ||
import { protocols } from '@multiformats/multiaddr'; | ||
import { isFirefox } from './peer_transport/util.js'; | ||
const log = logger('libp2p:webrtc:transport'); | ||
@@ -73,2 +74,4 @@ /** | ||
async _connect(ma, options) { | ||
const controller = new AbortController(); | ||
const signal = controller.signal; | ||
const remotePeerString = ma.getPeerId(); | ||
@@ -146,2 +149,19 @@ if (remotePeerString === null) { | ||
}; | ||
const eventListeningName = isFirefox ? 'iceconnectionstatechange' : 'connectionstatechange'; | ||
peerConnection.addEventListener(eventListeningName, () => { | ||
switch (peerConnection.connectionState) { | ||
case 'failed': | ||
case 'disconnected': | ||
case 'closed': | ||
maConn.close().catch((err) => { | ||
log.error('error closing connection', err); | ||
}).finally(() => { | ||
// Remove the event listener once the connection is closed | ||
controller.abort(); | ||
}); | ||
break; | ||
default: | ||
break; | ||
} | ||
}, { signal }); | ||
// Creating the connection before completion of the noise | ||
@@ -153,3 +173,3 @@ // handshake ensures that the stream opening callback is set up | ||
timeline: { | ||
open: (new Date()).getTime() | ||
open: Date.now() | ||
} | ||
@@ -156,0 +176,0 @@ }); |
{ | ||
"name": "@libp2p/webrtc", | ||
"version": "1.1.7", | ||
"version": "1.1.8", | ||
"description": "A libp2p transport using WebRTC connections", | ||
@@ -5,0 +5,0 @@ "author": "", |
@@ -64,5 +64,7 @@ import type { MultiaddrConnection, MultiaddrConnectionTimeline } from '@libp2p/interface-connection' | ||
this.timeline.close = new Date().getTime() | ||
log.trace('closing connection') | ||
this.timeline.close = Date.now() | ||
this.peerConnection.close() | ||
} | ||
} |
@@ -134,3 +134,3 @@ import type { Connection } from '@libp2p/interface-connection' | ||
peerConnection: pc, | ||
timeline: { open: (new Date()).getTime() }, | ||
timeline: { open: Date.now() }, | ||
remoteAddr: webrtcMultiaddr | ||
@@ -137,0 +137,0 @@ }), |
@@ -7,3 +7,3 @@ import { logger } from '@libp2p/logger' | ||
const browser = detect() | ||
const isFirefox = ((browser != null) && browser.name === 'firefox') | ||
export const isFirefox = ((browser != null) && browser.name === 'firefox') | ||
@@ -10,0 +10,0 @@ interface MessageStream { |
@@ -19,2 +19,3 @@ import { noise as Noise } from '@chainsafe/libp2p-noise' | ||
import { protocols } from '@multiformats/multiaddr' | ||
import { isFirefox } from './peer_transport/util.js' | ||
@@ -101,2 +102,5 @@ const log = logger('libp2p:webrtc:transport') | ||
async _connect (ma: Multiaddr, options: WebRTCDialOptions): Promise<Connection> { | ||
const controller = new AbortController() | ||
const signal = controller.signal | ||
const remotePeerString = ma.getPeerId() | ||
@@ -188,2 +192,21 @@ if (remotePeerString === null) { | ||
const eventListeningName = isFirefox ? 'iceconnectionstatechange' : 'connectionstatechange' | ||
peerConnection.addEventListener(eventListeningName, () => { | ||
switch (peerConnection.connectionState) { | ||
case 'failed': | ||
case 'disconnected': | ||
case 'closed': | ||
maConn.close().catch((err) => { | ||
log.error('error closing connection', err) | ||
}).finally(() => { | ||
// Remove the event listener once the connection is closed | ||
controller.abort() | ||
}) | ||
break | ||
default: | ||
break | ||
} | ||
}, { signal }) | ||
// Creating the connection before completion of the noise | ||
@@ -195,3 +218,3 @@ // handshake ensures that the stream opening callback is set up | ||
timeline: { | ||
open: (new Date()).getTime() | ||
open: Date.now() | ||
} | ||
@@ -198,0 +221,0 @@ }) |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
635286
5220