hms-protocol
v1.2.3
Published
The protocol stream that hms uses to communicate between servers and clients
Downloads
27
Readme
hms-protocol
The protocol stream that hms uses to communicate between servers and clients
npm install hms-protocol
This is mostly only useful for hms
Usage
Simply pipe the stream to and from a source
var protocol = require('hms-protocol');
var net = require('net');
net.createServer(function(stream) {
var p = protocol();
stream.pipe(p).pipe(stream);
p.on('start', function(id, cb) {
console.log('we received a start for', id);
cb();
});
}).listen(10000, function() {
var p = protocol();
var stream = net.connect(10000);
stream.pipe(p).pipe(stream);
p.start('test', function(err) {
console.log('start was received?', err);
});
});
Send messages
The following messages are supported over the protocol
p.handshake(opts, cb)
send a protocol handhakep.ping(cb)
ping to see if remote is alivep.get(id, cb)
get information about a servicep.add(id, service, cb)
add a new service.p.update(id, service, cb)
update an existing servicep.remove(id, cb)
remove a servicep.list(cb)
list all servicesp.ps(cb)
get process information about all servicesp.start(id, cb)
start a servicep.stop(id, cb)
stop a servicep.restart(id, cb)
restart a servicep.sync(id, service, cb)
sync service statep.subscribe([id], cb)
subscribe to service events. omit theid
to subscribe to*
p.unsubscribe([id], cb)
unsubscribe from service events. omit theid
to unsubscribe*
p.stdout(id, origin, buffer)
send a stdout eventp.stderr(id, origin, buffer)
send a stderr eventp.spawn(id, origin, pid)
send a process spawn eventp.exit(id, origin, code)
send a process exit eventp.amSubscribing(id)
returns true if you are subscribing toid
p.peerSubscribing(id)
returns true if the peer is subscribing toid
The service message can contain the following
{
start: 'node .',
build: 'npm install',
docks: [
'dock-id-to-run-at'
],
env: {
FOO: 'bar'
}
}
Receive messages
Sending any of the above messages will trigger an event of the same for the receiver.
I.e. if you do p.start(id, cb)
it will result in p.on('start', id, cb)
being triggered
for the receiver
License
MIT