Skip to content

Commit

Permalink
Merge pull request #673 from ongeo-dev/dev-issue-670
Browse files Browse the repository at this point in the history
Fix for issue #670
  • Loading branch information
nicolocarpignoli authored Dec 22, 2019
2 parents 88c25dd + ed7e6b5 commit 32bf818
Showing 1 changed file with 20 additions and 37 deletions.
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

0 comments on commit 32bf818

Please sign in to comment.