Skip to content

Commit

Permalink
full websocket I/O in app.log
Browse files Browse the repository at this point in the history
  • Loading branch information
miopa committed May 28, 2017
1 parent f9a1ff0 commit 27c0b6c
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var broadcastEvent = function (event, data) {
var payload = serializeEvent(event, data);
wss.broadcast(payload);
//myLib.consoleLog('debug', 'websocket::broadcastEvent', payload);
myLib.jsonLog({}, ['ws-out'], ['websocket'], payload, "broadcast");
myLib.jsonLog({ initiator: "system" }, ['ws-out'], ['websocket'], payload, "broadcast");
}
};
exports.broadcastEvent = broadcastEvent;
Expand All @@ -42,6 +42,10 @@ exports.startListening = function(options) {

ws.on('message', function incoming(message) {
//myLib.consoleLog('debug', 'websocket::receivedEvent', message);
myLib.jsonLog({
url: ws.upgradeReq.url,
"user-agent": ws.upgradeReq.headers["user-agent"],
}, ['ws-in'], ['websocket'], message, remoteIp);
message = JSON.parse(message);
if (!message.event) {
ws.send(serializeEvent("input_error", "message format error, should be { event: String, data: Object }"));
Expand All @@ -57,7 +61,12 @@ exports.startListening = function(options) {
data = serializeEvent(event, data);
//if (event !== 'pong') {
if (["pong", "inboxMessages"].indexOf(event) === -1) {
myLib.consoleLog('debug', 'websocket::emitEvent', target, data);
//myLib.consoleLog('debug', 'websocket::emitEvent', target, data);
myLib.jsonLog({
initiator: remoteIp,
url: ws.upgradeReq.url,
"user-agent": ws.upgradeReq.headers["user-agent"],
}, ['ws-out'], ['websocket'], data, target || "broadcast");
}
switch (target) {
case 'self':
Expand Down

0 comments on commit 27c0b6c

Please sign in to comment.