@@ -20,8 +20,6 @@ import { createServer } from 'http';
20
20
import { WebSocketServer , type RawData , type WebSocket } from 'ws' ;
21
21
import crypto from 'crypto' ;
22
22
import qs from 'qs' ;
23
- import { Mutex } from 'async-mutex' ;
24
- const mutex = new Mutex ( ) ;
25
23
26
24
const app = express ( ) ;
27
25
const port = process . env . PORT || 3000 ;
@@ -263,15 +261,15 @@ wss.on('connection', async (client: WebSocket, request: IncomingMessage) => {
263
261
if ( ! clientId . includes ( ':proof' ) ) {
264
262
const pair = pairs . get ( clientId ) ;
265
263
if ( pair ) {
266
- // pairs.delete(pair);
267
- // pairs.delete(clientId);
268
- // await send(
269
- // pair,
270
- // bufferify({
271
- // method: 'pair_disconnect',
272
- // params: { pairId: clientId },
273
- // }),
274
- // );
264
+ pairs . delete ( pair ) ;
265
+ pairs . delete ( clientId ) ;
266
+ await send (
267
+ pair ,
268
+ bufferify ( {
269
+ method : 'pair_disconnect' ,
270
+ params : { pairId : clientId } ,
271
+ } ) ,
272
+ ) ;
275
273
}
276
274
}
277
275
@@ -324,6 +322,8 @@ wss.on('connection', async (client: WebSocket, request: IncomingMessage) => {
324
322
}
325
323
break ;
326
324
}
325
+ case 'ping' :
326
+ break ;
327
327
default :
328
328
console . log ( 'unknown msg' , msg ) ;
329
329
break ;
@@ -339,27 +339,25 @@ wss.on('connection', async (client: WebSocket, request: IncomingMessage) => {
339
339
}
340
340
341
341
async function send ( clientId : string , data : RawData ) {
342
- return mutex . runExclusive ( async ( ) => {
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` ,
351
- } ,
352
- } ) ,
353
- ( err ) => {
354
- resolve ( false ) ;
342
+ return new Promise ( ( resolve ) => {
343
+ const target = clients . get ( clientId ) ;
344
+
345
+ if ( ! target ) {
346
+ client . send (
347
+ bufferify ( {
348
+ error : {
349
+ message : `client "${ clientId } " does not exist` ,
355
350
} ,
356
- ) ;
357
- } else {
358
- target . send ( data , ( err ) => {
359
- resolve ( ! err ) ;
360
- } ) ;
361
- }
362
- } ) ;
351
+ } ) ,
352
+ ( err ) => {
353
+ resolve ( false ) ;
354
+ } ,
355
+ ) ;
356
+ } else {
357
+ target . send ( data , ( err ) => {
358
+ resolve ( ! err ) ;
359
+ } ) ;
360
+ }
363
361
} ) ;
364
362
}
365
363
} ) ;
0 commit comments