MCPcopy Create free account
hub / github.com/ambianic/peerfetch / _schedulePing

Method _schedulePing

javascript/src/peerfetch.ts:339–356  ·  view source on GitHub ↗

* Schedule periodic pings to keep the datachannel alive. * Some routers and firewalls close open ports within seconds * without data packets flowing through.

()

Source from the content-addressed store, hash-verified

337 * without data packets flowing through.
338 */
339 _schedulePing () {
340 this._keepAlive = setInterval(
341 async () => {
342 // check if there are any pending requests
343 // no ping needed as long as there is traffic on the channel
344 if (!this._pendingRequests()) {
345 try {
346 // request pong to keep the webrtc datachannel connection alive
347 await this.get('ping')
348 } catch (err) {
349 console.warn('ping request timed out while waiting for pong from remote peer.')
350 }
351 }
352 },
353 1000 // every second
354 )
355 console.debug('Pings scheduled.')
356 }
357
358 /**
359 * Stop keepalive pings.

Callers 1

Calls 2

_pendingRequestsMethod · 0.95
getMethod · 0.95

Tested by

no test coverage detected