|
3 | 3 | const http = require('http');
|
4 | 4 | const path = require('path');
|
5 | 5 | const fs = require('fs');
|
6 |
| -const Websocket = require('websocket').server; |
| 6 | +const WebSocket = require('ws'); |
7 | 7 |
|
8 | 8 | global.memory = new Map();
|
9 | 9 | const api = new Map();
|
@@ -60,19 +60,13 @@ const server = http.createServer(async (req, res) => {
|
60 | 60 | }
|
61 | 61 | }).listen(8000);
|
62 | 62 |
|
63 |
| -const ws = new Websocket({ |
64 |
| - httpServer: server, |
65 |
| - autoAcceptConnections: false |
66 |
| -}); |
| 63 | +const ws = new WebSocket.Server({ server }); |
67 | 64 |
|
68 |
| -ws.on('request', req => { |
69 |
| - const connection = req.accept('', req.origin); |
| 65 | +ws.on('connection', connection => { |
70 | 66 | console.log('Connected ' + connection.remoteAddress);
|
71 | 67 | connection.on('message', async message => {
|
72 |
| - const dataName = message.type + 'Data'; |
73 |
| - const data = message[dataName]; |
74 |
| - console.log('Received: ' + data); |
75 |
| - const obj = JSON.parse(data); |
| 68 | + console.log('Received: ' + message); |
| 69 | + const obj = JSON.parse(message); |
76 | 70 | const { method, args } = obj;
|
77 | 71 | const fn = api.get(method);
|
78 | 72 | try {
|
|
0 commit comments