Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for issue #670 #673

Merged
merged 1 commit into from
Dec 22, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 20 additions & 37 deletions three.js/src/threex/threex-artoolkitsource.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,21 +97,15 @@ ARjs.Source.prototype.init = function(onReady, onError){

ARjs.Source.prototype._initSourceImage = function(onReady) {
// TODO make it static
var domElement = document.createElement('img')
domElement.src = this.parameters.sourceUrl
var domElement = document.createElement('img');
domElement.src = this.parameters.sourceUrl;

domElement.width = this.parameters.sourceWidth
domElement.height = this.parameters.sourceHeight
domElement.style.width = this.parameters.displayWidth+'px'
domElement.style.height = this.parameters.displayHeight+'px'

// wait until the video stream is ready
var interval = setInterval(function() {
if (!domElement.naturalWidth) return;
onReady()
clearInterval(interval)
}, 1000/50);
domElement.width = this.parameters.sourceWidth;
domElement.height = this.parameters.sourceHeight;
domElement.style.width = this.parameters.displayWidth+'px';
domElement.style.height = this.parameters.displayHeight+'px';

onReady();
return domElement
}

Expand All @@ -123,33 +117,28 @@ ARjs.Source.prototype._initSourceImage = function(onReady) {
ARjs.Source.prototype._initSourceVideo = function(onReady) {
// TODO make it static
var domElement = document.createElement('video');
domElement.src = this.parameters.sourceUrl
domElement.src = this.parameters.sourceUrl;

domElement.style.objectFit = 'initial'
domElement.style.objectFit = 'initial';

domElement.autoplay = true;
domElement.webkitPlaysinline = true;
domElement.controls = false;
domElement.loop = true;
domElement.muted = true
domElement.muted = true;

// trick to trigger the video on android
document.body.addEventListener('click', function onClick(){
document.body.removeEventListener('click', onClick);
domElement.play()
})
});

domElement.width = this.parameters.sourceWidth
domElement.height = this.parameters.sourceHeight
domElement.style.width = this.parameters.displayWidth+'px'
domElement.style.height = this.parameters.displayHeight+'px'
domElement.width = this.parameters.sourceWidth;
domElement.height = this.parameters.sourceHeight;
domElement.style.width = this.parameters.displayWidth+'px';
domElement.style.height = this.parameters.displayHeight+'px';

// wait until the video stream is ready
var interval = setInterval(function() {
if (!domElement.videoWidth) return;
onReady()
clearInterval(interval)
}, 1000/50);
onReady();
return domElement
}

Expand Down Expand Up @@ -185,7 +174,7 @@ ARjs.Source.prototype._initSourceWebcam = function(onReady, onError) {
onError({
name: '',
message: 'WebRTC issue-! '+fctName+' not present in your browser'
})
});
return null
}

Expand All @@ -194,7 +183,7 @@ ARjs.Source.prototype._initSourceWebcam = function(onReady, onError) {
var userMediaConstraints = {
audio: false,
video: {
facingMode: 'environment',
facingMode: {exact: 'environment'},
width: {
ideal: _this.parameters.sourceWidth,
// min: 1024,
Expand All @@ -206,7 +195,7 @@ ARjs.Source.prototype._initSourceWebcam = function(onReady, onError) {
// max: 1080
}
}
}
};

if (null !== _this.parameters.deviceId) {
userMediaConstraints.video.deviceId = {
Expand All @@ -227,13 +216,7 @@ ARjs.Source.prototype._initSourceWebcam = function(onReady, onError) {
});
// domElement.play();

// TODO listen to loadedmetadata instead
// wait until the video stream is ready
var interval = setInterval(function() {
if (!domElement.videoWidth) return;
onReady()
clearInterval(interval)
}, 1000/50);
onReady();
}).catch(function(error) {
onError({
name: error.name,
Expand Down