repo: janusweb
action: commit
revision: 
path_from: 
revision_from: 2cbb336f2b683b2b61b2e522780e39c867f547a1:
path_to: 
revision_to: 
git.thebackupbox.net
janusweb
git clone git://git.thebackupbox.net/janusweb
commit 2cbb336f2b683b2b61b2e522780e39c867f547a1
Author: James Baicoianu 
Date:   Fri Jun 23 02:07:32 2017 -0700

    Autoplay event handling

diff --git a/scripts/object.js b/scripts/object.js
index 04db73c3f3b8e5c45554ba81c1a323660e72057b..
index ..5b413a2f86e72a8f370b178881712f40d2f87472 100644
--- a/scripts/object.js
+++ b/scripts/object.js
@@ -246,6 +246,8 @@ elation.require(['janusweb.janusbase', 'janusweb.websurface'], function() {
           texture.minFilter = THREE.LinearFilter;
           texture.magFilter = THREE.LinearFilter;
           elation.events.add(texture, 'videoframe', elation.bind(this, this.refresh));
+          elation.events.add(texture, 'autoplaystart', elation.bind(this, this.handleAutoplayStart));
+          elation.events.add(texture, 'autoplayfailed', elation.bind(this, this.handleAutoplayFailed));
           this.videotexture = texture;
           this.assignTextureParameters(texture, modelasset);
           if (videoasset.auto_play) {
@@ -253,6 +255,7 @@ elation.require(['janusweb.janusbase', 'janusweb.websurface'], function() {
           } else {
             texture.image.pause();
           }
+          elation.events.add(this, elation.bind(this, this.handleVideoClick));
         }
       }
       if (this.properties.websurface_id) {
@@ -449,16 +452,6 @@ elation.require(['janusweb.janusbase', 'janusweb.websurface'], function() {
       texture.anisotropy = (linear ? elation.config.get('engine.assets.image.anisotropy', 4) : 1);
       texture.generateMipmaps = linear;
     }
-    this.pauseVideo = function() {
-      if (this.videotexture) {
-        var video = this.videotexture.image;
-        if (video.currentTime > 0 && !video.paused && !video.ended) {
-          video.pause();
-        } else {
-          video.play();
-        }
-      }
-    }
     this.start = function() {
       if (this.image_id) {
         var textureasset = this.getAsset('image', this.image_id);
@@ -499,6 +492,31 @@ elation.require(['janusweb.janusbase', 'janusweb.websurface'], function() {
         this.websurface.stop();
       }
     }
+    this.handleVideoClick = function() {
+      if (this.videotexture) {
+        var video = this.videotexture.image;
+        if (video.currentTime > 0 && !video.paused && !video.ended) {
+          video.pause();
+        } else {
+          video.play();
+        }
+      }
+    }
+    this.handleAutoplayStart = function() {
+      if (this.playbutton) {
+        this.remove(this.playbutton);
+      }
+    }
+    this.handleAutoplayFailed = function() {
+      if (!this.playbutton) {
+        this.playbutton = this.spawn('janustext', null, {
+          janus: this.janus,
+          room: this.room,
+          text: 'play'
+        });
+        elation.events.add(this.playbutton, 'click', elation.bind(this, this.play));
+      }
+    }
     this.getProxyObject = function() {
       var proxy = elation.engine.things.janusobject.extendclass.getProxyObject.call(this);
       proxy._proxydefs = {

-----END OF PAGE-----