discord-rpc/test-rpc-server/rpc-server.js
2017-06-27 12:23:09 -07:00

45 lines
No EOL
976 B
JavaScript

const net = require('net');
const RpcMessage = require('./rpc-message');
console.log('Start up');
let PipePrefix;
if (process.platform == 'win32') {
PipePrefix = "\\\\.\\pipe\\";
}
else {
PipePrefix = "/tmp";
}
const PipePath = PipePrefix + "DiscordRpcServer";
var server = net.createServer(function(stream) {
console.log('Server: on connection')
stream.on('data', function(data) {
const msgObj = RpcMessage.deserialize(data);
if (msgObj != null) {
console.log('Server: on data:', msgObj);
}
else {
console.log('Server: got some data');
}
});
stream.on('end', function() {
console.log('Server: on end')
server.close();
});
});
server.on('close', function(){
console.log('Server: on close');
})
try {
server.listen(PipePath, function(){
console.log('Server: on listening');
});
} catch(e) {
console.error('could not start server:', e);
}