Skip to content

Commit ce18598

Browse files
authored
chore: add log for debugging ws server (#35)
1 parent cd4b22a commit ce18598

File tree

1 file changed

+22
-25
lines changed

1 file changed

+22
-25
lines changed

server/index.tsx

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,6 @@ const clients: Map<string, WebSocket> = new Map<string, WebSocket>();
238238
const pairs: Map<string, string> = new Map<string, string>();
239239

240240
wss.on('connection', (client: WebSocket, request: IncomingMessage) => {
241-
// you have a new client
242-
console.log('New Connection');
243-
// add this client to the clients array
244-
245241
const query = qs.parse((request.url || '').replace(/\/\?/g, ''));
246242
const clientId = (query?.clientId as string) || crypto.randomUUID();
247243
clients.set(clientId, client);
@@ -288,6 +284,8 @@ wss.on('connection', (client: WebSocket, request: IncomingMessage) => {
288284
if (!msg) {
289285
const [cid] = clientId.split(':');
290286
const pairedClientId = pairs.get(cid);
287+
// @ts-ignore
288+
console.log('mpc', rawData.length);
291289
await send(pairedClientId + ':proof', rawData);
292290
return;
293291
}
@@ -316,9 +314,11 @@ wss.on('connection', (client: WebSocket, request: IncomingMessage) => {
316314
case 'proof_request_cancel':
317315
case 'proof_request_reject':
318316
case 'proof_request_end':
317+
console.log(msg.method);
319318
await send(to, rawData);
320319
break;
321320
case 'pair_request_success': {
321+
console.log(msg.method);
322322
if (await send(to, rawData)) {
323323
pairs.set(to, clientId);
324324
pairs.set(clientId, to);
@@ -340,28 +340,25 @@ wss.on('connection', (client: WebSocket, request: IncomingMessage) => {
340340
}
341341

342342
async function send(clientId: string, data: RawData) {
343-
return mutex.runExclusive(async () => {
344-
const res = await new Promise((resolve) => {
345-
const target = clients.get(clientId);
346-
347-
if (!target) {
348-
client.send(
349-
bufferify({
350-
error: {
351-
message: `client "${clientId}" does not exist`,
352-
},
353-
}),
354-
(err) => {
355-
resolve(false);
343+
return new Promise((resolve) => {
344+
const target = clients.get(clientId);
345+
346+
if (!target) {
347+
client.send(
348+
bufferify({
349+
error: {
350+
message: `client "${clientId}" does not exist`,
356351
},
357-
);
358-
} else {
359-
target.send(data, (err) => {
360-
resolve(!err);
361-
});
362-
}
363-
});
364-
return res;
352+
}),
353+
(err) => {
354+
resolve(false);
355+
},
356+
);
357+
} else {
358+
target.send(data, (err) => {
359+
resolve(!err);
360+
});
361+
}
365362
});
366363
}
367364
});

0 commit comments

Comments
 (0)