Skip to content
Browse files

Added a few comments

  • Loading branch information...
1 parent 5e55cd2 commit fe4ef91ac07a22c6edc3ec7cbb382cff3f7fc041 @chemicaloliver committed
Showing with 31 additions and 15 deletions.
  1. +8 −2 app.js
  2. +21 −13 js/camera.js
  3. +2 −0 js/client.js
View
10 app.js
@@ -4,10 +4,12 @@ var ws = require('websocket-server');
var sys = require("sys");
var path = require('path');
+//create websocket server
var ws_server = ws.createServer();
-//standard html home page
-
+/**
+ * Setup simple http server to serve static page elements on port 8000
+ */
http.createServer(function (request, response) {
console.log('request starting...');
@@ -49,9 +51,12 @@ http.createServer(function (request, response) {
}).listen(8000);
+
+
// Handle WebSocket Requests
ws_server.addListener("connection", function(conn){
+//add listener to rebroadcast incomming messages
conn.addListener("message", function(msg){
console.log('message');
conn.broadcast(msg);
@@ -67,4 +72,5 @@ ws_server.addListener("disconnected", function(conn){
ws_server.broadcast("<"+conn.id+"> disconnected");
});
+//start websocket server on port 8001
ws_server.listen(8001);
View
34 js/camera.js
@@ -8,12 +8,12 @@
*/
var videoId = 'video',
- scaleFactor = 0.5,
- snapshot = null,
- upload_image,
- video = document.getElementsByTagName('video')[0],
- heading = document.getElementsByTagName('h1')[0];
- var ws = new WebSocket("ws://192.168.1.2:8001/");
+scaleFactor = 0.5,
+snapshot = null,
+upload_image,
+video = document.getElementsByTagName('video')[0],
+heading = document.getElementsByTagName('h1')[0];
+var ws = new WebSocket("ws://192.168.1.2:8001/");
@@ -151,20 +151,28 @@ ws.onmessage = function(event)
//bind button to send picture
addEventListener('click', streamFrame, false);
+/**
+ * Start grabbing frames and sending them via the websocket
+ *
+ * Called when the button is pressed, grabs a frame of video,
+ * renders it to the canvas, grabs the base64 encoded data and
+ * sends it through the websocket. The framerate can be adjusted
+ * by changing the interval time but I found this to be the fastest
+ * my phone could cope with
+ *
+ */
+
function streamFrame()
{
var context = canvas.getContext("2d");
setInterval(function(){
context.drawImage(video, 0, 0, 240, 320);
- var image = canvas.toDataURL("image/png");
+ var image = canvas.toDataURL("image/png");
- console.log('send');
- ws.send(image);
+ console.log('send');
+ ws.send(image);
-},400);
-
-
-
+ },400);
}
View
2 js/client.js
@@ -2,6 +2,8 @@
*
* Streaming Video Client
*
+ * Recieves image data via a websocket connection and renders it to #img
+ *
*******************************************************************************
*/

0 comments on commit fe4ef91

Please sign in to comment.
Something went wrong with that request. Please try again.