-
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
Showing
4 changed files
with
173 additions
and
1 deletion.
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
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,53 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
|
||
<head> | ||
|
||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0"> | ||
|
||
<title>Websocket node-webcam example</title> | ||
|
||
<style> | ||
html, body { | ||
width: 100%; | ||
height: 100%; | ||
padding: 0; | ||
margin: 0; | ||
} | ||
#container { | ||
width: 100%; | ||
height: 100%; | ||
position: absolute; | ||
} | ||
#img { | ||
width: 100%; | ||
display: block; | ||
} | ||
</style> | ||
|
||
</head> | ||
|
||
<body> | ||
|
||
<div id="container"> | ||
|
||
<img id="img"></img> | ||
|
||
</div> | ||
|
||
<script> | ||
(function() { | ||
"use strict"; | ||
var container = document.getElementById( "container" ); | ||
var img = document.getElementById( "img" ); | ||
var ws = new WebSocket( "ws://localhost:9091" ); | ||
ws.onmessage = function( data ) { | ||
img.src = data.data; | ||
}; | ||
})(); | ||
</script> | ||
|
||
</body> | ||
|
||
</html> |
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,94 @@ | ||
/** | ||
* Websocket server app | ||
* | ||
* Will use base64 return to the websocket clients and | ||
* in memory capturing without saving | ||
* | ||
*/ | ||
"use strict"; | ||
|
||
var port = 9090; | ||
|
||
var HTTP = require( "http" ); | ||
|
||
var FS = require( "fs" ); | ||
|
||
var HTML_CONTENT = FS.readFileSync( __dirname + "/index.html" ); | ||
|
||
var WS = require( "ws" ); | ||
|
||
var WSS = new WS.Server({ port: 9091 }); | ||
|
||
// Broadcast to all. | ||
|
||
WSS.broadcast = function broadcast( data ) { | ||
|
||
WSS.clients.forEach( function each( client ) { | ||
|
||
client.send( data ); | ||
|
||
}); | ||
|
||
}; | ||
|
||
var NodeWebcam = require( "./../../" ); | ||
|
||
var Webcam = NodeWebcam.create({ | ||
callbackReturn: "base64", | ||
saveShots: false | ||
}); | ||
|
||
|
||
// Main | ||
|
||
init(); | ||
|
||
function init() { | ||
|
||
setupHTTP(); | ||
|
||
setupWebcam(); | ||
|
||
console.log( "Visit localhost:9090" ); | ||
|
||
} | ||
|
||
function setupHTTP() { | ||
|
||
var server = HTTP.createServer(); | ||
|
||
server.on( "request", function( request, response ) { | ||
|
||
response.write( HTML_CONTENT ); | ||
|
||
response.end(); | ||
|
||
}); | ||
|
||
server.listen( port ); | ||
|
||
} | ||
|
||
function setupWebcam() { | ||
|
||
function capture() { | ||
|
||
Webcam.capture( "picture", function( err, data ) { | ||
|
||
if( err ) { | ||
|
||
throw err; | ||
|
||
} | ||
|
||
WSS.broadcast( data ); | ||
|
||
setTimeout( capture, 25 ); | ||
|
||
}); | ||
|
||
} | ||
|
||
capture(); | ||
|
||
} |
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