Closed deathcap closed 8 years ago
This sort of works, but with ./cli.js ls
, losing some messages:
host $ ./cli.js ls
Host received { cmd: 'ack',
msg: { fromUnix: true, unixID: 5624, args: [ 'ls' ] } }
Started pid=22, argv=["/bin/node","ls"], env={"TERM":"xterm-256color","SHELL":"/bin/sh","USER":"user","LOGNAME":"user","PATH":"~/.bin/:/usr/bin/:/bin:/usr/sbin:/sbin:/usr/local/bin","PWD":"/","HOME":"/home"}
a
b2.js
node_modules
package.json
Unknown message: { counter: 0 }
Unknown message: { counter: 1 }
Unknown message: { counter: 2 }
Unknown message: { counter: 4 }
Unknown message: { counter: 5 }
Unknown message: { counter: 6 }
Unknown message: { counter: 7 }
Unknown message: { counter: 8 }
Unknown message: { counter: 9 }
^C
not sure about the client.on('readable', ...)
usage. Would like to be able to simply pipe to writable:
const Writable = require('stream').Writable;
rs
.pipe(new nativeMessage.Output())
.pipe(client)
const ws = new Writable({objectMode: true});
ws._write = (msg, encoding, cb) => {
//console.log('msg',msg);
if (msg.cmd === 'stdout') {
process.stdout.write(msg.output);
} else if (msg.cmd === 'ack') {
console.log('Host received',msg);
} else {
console.log('Unknown message:',msg);
}
};
client
.pipe(new nativeMessage.Input())
.pipe(ws);
but if I do this, I only get one message. Listening for the readable
event on the client allows it to read more than one message, but then I would need to buffer the length like https://github.com/jdiamond/chrome-native-messaging/blob/master/index.js#L38
When invoked from the cli interface, pipe the process.stdout stream from the browser process, to the kernel, to the native host, back to the Unix command-line tool:
relevant: https://github.com/deathcap/nodeachrome/issues/21 child_process API: stdio