mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-09-16 17:40:46 -04:00
22 lines
529 B
JavaScript
22 lines
529 B
JavaScript
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;
|