Skip to content
This repository has been archived by the owner on Oct 25, 2023. It is now read-only.

Commit

Permalink
Merge 099ef40 into 7749ff7
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach committed May 2, 2020
2 parents 7749ff7 + 099ef40 commit 324d036
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
19 changes: 14 additions & 5 deletions lib/mjpeg.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import _ from 'lodash';
import request from 'request';
import log from './logger';
import http from 'http';
import B from 'bluebird';
import { getJimpImage, MIME_PNG } from './image-util';
import mJpegServer from 'mjpeg-server';
import { Writable } from 'stream';
import { requirePackage } from './node';
import axios from 'axios';


// lazy load this, as it might not be available
Expand Down Expand Up @@ -127,16 +127,25 @@ class MJpegStream extends Writable {
`Waited ${serverTimeout}ms but the MJPEG server never sent any images`);

const onErr = (err) => {
log.error(`Error getting MJpeg screenshot chunk: ${err}`);
log.error(`Error getting MJpeg screenshot chunk: ${err.message}`);
this.errorHandler(err);
if (this.registerStartFailure) {
this.registerStartFailure(err);
}
};

this.request = request(this.url);
try {
this.request = await axios({
url: this.url,
method: 'GET',
responseType: 'stream',
timeout: serverTimeout,
});
} catch (e) {
return onErr(e);
}

this.request
this.request.data
.on('error', onErr) // ensure we do something with errors
.pipe(this.consumer) // allow chunking and transforming of jpeg data
.pipe(this); // send the actual jpegs to ourself
Expand All @@ -154,7 +163,7 @@ class MJpegStream extends Writable {
}

this.consumer.unpipe();
this.request.end();
this.request.data.end();
this.clear();
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"dependencies": {
"@babel/runtime": "^7.0.0",
"archiver": "^4.0.1",
"axios": "^0.19.2",
"base64-stream": "^1.0.0",
"bluebird": "^3.5.1",
"bplist-creator": "^0",
Expand All @@ -51,7 +52,6 @@
"plist": "^3.0.1",
"pluralize": "^8.0.0",
"pngjs": "^5.0.0",
"request": "^2.83.0",
"request-promise": "^4.2.2",
"rimraf": "^3.0.0",
"sanitize-filename": "^1.6.1",
Expand Down

0 comments on commit 324d036

Please sign in to comment.