Skip to content

Commit 89e2de2

Browse files
committed
feat: wss + DEBUG all over
1 parent 6bda2b4 commit 89e2de2

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

dashsight-server.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ DashSightServer.create = function ({ rpc, wss, authenticate }) {
7070

7171
dss.sockets = {};
7272
dss.sockets.onconnection = async function (ws, request) {
73+
console.error("[DEBUG] dss.sockets.onconnection");
7374
ws.on("error", console.error);
7475

7576
// TODO session should establish which hostname and port
@@ -96,9 +97,9 @@ DashSightServer.create = function ({ rpc, wss, authenticate }) {
9697
return;
9798
}
9899

99-
console.log(`DEBUG ws query:`);
100+
console.log(`[DEBUG] ws query:`);
100101
console.log(query);
101-
let stream = WebSocket.createWebSocketStream(ws);
102+
let stream = WebSocket.createWebSocketStream(ws, { encoding: null });
102103
let conn = Net.createConnection({
103104
host: query.hostname,
104105
port: query.port,
@@ -108,14 +109,29 @@ DashSightServer.create = function ({ rpc, wss, authenticate }) {
108109
});
109110
stream.pipe(conn);
110111
conn.pipe(stream);
112+
ws.on("open", function (chunk) {
113+
console.log("[DEBUG] ws.on open");
114+
});
115+
ws.on("message", function (chunk) {
116+
let hex = chunk.toString("hex");
117+
console.log("[DEBUG] ws.on data hex", hex);
118+
});
119+
conn.on("data", function (chunk) {
120+
let hex = chunk.toString("hex");
121+
console.log("[DEBUG] conn.on data hex", hex);
122+
// ws.send(chunk);
123+
});
111124

112125
stream.once("error", disconnect);
113126
stream.once("end", disconnect);
114127
stream.once("close", disconnect);
115128
function disconnect() {
129+
console.log("[DEBUG] ws stream pipe disconnected");
116130
conn.end();
117131
conn.destroy();
118132
}
133+
134+
console.log("[DEBUG] piped each end and added handlers");
119135
};
120136

121137
dss.router = new AsyncRouter.Router();

server.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ server.on("upgrade", function upgrade(request, socket, head) {
8888
}
8989

9090
wss.handleUpgrade(request, socket, head, function (ws) {
91+
console.error('[DEBUG] wss.handleUpgrade: emit connection');
9192
wss.emit("connection", ws, request);
9293
});
9394
});

0 commit comments

Comments
 (0)