create (path, options) { if (!net) return this.emit('error', new Error('No IPC transport')) this.socket = net.connect({ path }) this.socket.on('connect', () => { this.emit('connect') this.socket.on('close', () => { if (this.socket) this.socket.destroy() this.onClose() }) if (net.constructor.name === 'Socket') { oboe(this.socket).done(payloads => this.emitPayloads(payloads)) } else { this.socket.on('data', data => parse(data.toString(), (err, payloads) => { if (!err) this.emitPayloads(payloads) })) } }) this.socket.on('error', err => this.emit('error', err)) }
function startStreamListener(endpoint, gameId) { console.log(`Starting stream at ${endpoint}`); oboe({ method: "GET", url: `${urlStub}/${endpoint}`, headers: headersGet }) .node("!", function(data) { console.log("STREAM data : " + JSON.stringify(data.type)); if (handlers[data.type]) { let munged = { gameId: gameId }; munged = Object.assign(munged, data); handlers[data.type](munged); } }) .fail(function(errorReport) { console.error(`Failure to get ${endpoint}:`); console.error(JSON.stringify(errorReport)); // Retry setTimeout(function() { startStreamListener(endpoint, gameId); }, 10000); }); }