
Checkpoint
./server.js:13690106/661
Showing
3 changed files
with
12 additions
and
5 deletions
radata/!
0 → 100644
1 | {"jack\u001bname":{"":{":":"Jack",">":1586991774902}}} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
radata/%1C
0 → 100644
1 | {"!":{"":1}} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
... | @@ -6,9 +6,9 @@ var server = http.createServer().listen(3000); | ... | @@ -6,9 +6,9 @@ var server = http.createServer().listen(3000); |
6 | 6 | ||
7 | // LRU with last used sockets | 7 | // LRU with last used sockets |
8 | const QuickLRU = require('quick-lru'); | 8 | const QuickLRU = require('quick-lru'); |
9 | const lru = new QuickLRU({maxSize: 100}); | 9 | const lru = new QuickLRU({maxSize: 1}); |
10 | 10 | ||
11 | var wss_event = new WebSocket.Server({ noServer: true}); | 11 | //var wss_event = new WebSocket.Server({ noServer: true}); |
12 | 12 | ||
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'; |
... | @@ -22,15 +22,20 @@ server.on('upgrade', async function (request, socket, head) { | ... | @@ -22,15 +22,20 @@ server.on('upgrade', async function (request, socket, head) { |
22 | } else { | 22 | } else { |
23 | // Create Node | 23 | // Create Node |
24 | console.log('Create id',pathname); | 24 | console.log('Create id',pathname); |
25 | gun = await Gun({peers:[], ws: { path: pathname}, web: new WebSocket.Server({ noServer: true})}); | 25 | var wserver = new WebSocket.Server({ noServer: true}); |
26 | gun = new Gun({peers:[], ws: { path: pathname}, web: server }); | ||
26 | lru.set(pathname,gun); | 27 | lru.set(pathname,gun); |
27 | } | 28 | } |
28 | } | 29 | } |
29 | if (gun){ | 30 | if (gun){ |
30 | // Handle Request | 31 | // Handle Request |
31 | gun.handleUpgrade(request, socket, head, function (ws) { | 32 | console.log('handle connection...'); |
32 | gun.emit('connection', ws); | 33 | //ws.emit('connection', socket); |
34 | wserver.handleUpgrade(request, socket, head, function (ws) { | ||
35 | console.log('connecting.. ') | ||
36 | ws.emit('connection', socket); | ||
33 | }); | 37 | }); |
38 | |||
34 | } else { | 39 | } else { |
35 | socket.destroy(); | 40 | socket.destroy(); |
36 | } | 41 | } | ... | ... |
-
Please register or sign in to post a comment