pipe names

This commit is contained in:
Chris Marsh 2017-06-27 13:19:36 -07:00
parent 8e13ed2a63
commit d0ad279d33
3 changed files with 19 additions and 8 deletions

View File

@ -18,7 +18,7 @@ module.exports = class RpcMessage {
try { try {
return JSON.parse(msg); return JSON.parse(msg);
} catch(e) { } catch(e) {
return null; return {};
} }
} }
}; };

View File

@ -4,17 +4,20 @@ const RpcMessage = require('./rpc-message');
console.log('Start up'); console.log('Start up');
let PipePrefix; let PipePrefix;
let PipePostfix;
if (process.platform == 'win32') { if (process.platform == 'win32') {
PipePrefix = "\\\\.\\pipe\\"; PipePrefix = '\\\\.\\pipe\\';
PipePostfix = '';
} }
else { else {
PipePrefix = "/tmp"; PipePrefix = "/tmp";
PipePostfix = '.pipe';
} }
const PipePath = PipePrefix + "DiscordRpcServer"; const PipePath = PipePrefix + "DiscordRpcServer" + PipePostfix;
var server = net.createServer(function(stream) { var server = net.createServer(function(stream) {
console.log('Server: on connection') console.log('Server: on connection');
stream.on('data', function(data) { stream.on('data', function(data) {
const msgObj = RpcMessage.deserialize(data); const msgObj = RpcMessage.deserialize(data);

View File

@ -1,10 +1,18 @@
const net = require('net'); const net = require('net');
const RpcMessage = require('./rpc-message'); const RpcMessage = require('./rpc-message');
var PIPE_NAME = "DiscordRpcServer"; let PipePrefix;
var PIPE_PATH = "\\\\.\\pipe\\" + PIPE_NAME; let PipePostfix;
if (process.platform == 'win32') {
PipePrefix = '\\\\.\\pipe\\';
PipePostfix = '';
}
else {
PipePrefix = "/tmp";
PipePostfix = '.pipe';
}
const msg = new RpcMessage(); const PipePath = PipePrefix + "DiscordRpcServer" + PipePostfix;
function sendMesg(testUpdatesToSend, stream) { function sendMesg(testUpdatesToSend, stream) {
const msgObj = { const msgObj = {
@ -24,7 +32,7 @@ function sendMessageLoop(testUpdatesToSend, interval, stream) {
} }
} }
const client = net.connect(PIPE_PATH, function(stream) { const client = net.connect(PipePath, function(stream) {
console.log('Client: on connection'); console.log('Client: on connection');
sendMessageLoop(5, 3000, client); sendMessageLoop(5, 3000, client);