Skip to content

Commit

Permalink
Update for tessel-mjpeg-consumer
Browse files Browse the repository at this point in the history
  • Loading branch information
rwaldron committed Oct 21, 2016
1 parent b91b758 commit a142183
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
9 changes: 3 additions & 6 deletions lib/camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

// Dependencies: Built-in
const cp = require('child_process');
const fs = require('fs');
const Stream = require('stream');
const Readable = Stream.Readable;

// Dependencies: Third Party
const got = require('got');
const ip = require('ip');
const MjpegConsumer = require('mjpeg-consumer');
const MjpegConsumer = require('tessel-mjpeg-consumer');

// Dependencies: Internal
const CaptureStream = require('./capture-stream');
Expand All @@ -33,7 +31,6 @@ class Camera extends Stream {
constructor(options) {
super();

let child;
let device = '/dev/video0';
let dimensions = '800x600';
let fps = 30;
Expand Down Expand Up @@ -163,7 +160,7 @@ class Camera extends Stream {

if (!state.stream) {
state.stream = got.stream(state.remote.url);
state.stream.on('error', _ => {
state.stream.on('error', () => {
state.stream = null;
this.stream();
});
Expand All @@ -172,7 +169,7 @@ class Camera extends Stream {
let incoming = state.stream.pipe(new MjpegConsumer());

incoming.on('data', frame => state.frame = frame);
incoming.on('error', _ => this.stream());
incoming.on('error', () => this.stream());
incoming.pipe(this);

return this;
Expand Down
2 changes: 1 addition & 1 deletion test/common/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ global.Writable = stream.Writable;

// Dependencies: Third Party
global.sinon = require('sinon');
global.MjpegConsumer = require('mjpeg-consumer');
global.MjpegConsumer = require('tessel-mjpeg-consumer');


// Dependencies: Internal
Expand Down
28 changes: 15 additions & 13 deletions test/unit/camera.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
exports['av.Camera'] = {
setUp: function(done) {
setUp(done) {
this.sandbox = sinon.sandbox.create();
this.emitter = new Emitter();
this.spawn = this.sandbox.stub(cp, 'spawn', () => {
Expand All @@ -15,31 +15,33 @@ exports['av.Camera'] = {
done();
},

tearDown: function(done) {
tearDown(done) {
this.sandbox.restore();
done();
},

basic: function(test) {
basic(test) {
test.expect(1);
test.equal(typeof av.Camera, 'function');
test.done();
},

emitter: function(test) {
emitter(test) {
test.expect(1);
test.equal((new av.Camera()) instanceof Emitter, true);
test.done();
},

captureToEmitter: function(test) {
test.expect(3);

var buffer = new Buffer([0]);
var cam = new av.Camera();
capture(test) {
test.expect(1);
test.equal(typeof av.Camera.prototype.capture, 'function');
test.done();
},

test.equal(typeof cam.capture, 'function');
captureReadable(test) {
test.expect(2);

var cam = new av.Camera();
var capture = cam.capture();

test.equal(capture instanceof CaptureStream, true);
Expand All @@ -48,7 +50,7 @@ exports['av.Camera'] = {
test.done();
},

captureToPipe: function(test) {
captureToPipe(test) {
test.expect(1);

var buffer = new Buffer([0]);
Expand All @@ -69,7 +71,7 @@ exports['av.Camera'] = {
this.emitter.emit('close');
},

spawned: function(test) {
spawned(test) {
test.expect(3);

var cam = new av.Camera();
Expand All @@ -88,7 +90,7 @@ exports['av.Camera'] = {
test.done();
},

stream: function(test) {
stream(test) {
test.expect(1);

var cam = new av.Camera();
Expand Down

0 comments on commit a142183

Please sign in to comment.