
Checkpoint
./server.js:13690106/175
Showing
2 changed files
with
8 additions
and
8 deletions
... | @@ -13,7 +13,7 @@ const lru = new QuickLRU({maxSize: 1}); | ... | @@ -13,7 +13,7 @@ const lru = new QuickLRU({maxSize: 1}); |
13 | server.on('upgrade', async function (request, socket, head) { | 13 | server.on('upgrade', async function (request, socket, head) { |
14 | var pathname = url.parse(request.url).pathname || '/gun'; | 14 | var pathname = url.parse(request.url).pathname || '/gun'; |
15 | console.log('Got WS request',pathname); | 15 | console.log('Got WS request',pathname); |
16 | var gun = false; | 16 | var gun = { gun: false, server: false}; |
17 | if (pathname){ | 17 | if (pathname){ |
18 | if (lru.has(pathname)){ | 18 | if (lru.has(pathname)){ |
19 | // Existing Node | 19 | // Existing Node |
... | @@ -23,17 +23,17 @@ server.on('upgrade', async function (request, socket, head) { | ... | @@ -23,17 +23,17 @@ server.on('upgrade', async function (request, socket, head) { |
23 | // Create Node | 23 | // Create Node |
24 | console.log('Create id',pathname); | 24 | console.log('Create id',pathname); |
25 | var wserver = new WebSocket.Server({ noServer: true}); | 25 | var wserver = new WebSocket.Server({ noServer: true}); |
26 | gun = new Gun({peers:[], ws: { path: pathname}, web: server }); | 26 | gun = new Gun({peers:[], ws: { path: pathname}, web: wserver }); |
27 | lru.set(pathname,gun); | 27 | lru.set(pathname,{gun: gun, server: wserver}); |
28 | } | 28 | } |
29 | } | 29 | } |
30 | if (gun){ | 30 | if (gun.server){ |
31 | // Handle Request | 31 | // Handle Request |
32 | console.log('handle connection...'); | 32 | console.log('handle connection...', gun); |
33 | //ws.emit('connection', socket); | 33 | //ws.emit('connection', socket); |
34 | wserver.handleUpgrade(request, socket, head, function (ws) { | 34 | gun.server.handleUpgrade(request, socket, head, function (ws) { |
35 | console.log('connecting.. ') | 35 | console.log('connecting.. ') |
36 | ws.emit('connection', socket); | 36 | ws.emit('connection', ws); |
37 | }); | 37 | }); |
38 | 38 | ||
39 | } else { | 39 | } else { | ... | ... |
-
Please register or sign in to post a comment