From e946219af6a75ab33e84407e4259d1a3156f4517 Mon Sep 17 00:00:00 2001 From: Gary Katsevman Date: Thu, 17 Aug 2017 17:48:11 -0400 Subject: [PATCH] fix: add a cardboard button for native webvr support (#22) --- src/plugin.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/plugin.js b/src/plugin.js index d53552d6..e040dae3 100644 --- a/src/plugin.js +++ b/src/plugin.js @@ -456,7 +456,7 @@ class VR extends Plugin { if (this.options_.forceCardboard || videojs.browser.IS_ANDROID || videojs.browser.IS_IOS) { - this.player_.controlBar.addChild('CardboardButton', {}); + this.addCardboardButton_(); } // if ios remove full screen toggle @@ -523,6 +523,13 @@ class VR extends Plugin { this.log('WebVR supported, VRDisplays found.'); this.vrDisplay = displays[0]; this.log(this.vrDisplay); + + // Native WebVR Head Mounted Displays (HMDs) like the HTC Vive + // also need the cardboard button to enter fully immersive mode + // so, we want to add the button if we're not polyfilled. + if (!this.vrDisplay.isPolyfilled) { + this.addCardboardButton_(); + } } else { this.triggerError_({code: 'web-vr-no-devices-found', dismiss: false}); } @@ -543,6 +550,12 @@ class VR extends Plugin { this.initialized_ = true; } + addCardboardButton_() { + if (!this.player_.getChild('CardboardButton')) { + this.player_.controlBar.addChild('CardboardButton', {}); + } + } + getVideoEl_() { return this.player_.el().getElementsByTagName('video')[0]; }