httpwsd.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  1. /*******************************************************************************
  2. AToMPM - A Tool for Multi-Paradigm Modelling
  3. Copyright (c) 2011 Raphael Mannadiar (raphael.mannadiar@mail.mcgill.ca)
  4. This file is part of AToMPM.
  5. AToMPM is free software: you can redistribute it and/or modify it under the
  6. terms of the GNU Lesser General Public License as published by the Free Software
  7. Foundation, either version 3 of the License, or (at your option) any later
  8. version.
  9. AToMPM is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  11. PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License along
  13. with AToMPM. If not, see <http://www.gnu.org/licenses/>.
  14. *******************************************************************************/
  15. /*********************************** IMPORTS **********************************/
  16. var _util = require("util"),
  17. _fs = require('fs'),
  18. _http = require('http'),
  19. _path = require('path'),
  20. _url = require('url'),
  21. _utils = require('./utils'),
  22. _sio = require('socket.io'),
  23. _cp = require('child_process'),
  24. _fspp = require('./___fs++'),
  25. _duri = require('./___dataurize');
  26. /*********************************** GLOBALS **********************************/
  27. /* an array of WebWorkers
  28. ... each has its own mmmk instance */
  29. var workers = new Array();
  30. /* an array of response objects
  31. ... for workers to write on when they complete requests */
  32. var responses = new Array();
  33. /* a map of worker ids to socket.io socket session ids
  34. ... each socket is registered to exactly one worker
  35. ... several sockets may be registered to the same worker */
  36. var workerIds2socketIds = {};
  37. /************************************ UTILS ***********************************/
  38. /** Syntactic sugar to build and send HTTP responses **/
  39. function __respond(response, statusCode, reason, data, headers)
  40. {
  41. response.writeHead(
  42. statusCode,
  43. reason,
  44. (headers || {'Content-Type': 'text/plain'}));
  45. var encoding =
  46. (headers &&
  47. (headers['Content-Type'].match(/image/) ||
  48. headers['Content-Type'].match(/pdf/) ||
  49. headers['Content-Type'].match(/zip/) ) ?
  50. 'binary' :
  51. 'utf8'),
  52. content = reason || data;
  53. if( _utils.isObject(content) )
  54. response.end(_utils.jsons(content,null,'\t'), encoding);
  55. else
  56. response.end(content, encoding);
  57. }
  58. /** Syntactic sugar to build and send a socket.io message **/
  59. function __send(socket, statusCode, reason, data, headers)
  60. {
  61. //headers['Access-Control-Allow-Origin'] = 'http://raven10.kicks-ass.net:8080';
  62. socket.json.emit('message',
  63. {'statusCode':statusCode,
  64. 'reason':reason,
  65. 'headers':(headers || {'Content-Type': 'text/plain'}),
  66. 'data':data});
  67. }
  68. /************************************ LOGIC ***********************************/
  69. var httpserver = _http.createServer(
  70. function(req, resp)
  71. {
  72. var url = _url.parse(req.url,true);
  73. url.pathname = decodeURI(url.pathname);
  74. /* serve client */
  75. if( req.method == 'GET' && url.pathname == '/atompm' )
  76. _fs.readFile('./client/atompm.html', 'utf8',
  77. function(err, data)
  78. {
  79. if(err)
  80. __respond(resp,500,String(err));
  81. else
  82. __respond(resp,200,'',data,{'Content-Type': 'text/html'});
  83. });
  84. else if( req.method == 'GET' && url.pathname == '/favicon.png' )
  85. _fs.readFile('./favicon.png', 'binary',
  86. function(err, data)
  87. {
  88. if(err)
  89. __respond(resp,500,String(err));
  90. else
  91. __respond(resp,200,'',data,{'Content-Type': 'image/png'});
  92. });
  93. /* provide an interface to the unfortunately unavoidable dataurize
  94. module which returns data URIs for resources at arbitrary URLs */
  95. else if( req.method == 'GET' && url.pathname == '/datauri' )
  96. {
  97. var target = _url.parse(decodeURI(url['query']['target']));
  98. _duri.dataurize(
  99. target,
  100. function(err,datauri)
  101. {
  102. if(err)
  103. __respond(resp,500,_utils.jsons(err));
  104. else
  105. __respond(resp,200,'',datauri);
  106. });
  107. }
  108. /* serve metamodels, buttons models and their icons */
  109. else if( req.method == 'GET' &&
  110. (url.pathname.match(/\.metamodel$/) ||
  111. url.pathname.match(/\.buttons.model$/) ||
  112. url.pathname.match(/\.icon\.png$/i)) )
  113. {
  114. var isIcon = url.pathname.match(/\.icon\.png$/i);
  115. _fs.readFile('./users/'+url.pathname, (isIcon ? 'binary' : 'utf8'),
  116. function(err, data)
  117. {
  118. if(err)
  119. __respond(resp,500,String(err));
  120. else
  121. {
  122. var contentType =
  123. (isIcon ?
  124. {'Content-Type': 'image/png'} :
  125. {'Content-Type': 'application/json'});
  126. __respond(resp,200,'',data,contentType);
  127. }
  128. });
  129. }
  130. /* serve ordinary files (e.g., js includes, images, css)
  131. NOTE:: distinguish between atompm images (e.g., grid background,
  132. filebrowser icons) and CS/Images */
  133. else if( req.method == 'GET' &&
  134. (url.pathname.match(/\.html$/) ||
  135. url.pathname.match(/\.css$/) ||
  136. url.pathname.match(/\.js$/) ||
  137. url.pathname.match(/\.pdf$/) ||
  138. url.pathname.match(/\.png$/i) ||
  139. url.pathname.match(/\.jpg$/i) ||
  140. url.pathname.match(/\.jpeg$/i) ||
  141. url.pathname.match(/\.gif$/i) ||
  142. url.pathname.match(/\.svg$/i)) )
  143. {
  144. var isImage = url.pathname.match(/\.png$/i) ||
  145. url.pathname.match(/\.jpg$/i) ||
  146. url.pathname.match(/\.jpeg$/i) ||
  147. url.pathname.match(/\.gif$/i) ||
  148. url.pathname.match(/\.svg$/i),
  149. isText = ! isImage && ! url.pathname.match(/\.pdf$/);
  150. if( isImage && ! url.pathname.match(/^\/client\/media\//) )
  151. url.pathname = '/users/'+url.pathname;
  152. _fs.readFile('.'+url.pathname, (isText ? 'utf8' : 'binary'),
  153. function(err, data)
  154. {
  155. if(err)
  156. __respond(resp,500,String(err));
  157. else
  158. {
  159. var contentType =
  160. (url.pathname.match(/\.html$/) ?
  161. {'Content-Type': 'text/html'} :
  162. url.pathname.match(/\.css$/) ?
  163. {'Content-Type': 'text/css'} :
  164. url.pathname.match(/\.js$/) ?
  165. {'Content-Type': 'application/javascript'} :
  166. url.pathname.match(/\.pdf$/) ?
  167. {'Content-Type': 'application/pdf'} :
  168. url.pathname.match(/\.png$/i) ?
  169. {'Content-Type': 'image/png'} :
  170. url.pathname.match(/\.jpg$/i) ||
  171. url.pathname.match(/\.jpeg$/i) ?
  172. {'Content-Type': 'image/jpeg'} :
  173. url.pathname.match(/\.gif$/i) ?
  174. {'Content-Type': 'image/gif'} :
  175. url.pathname.match(/\.svg$/i) ?
  176. {'Content-Type': 'image/svg+xml'} :
  177. undefined);
  178. __respond(resp,200,'',data,contentType);
  179. }
  180. });
  181. }
  182. /* serve encrypted user password */
  183. else if( req.method == 'GET' && url.pathname == '/passwd' )
  184. _fs.readFile('./users/'+url['query']['username']+'/passwd', 'utf8',
  185. function(err, data)
  186. {
  187. if(err)
  188. __respond(resp,500,String(err));
  189. else
  190. __respond(resp,200,'',data,{'Content-Type': 'text/html'});
  191. });
  192. /* create new user
  193. 1. make sure user doesn't already exist
  194. 2. make a new copy of ./users/(default)
  195. 3. create password file */
  196. else if( req.method == 'POST' && url.pathname == '/user' )
  197. {
  198. var userdir = './users/'+url['query']['username'];
  199. _path.exists(userdir,
  200. function(exists)
  201. {
  202. if( exists )
  203. {
  204. __respond(resp,500,'username already exists');
  205. return;
  206. }
  207. _fspp.cp('./users/(default)/',userdir,
  208. function(err, stdout, stderr)
  209. {
  210. if( err )
  211. {
  212. __respond(resp,500,String(err));
  213. return;
  214. }
  215. _fs.writeFile(
  216. userdir+'/passwd',
  217. url['query']['password'],
  218. function(err)
  219. {
  220. if( err )
  221. __respond(resp,500,String(err));
  222. else
  223. __respond(resp,200);
  224. });
  225. });
  226. });
  227. }
  228. /* serve [a subset of] user preferences */
  229. else if( req.method == 'GET' && url.pathname.match(/prefs$/) )
  230. _fs.readFile('./users/'+url.pathname, 'utf8',
  231. function(err, data)
  232. {
  233. if(err)
  234. __respond(resp,500,String(err));
  235. else if( url['query']['subset'] == undefined )
  236. __respond(resp,200,'',data);
  237. else
  238. try
  239. {
  240. __respond(
  241. resp,
  242. 200,
  243. '',
  244. _utils.splitDict(
  245. _utils.jsonp(data),
  246. _utils.jsonp(url['query']['subset'])));
  247. }
  248. catch(err) {__respond(resp,500,String(err));}
  249. });
  250. /* update user preferences
  251. 1 retrieve all post data
  252. 2 read prefs file from disk
  253. 3 apply changes
  254. 4 write updated prefs to disk */
  255. else if( req.method == 'PUT' && url.pathname.match(/prefs$/) )
  256. {
  257. var reqData = '';
  258. req.addListener("data", function(chunk) {reqData += chunk;});
  259. req.addListener("end",
  260. function()
  261. {
  262. _fs.readFile('./users/'+url.pathname, 'utf8',
  263. function(err, prefs)
  264. {
  265. if(err)
  266. __respond(resp,500,String(err));
  267. else
  268. {
  269. try
  270. {
  271. prefs = _utils.jsonp(prefs);
  272. reqData = _utils.jsonp(reqData);
  273. }
  274. catch(err)
  275. {
  276. __respond(resp,500,String(err));
  277. return;
  278. }
  279. for( var pref in reqData )
  280. prefs[pref]['value'] = reqData[pref];
  281. _fs.writeFile(
  282. './users/'+url.pathname,
  283. _utils.jsons(prefs,null,'\t'),
  284. function(err, data)
  285. {
  286. if(err)
  287. __respond(resp,500,String(err));
  288. else
  289. __respond(resp,200);
  290. });
  291. }
  292. });
  293. });
  294. }
  295. /* delete specified file/folder */
  296. else if( req.method == 'DELETE' && url.pathname.match(/\.(file|folder)$/) )
  297. {
  298. var matches = url.pathname.match(/^\/(.*?)\/(.*\/)?(.*)\.(file|folder)$/),
  299. username = matches[1],
  300. folder = matches[2] || '',
  301. fname = matches[3],
  302. userdir = './users/'+username+'/',
  303. ondelete =
  304. function(err, stdout, stderr)
  305. {
  306. if( err )
  307. __respond(resp,500,String(err));
  308. else
  309. __respond(resp,200);
  310. },
  311. deletef =
  312. function(response)
  313. {
  314. _fspp.mv(userdir+folder+fname,userdir+'_Trash_/'+folder,ondelete);
  315. };
  316. _fs.exists(userdir+'_Trash_/'+folder,
  317. function(exists)
  318. {
  319. if( ! exists )
  320. _fspp.mkdirs(userdir+'_Trash_/'+folder,deletef);
  321. else {
  322. deletef();
  323. }
  324. });
  325. }
  326. /* create folder */
  327. else if( req.method == 'POST' && url.pathname.match(/\.folder$/) )
  328. {
  329. var matches = url.pathname.match(/^\/(.*?)\/(.*)\.folder$/),
  330. username = matches[1],
  331. folder = matches[2],
  332. userdir = './users/'+username+'/',
  333. oncreate =
  334. function(err, stdout, stderr)
  335. {
  336. if( err )
  337. __respond(resp,500,String(err));
  338. else
  339. __respond(resp,200);
  340. };
  341. _fs.exists(userdir+folder,
  342. function(exists)
  343. {
  344. if( ! exists )
  345. _fspp.mkdirs(userdir+folder,oncreate);
  346. else {
  347. oncreate("folder " + folder + " already exists");
  348. }
  349. });
  350. }
  351. /* rename file/folder (or move) */
  352. else if( req.method == 'PUT' && url.pathname.match(/\.(folder|file)$/) )
  353. {
  354. req.setEncoding('utf8');
  355. var data = '';
  356. req.addListener("data", function(chunk) {data += chunk;});
  357. req.addListener("end",
  358. function() {
  359. data = _utils.jsonp(data);
  360. if (data.match(/^\//)) {
  361. // move
  362. var matches = url.pathname.match(/^\/(.*?)\/(.*\/)?(.*)\.(file|folder)$/),
  363. username = matches[1],
  364. folder = matches[2] || '',
  365. fname = matches[3],
  366. userdir = './users/'+username,
  367. onmove =
  368. function(err, stdout, stderr)
  369. {
  370. if( err )
  371. __respond(resp,500,String(err));
  372. else
  373. __respond(resp,200);
  374. };
  375. _fspp.mv(userdir+"/"+folder+fname,userdir+data,onmove)
  376. } else {
  377. //rename
  378. var matches = url.pathname.match(/^\/(.*?)\/(.*\/)?(.*)\.(file|folder)$/),
  379. username = matches[1],
  380. folder = matches[2] || '',
  381. fname = matches[3],
  382. userdir = './users/'+username+'/',
  383. onrename =
  384. function(err, stdout, stderr)
  385. {
  386. if( err )
  387. __respond(resp,500,String(err));
  388. else
  389. __respond(resp,200);
  390. };
  391. _fs.rename(userdir+folder+fname,userdir+folder+data,onrename)
  392. }
  393. }
  394. )
  395. }
  396. /* extract user-uploaded archive to specified folder
  397. 1. read in all data
  398. 2. make sure destination exists and is a directory
  399. 3. write data to temp file (upload###.zip)
  400. 4. extract temp file and remove it
  401. NOTE:: it's not clear why (despite hours of googling) but the
  402. "req.setEncoding('utf8')" statement makes the difference
  403. between retrieving correct and corrupted (when non-text
  404. files in zip) data */
  405. else if( req.method == 'PUT' && url.pathname.match(/\.file$/) )
  406. {
  407. req.setEncoding('utf8');
  408. var reqData = '',
  409. tmpzip = 'upload'+Date.now()+'.zip',
  410. destdir = './users/'+url.pathname.match(/(.*)\.file$/)[1]+'/';
  411. req.addListener("data", function(chunk) {reqData += chunk;});
  412. req.addListener("end",
  413. function()
  414. {
  415. _fs.stat(destdir,
  416. function(err,stats)
  417. {
  418. if( err )
  419. __respond(resp,404,String(err));
  420. else if( ! stats.isDirectory() )
  421. __respond(resp,404,
  422. 'destination is not a directory :: '+destdir);
  423. else
  424. _fs.writeFile(
  425. destdir+tmpzip,eval('('+reqData+')'),
  426. 'binary',
  427. function(err)
  428. {
  429. _cp.exec('cd '+destdir+'; unzip -o '+tmpzip,
  430. function(err, stdout, stderr)
  431. {
  432. if( err )
  433. __respond(resp,500,String(err));
  434. else
  435. __respond(resp,200);
  436. _fs.unlink(destdir+tmpzip);
  437. });
  438. });
  439. });
  440. });
  441. }
  442. /* serve specified file/folder within a zip file */
  443. else if( req.method == 'GET' && url.pathname.match(/\.file$/) )
  444. {
  445. var matches = url.pathname.match(/^\/(.*?)\/(.*)\.file$/),
  446. username = matches[1],
  447. fname = './'+matches[2],
  448. userdir = './users/'+username+'/',
  449. tmpzip = 'download'+Date.now()+'.zip';
  450. _fs.exists(userdir+fname,
  451. function(exists)
  452. {
  453. if( ! exists )
  454. __respond(resp,404,
  455. 'requested file/folder does not exist :: '+fname);
  456. else
  457. _cp.exec('cd '+userdir+'; zip -r '+tmpzip+' "'+fname+'"',
  458. function(err, stdout, stderr)
  459. {
  460. if( err )
  461. __respond(resp,500,String(err));
  462. else
  463. _fs.readFile(userdir+tmpzip,'binary',
  464. function(err, data)
  465. {
  466. __respond(resp,200,'',data,
  467. {'Content-Type':'application/zip',
  468. 'Content-Disposition':
  469. 'attachment; filename="'+tmpzip+'"'});
  470. _fs.unlink(userdir+tmpzip);
  471. });
  472. });
  473. });
  474. }
  475. /* serve list of all files */
  476. else if( req.method == 'GET' &&
  477. url.pathname.match(/^\/.+\/filelist$/) )
  478. {
  479. var matches = url.pathname.match(/^\/(.+)\/filelist$/);
  480. _fspp.findfiles('./users/'+matches[1],
  481. function(err, stdout, stderr)
  482. {
  483. if( err )
  484. __respond(resp,404,String(err));
  485. else
  486. __respond(resp,200,'',stdout);
  487. });
  488. }
  489. /* spawn new worker */
  490. else if( (url.pathname == '/csworker' || url.pathname == '/asworker')
  491. && req.method == 'POST' )
  492. {
  493. /* setup and store new worker */
  494. var worker = _cp.fork(_path.join(__dirname, '__worker.js')),
  495. wid = workers.push(worker)-1;
  496. workerIds2socketIds[wid] = [];
  497. worker.on('message',
  498. function(msg)
  499. {
  500. /* push changes (if any) to registered sockets... even empty
  501. changelogs are pushed to facilitate sequence number-based
  502. ordering */
  503. if( msg['changelog'] != undefined )
  504. {
  505. var _msg = {'changelog':msg['changelog'],
  506. 'sequence#':msg['sequence#'],
  507. 'hitchhiker':msg['hitchhiker']};
  508. workerIds2socketIds[wid].forEach(
  509. function(sid)
  510. {
  511. __send(
  512. wsserver.sockets.sockets[sid],
  513. undefined,
  514. undefined,
  515. _msg);
  516. });
  517. }
  518. /* respond to a request */
  519. if( msg['respIndex'] != undefined )
  520. __respond(
  521. responses[msg['respIndex']],
  522. msg['statusCode'],
  523. msg['reason'],
  524. JSON.stringify(
  525. {'headers':
  526. (msg['headers'] ||
  527. {'Content-Type': 'text/plain'}),
  528. 'data':msg['data'],
  529. 'sequence#':msg['sequence#']}),
  530. {'Content-Type': 'application/json'});
  531. });
  532. worker.send(
  533. {'workerType':url.pathname,
  534. 'workerId':wid});
  535. /* respond worker id (used to identify associated worker) */
  536. __respond(
  537. resp,
  538. 201,
  539. '',
  540. ''+wid);
  541. return;
  542. }
  543. /* check for worker id and it's validity */
  544. else if( url['query'] == undefined ||
  545. url['query']['wid'] == undefined )
  546. __respond(resp, 400, 'missing worker id');
  547. else if( workers[url['query']['wid']] == undefined )
  548. __respond(resp, 400, 'invalid worker id :: '+url['query']['wid']);
  549. /* save resp object and forward request to worker (if request is PUT or
  550. POST, recover request data first)
  551. TBI:: only registered sockets should be allowed to speak to worker
  552. ... one way of doing this is forcing request urls to contain
  553. cid=socket.id## */
  554. else if( req.method == 'PUT' || req.method == 'POST' )
  555. {
  556. var reqData = '';
  557. req.addListener("data", function(chunk) {reqData += chunk;});
  558. req.addListener("end",
  559. function()
  560. {
  561. workers[url['query']['wid']].send(
  562. {'method':req.method,
  563. 'uri':url.pathname,
  564. 'reqData':(reqData == '' ?
  565. undefined :
  566. eval('('+reqData+')')),
  567. 'uriData':url['query'],
  568. 'respIndex':responses.push(resp)-1});
  569. });
  570. }
  571. else
  572. workers[url['query']['wid']].send(
  573. {'method':req.method,
  574. 'uri':url.pathname,
  575. 'uriData':url['query'],
  576. 'respIndex':responses.push(resp)-1});
  577. });
  578. httpserver.listen(8124);
  579. var wsserver = _sio.listen(httpserver);
  580. wsserver.configure(
  581. function()
  582. {
  583. wsserver.set('log level',2);
  584. });
  585. wsserver.sockets.on('connection',
  586. function(socket)
  587. {
  588. /* unregister this socket from the specified worker ... when a worker
  589. has no more registered sockets, terminate it */
  590. function unregister(wid)
  591. {
  592. var i = workerIds2socketIds[wid].indexOf(socket.id)
  593. if( i == -1 )
  594. __send(socket,403,'already unregistered from worker');
  595. else
  596. {
  597. workerIds2socketIds[wid].splice(i,1);
  598. if( workerIds2socketIds[wid].length == 0 )
  599. {
  600. workers[wid].kill();
  601. workers[wid] = undefined;
  602. delete workerIds2socketIds[wid];
  603. }
  604. __send(socket,200);
  605. }
  606. }
  607. /* onmessage : on reception of data from client */
  608. socket.on('message',
  609. function(msg/*{method:_,url:_}*/)
  610. {
  611. var url = _url.parse(msg.url,true);
  612. /* check for worker id and it's validity */
  613. if( url['query'] == undefined ||
  614. url['query']['wid'] == undefined )
  615. return __send(socket,400,'missing worker id');
  616. var wid = url['query']['wid'];
  617. if( workers[wid] == undefined )
  618. __send(socket,400,'unknown worker id :: '+wid);
  619. /* register socket for requested worker */
  620. else if( msg.method == 'POST' &&
  621. url.pathname.match(/changeListener$/) )
  622. {
  623. if( workerIds2socketIds[wid].indexOf(socket.id) > -1 )
  624. __send(socket,403,'already registered to worker');
  625. else
  626. {
  627. workerIds2socketIds[wid].push(socket.id);
  628. __send(socket,201);
  629. }
  630. }
  631. /* unregister socket for requested worker */
  632. else if( msg.method == 'DELETE' &&
  633. url.pathname.match(/changeListener$/) )
  634. unregister(wid);
  635. /* unsupported request */
  636. else
  637. __send(socket,501);
  638. });
  639. /* ondisconnect : on disconnection of socket */
  640. socket.on('disconnect',
  641. function()
  642. {
  643. for( var wid in workerIds2socketIds )
  644. for( var i in workerIds2socketIds[wid] )
  645. if( workerIds2socketIds[wid][i] == socket.id )
  646. {
  647. unregister(wid);
  648. return;
  649. }
  650. });
  651. });