提交 0452e15d 编写于 作者: N nicolo.carpignoli

feat: camera init and camera error events triggered on window

上级 1d58baf9
......@@ -4,6 +4,16 @@
<script src="../build/aframe-ar.js"></script>
<!-- Register an aframe component that allows reacting to marker events -->
<script>
window.addEventListener('camera-init', (data) => {
console.log('camera-init', data);
// TODO: Add your own code
})
window.addEventListener('camera-error', (error) => {
console.log('camera-error', error);
// TODO: Add your own code e.g. splash screen, message to user, etc.
})
AFRAME.registerComponent('registerevents', {
init: function () {
var marker = this.el;
......@@ -50,7 +60,7 @@
<a-torus-knot radius='0.26' radius-tubular='0.05'>
<a-animation attribute="rotation" to="360 0 0" dur="5000" easing='linear' repeat="indefinite"></a-animation>
</a-torus-knot>
</a-box>
</a-box>
</a-marker>
<!-- add a simple camera -->
......
......@@ -157,6 +157,8 @@ ARjs.Source.prototype._initSourceWebcam = function(onReady, onError) {
// init default value
onError = onError || function(error){
alert('Webcam Error\nName: '+error.name + '\nMessage: '+error.message)
const event = new CustomEvent('camera-error', {error});
window.dispatchEvent(event);
}
var domElement = document.createElement('video');
......@@ -211,10 +213,12 @@ ARjs.Source.prototype._initSourceWebcam = function(onReady, onError) {
// set the .src of the domElement
domElement.srcObject = stream;
const event = new CustomEvent('camera-init', {stream});
window.dispatchEvent(event);
// to start the video, when it is possible to start it only on userevent. like in android
document.body.addEventListener('click', function(){
domElement.play();
})
});
// domElement.play();
// TODO listen to loadedmetadata instead
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册