mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-09-16 09:31:20 -04:00
modularize code, add dummy version of roverd
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
const { WebSocketServer } = require('ws');
|
||||
const { httpServer } = require('./http');
|
||||
const logger = require('./logger');
|
||||
|
||||
const roverWSS = new WebSocketServer({ noServer: true });
|
||||
|
||||
httpServer.on('upgrade', (req, socket, head) => {
|
||||
if (req.url.startsWith('/rover')) {
|
||||
roverWSS.handleUpgrade(req, socket, head, (ws) => {
|
||||
roverWSS.emit('connection', ws, req);
|
||||
});
|
||||
} else {
|
||||
socket.destroy();
|
||||
}
|
||||
});
|
||||
|
||||
roverWSS.on('connection', () => {
|
||||
logger.info('Rover websocket connected');
|
||||
});
|
||||
|
||||
module.exports = roverWSS;
|
||||
Reference in New Issue
Block a user