* Schedule periodic pings to keep the datachannel alive. * Some routers and firewalls close open ports within seconds * without data packets flowing through.
()
| 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. |
no test coverage detected