ping-pong-stream
v1.0.0
Published
Most transport streams (e.g. websockets) can detect when they close.
Downloads
13
Readme
PingStream and PongStream
Most transport streams (e.g. websockets) can detect when they close.
Some can't (e.g. window.postMessage)! For those that can't, theres ping-pong-stream
.
const PingStream = require('ping-pong-stream/ping')
const PongStream = require('ping-pong-stream/pong')
const endOfStream = require('end-of-stream')
const pinger = new PingStream()
const ponger = new PongStream()
// ping and pong would normally be in different processes but...
pinger
.pipe(nonSelfClosingTransport)
.pipe(ponger)
.pipe(nonSelfClosingTransport)
.pipe(pinger)
endOfStream(pinger, function(){
// the nonSelfClosingTransport has closed
})
options
// defaults shown
new PingStream({
heartbeatPollingInterval: 1e3,
heartbeatTimeout: 1e2,
heartbeatRequest: 'ping',
heartbeatResponse: 'pong',
})