var listener = function(data) { if (data.toString('utf8').indexOf('Done') === -1) return; child.stdout.removeListener('data', listener); clearTimeout(timeout); active = true; process.on('exit', function() { child.kill('SIGINT'); }); resolve(new Tor(child, port, dir)); }
// Create a route that will respond to a POST request app.get('/command', function(request, response) { // Get the command from the HTTP request and send it to the Minecraft // server process var command = request.param('Body'); minecraftServerProcess.stdin.write(command+'\n'); // buffer output for a quarter of a second, then reply to HTTP request var buffer = []; var collector = function(data) { data = data.toString(); buffer.push(data.split(']: ')[1]); }; minecraftServerProcess.stdout.on('data', collector); setTimeout(function() { minecraftServerProcess.stdout.removeListener('data', collector); response.send(buffer.join('')); }, 250); });
/** * Deactivates the gateway components specified to be disabled in [gatewayConfig]{@link localtunnel#gatewayConfig} and * updates the updates the [started]{@link localtunnel#started}. * * @return {Promise} The returned promise resolves when the gateway is stopped and no longer sending * or receiving data. */ stop() { var promise = new Promise((resolve, reject) => { this._tunnelProc.stdout._openResolve = null; this._tunnelProc.stdout._openReject = null; this._tunnelProc.stdout.gateway = null; this._tunnelProc.stdout.removeListener('data', this.onTunnelSTDOUT); this._tunnelProc.stderr.removeListener('data', this.onTunnelSTDERR); this._tunnelProc.kill('SIGTERM'); delete this._tunnelProc; this._started = false; resolve(true); }); return (promise); }
function runScript(script, scriptArgs, inspectHost, inspectPort, childPrint) { return portIsFree(inspectHost, inspectPort) .then(() => { return new Promise((resolve) => { const needDebugBrk = process.version.match(/^v(6|7)\./); const args = (needDebugBrk ? ['--inspect', `--debug-brk=${inspectPort}`] : [`--inspect-brk=${inspectPort}`]) .concat([script], scriptArgs); const child = spawn(process.execPath, args); child.stdout.setEncoding('utf8'); child.stderr.setEncoding('utf8'); child.stdout.on('data', childPrint); child.stderr.on('data', childPrint); let output = ''; function waitForListenHint(text) { output += text; if (/Debugger listening on ws:\/\/\[?(.+?)\]?:(\d+)\//.test(output)) { const host = RegExp.$1; const port = Number.parseInt(RegExp.$2); child.stderr.removeListener('data', waitForListenHint); resolve([child, port, host]); } } child.stderr.on('data', waitForListenHint); }); }); }
router.get(/^\/live\.(?:ogg|opus)(?:\?|$)/, middleware); oggStream.removeListener('data', headerCatcher); oggStream.resume(); bridge.removeListener('metadata', waitforMetadata); // Remove our metadata listener
child.stdout.removeListener('data', checkOutput); child.removeListener('exit', onChildExit);