Skip to content

Commit

Permalink
fix: add a cardboard button for native webvr support (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
gkatsev authored Aug 17, 2017
1 parent a644d1e commit e946219
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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});
}
Expand All @@ -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];
}
Expand Down

0 comments on commit e946219

Please sign in to comment.