Skip to content

Instantly share code, notes, and snippets.

@mmaelzer
Created June 24, 2015 04:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mmaelzer/8e6eda9bd9750921bb01 to your computer and use it in GitHub Desktop.
Save mmaelzer/8e6eda9bd9750921bb01 to your computer and use it in GitHub Desktop.
mjpeg-camera + socket.io
/** =========================== SERVER =================================== */
var io = require('socket.io')(server);
var MjpegCamera = require('mjpeg-camera');
server.listen(3000);
// Create an MjpegCamera instance
var camera = new MjpegCamera({
name: 'backdoor',
url: 'http://192.168.7.1/video'
});
// As frames come in, emit them in socket.io
camera.on('data', function(frame) {
io.emit('frame', frame.data.toString('base64'))
});
// Start streaming
camera.start();
/** =========================== BROWSER =================================== */
var socket = io();
socket.on('frame', function(frame){
$('#video-frame').attr('src', 'data:image/jpg;base64,' + frame);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment