This repository was archived by the owner on Feb 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a1a4d35
commit d2427ba
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
|
||
// Load WebSocket networking library | ||
WebSocket = require('ws'); | ||
|
||
// Start WebSocket server | ||
wss = new WebSocket.Server({ | ||
port: 8080, | ||
host : '0.0.0.0' | ||
}); | ||
|
||
cameraSocket = null; | ||
|
||
// Configure WebSocket server | ||
wss.on('connection', function connection(socket) { | ||
|
||
console.log("A client connected!"); | ||
|
||
// Handle client data | ||
socket.on('message', function incoming(message) { | ||
console.log("Received message: %s", message); | ||
if (message == "camera") { | ||
cameraSocket = socket; | ||
} | ||
else { | ||
if (cameraSocket != null) { | ||
cameraSocket.send("photo\n"); | ||
} | ||
} | ||
}); | ||
|
||
// Handle client disconnect | ||
wss.on('close', function close() { | ||
console.log("A client disconnected"); | ||
}); | ||
|
||
// Handle client error | ||
wss.on('error', function() { | ||
console.log("A connection error occurred"); | ||
}); | ||
|
||
}); |