mirror of
https://github.com/0015/ThatProject.git
synced 2026-01-12 17:27:43 +03:00
ESP32 CAM with Arduino IDE | Tutorial - [Part.2] World Wide Access to ESP32CAM (feat. GCP)
This commit is contained in:
28
ESP32_CAM_GoogleCloudServer/NodeServer/server.js
Normal file
28
ESP32_CAM_GoogleCloudServer/NodeServer/server.js
Normal file
@@ -0,0 +1,28 @@
|
||||
const path = require('path');
|
||||
const express = require('express');
|
||||
const WebSocket = require('ws');
|
||||
const app = express();
|
||||
|
||||
const WS_PORT = 65080;
|
||||
const HTTP_PORT = 80;
|
||||
|
||||
const wsServer = new WebSocket.Server({port: WS_PORT}, ()=> console.log(`WS Server is listening at ${WS_PORT}`));
|
||||
|
||||
let connectedClients = [];
|
||||
wsServer.on('connection', (ws, req)=>{
|
||||
console.log('Connected');
|
||||
connectedClients.push(ws);
|
||||
|
||||
ws.on('message', data => {
|
||||
connectedClients.forEach((ws,i)=>{
|
||||
if(ws.readyState === ws.OPEN){
|
||||
ws.send(data);
|
||||
}else{
|
||||
connectedClients.splice(i ,1);
|
||||
}
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
app.get('/client',(req,res)=>res.sendFile(path.resolve(__dirname, './client.html')));
|
||||
app.listen(HTTP_PORT, ()=> console.log(`HTTP server listening at ${HTTP_PORT}`));
|
||||
Reference in New Issue
Block a user