mirror of
https://github.com/serratus/quaggaJS.git
synced 2026-08-12 21:21:42 +08:00
Fixed bug in event-handling; Updated webrtc-adapter
This commit is contained in:
Vendored
+1523
-1001
File diff suppressed because one or more lines are too long
Vendored
+4
-3
File diff suppressed because one or more lines are too long
+1534
-1012
File diff suppressed because one or more lines are too long
+1
-1
@@ -108,6 +108,6 @@
|
|||||||
"lodash": "^4.6.1",
|
"lodash": "^4.6.1",
|
||||||
"ndarray": "^1.0.18",
|
"ndarray": "^1.0.18",
|
||||||
"ndarray-linear-interpolate": "^1.0.0",
|
"ndarray-linear-interpolate": "^1.0.0",
|
||||||
"webrtc-adapter": "^1.0.6"
|
"webrtc-adapter": "^1.3.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-1
@@ -50,10 +50,22 @@ export default (function() {
|
|||||||
var event = getEvent(eventName),
|
var event = getEvent(eventName),
|
||||||
subscribers = event.subscribers;
|
subscribers = event.subscribers;
|
||||||
|
|
||||||
event.subscribers = subscribers.filter(function(subscriber) {
|
// Publish one-time subscriptions
|
||||||
|
subscribers.filter(function(subscriber) {
|
||||||
|
return !!subscriber.once;
|
||||||
|
}).forEach((subscriber) => {
|
||||||
publishSubscription(subscriber, data);
|
publishSubscription(subscriber, data);
|
||||||
|
});
|
||||||
|
|
||||||
|
// remove them from the subscriber
|
||||||
|
event.subscribers = subscribers.filter(function(subscriber) {
|
||||||
return !subscriber.once;
|
return !subscriber.once;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// publish the rest
|
||||||
|
event.subscribers.forEach((subscriber) => {
|
||||||
|
publishSubscription(subscriber, data);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
once: function(event, callback, async) {
|
once: function(event, callback, async) {
|
||||||
subscribe(event, {
|
subscribe(event, {
|
||||||
|
|||||||
+12
-12
@@ -1,7 +1,6 @@
|
|||||||
import {merge, pick} from 'lodash';
|
import {merge, pick} from 'lodash';
|
||||||
|
|
||||||
var streamRef,
|
var streamRef;
|
||||||
loadedDataHandler;
|
|
||||||
|
|
||||||
function waitForVideo(video) {
|
function waitForVideo(video) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
@@ -35,13 +34,14 @@ function waitForVideo(video) {
|
|||||||
function initCamera(video, constraints) {
|
function initCamera(video, constraints) {
|
||||||
return navigator.mediaDevices.getUserMedia(constraints)
|
return navigator.mediaDevices.getUserMedia(constraints)
|
||||||
.then((stream) => {
|
.then((stream) => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve) => {
|
||||||
streamRef = stream;
|
streamRef = stream;
|
||||||
video.src = window.URL.createObjectURL(stream);
|
video.setAttribute("autoplay", 'true');
|
||||||
video.onloadedmetadata = (e) => {
|
video.srcObject = stream;
|
||||||
|
video.addEventListener('loadedmetadata', () => {
|
||||||
video.play();
|
video.play();
|
||||||
resolve();
|
resolve();
|
||||||
};
|
});
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.then(waitForVideo.bind(null, video));
|
.then(waitForVideo.bind(null, video));
|
||||||
@@ -51,13 +51,13 @@ function deprecatedConstraints(videoConstraints) {
|
|||||||
const normalized = pick(videoConstraints, ["width", "height", "facingMode",
|
const normalized = pick(videoConstraints, ["width", "height", "facingMode",
|
||||||
"aspectRatio", "deviceId"]);
|
"aspectRatio", "deviceId"]);
|
||||||
|
|
||||||
if (typeof videoConstraints["minAspectRatio"] !== 'undefined' &&
|
if (typeof videoConstraints.minAspectRatio !== 'undefined' &&
|
||||||
videoConstraints["minAspectRatio"] > 0) {
|
videoConstraints.minAspectRatio > 0) {
|
||||||
normalized["aspectRatio"] = videoConstraints["minAspectRatio"];
|
normalized.aspectRatio = videoConstraints.minAspectRatio;
|
||||||
console.log("WARNING: Constraint 'minAspectRatio' is deprecated; Use 'aspectRatio' instead");
|
console.log("WARNING: Constraint 'minAspectRatio' is deprecated; Use 'aspectRatio' instead");
|
||||||
}
|
}
|
||||||
if (typeof videoConstraints["facing"] !== 'undefined') {
|
if (typeof videoConstraints.facing !== 'undefined') {
|
||||||
normalized["facingMode"] = videoConstraints["facing"];
|
normalized.facingMode = videoConstraints.facing;
|
||||||
console.log("WARNING: Constraint 'facing' is deprecated. Use 'facingMode' instead'");
|
console.log("WARNING: Constraint 'facing' is deprecated. Use 'facingMode' instead'");
|
||||||
}
|
}
|
||||||
return normalized;
|
return normalized;
|
||||||
@@ -69,7 +69,7 @@ function applyCameraFacing(facing, constraints) {
|
|||||||
}
|
}
|
||||||
if ( typeof MediaStreamTrack !== 'undefined' &&
|
if ( typeof MediaStreamTrack !== 'undefined' &&
|
||||||
typeof MediaStreamTrack.getSources !== 'undefined') {
|
typeof MediaStreamTrack.getSources !== 'undefined') {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve) => {
|
||||||
MediaStreamTrack.getSources((sourceInfos) => {
|
MediaStreamTrack.getSources((sourceInfos) => {
|
||||||
const videoSource = sourceInfos.filter((sourceInfo) => (
|
const videoSource = sourceInfos.filter((sourceInfo) => (
|
||||||
sourceInfo.kind === "video" && sourceInfo.facing === facing
|
sourceInfo.kind === "video" && sourceInfo.facing === facing
|
||||||
|
|||||||
@@ -67,7 +67,6 @@ function initInputStream(cb) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_inputStream.setAttribute("preload", "auto");
|
_inputStream.setAttribute("preload", "auto");
|
||||||
_inputStream.setAttribute("autoplay", true);
|
|
||||||
_inputStream.setInputStream(_config.inputStream);
|
_inputStream.setInputStream(_config.inputStream);
|
||||||
_inputStream.addEventListener("canrecord", canRecord.bind(undefined, cb));
|
_inputStream.addEventListener("canrecord", canRecord.bind(undefined, cb));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,9 +27,10 @@ beforeEach(function() {
|
|||||||
sinon.spy(tracks[0], "stop");
|
sinon.spy(tracks[0], "stop");
|
||||||
|
|
||||||
video = {
|
video = {
|
||||||
src: null,
|
srcObject: null,
|
||||||
addEventListener: function() {},
|
addEventListener: function() {},
|
||||||
removeEventListener: function() {},
|
removeEventListener: function() {},
|
||||||
|
setAttribute: sinon.spy(),
|
||||||
play: function() {},
|
play: function() {},
|
||||||
videoWidth: 320,
|
videoWidth: 320,
|
||||||
videoHeight: 480
|
videoHeight: 480
|
||||||
@@ -60,12 +61,9 @@ describe('success', function() {
|
|||||||
CameraAccess.request(video, {})
|
CameraAccess.request(video, {})
|
||||||
.then(function () {
|
.then(function () {
|
||||||
expect(navigator.mediaDevices.getUserMedia.calledOnce).to.equal(true);
|
expect(navigator.mediaDevices.getUserMedia.calledOnce).to.equal(true);
|
||||||
expect(video.src).to.deep.equal(stream);
|
expect(video.srcObject).to.deep.equal(stream);
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
window.setTimeout(() => {
|
|
||||||
video.onloadedmetadata();
|
|
||||||
}, 100);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should allow deprecated constraints to be used", (done) => {
|
it("should allow deprecated constraints to be used", (done) => {
|
||||||
@@ -89,9 +87,6 @@ describe('success', function() {
|
|||||||
expect(args[0].video.maxAspectRatio).not.to.be.defined;
|
expect(args[0].video.maxAspectRatio).not.to.be.defined;
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
window.setTimeout(() => {
|
|
||||||
video.onloadedmetadata();
|
|
||||||
}, 100);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -122,9 +117,6 @@ describe('success', function() {
|
|||||||
expect(args[0].video.deviceId).to.equal("user");
|
expect(args[0].video.deviceId).to.equal("user");
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
window.setTimeout(() => {
|
|
||||||
video.onloadedmetadata();
|
|
||||||
}, 100);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -132,15 +124,12 @@ describe('success', function() {
|
|||||||
it('should release the camera', function (done) {
|
it('should release the camera', function (done) {
|
||||||
CameraAccess.request(video, {})
|
CameraAccess.request(video, {})
|
||||||
.then(function () {
|
.then(function () {
|
||||||
expect(video.src).to.deep.equal(stream);
|
expect(video.srcObject).to.deep.equal(stream);
|
||||||
CameraAccess.release();
|
CameraAccess.release();
|
||||||
expect(video.src.getVideoTracks()).to.have.length(1);
|
expect(video.srcObject.getVideoTracks()).to.have.length(1);
|
||||||
expect(video.src.getVideoTracks()[0].stop.calledOnce).to.equal(true);
|
expect(video.srcObject.getVideoTracks()[0].stop.calledOnce).to.equal(true);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
window.setTimeout(() => {
|
|
||||||
video.onloadedmetadata();
|
|
||||||
}, 100);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user