Skip to content

Commit

Permalink
fire VRDisplay connect only when polyfilled display is used. Fixes #303
Browse files Browse the repository at this point in the history
  • Loading branch information
jsantell committed Mar 14, 2018
1 parent 2c67610 commit 73e6bb0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,14 @@
buttons.hidden = vrDisplay.isPresenting;
}

function onVRDisplayConnect(e) {
console.log('onVRDisplayConnect', (e.display || (e.detail && e.detail.display)));
}

// Resize the WebGL canvas when we resize and also when we change modes.
window.addEventListener('resize', onResize);
window.addEventListener('vrdisplaypresentchange', onVRDisplayPresentChange);
window.addEventListener('vrdisplayconnect', onVRDisplayConnect);

// Button click handlers.
document.querySelector('button#fullscreen').addEventListener('click', function() {
Expand Down
7 changes: 7 additions & 0 deletions src/webvr-polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ function WebVRPolyfill(config) {
// inject our own polyfill
if (!this.hasNative || this.config.PROVIDE_MOBILE_VRDISPLAY && isMobile()) {
this.enable();
// If we need to create a CardboardVRDisplay, fire the `vrdisplayconnect`
// event when the polyfill is enabled
this.getVRDisplays().then(function (displays) {
if (displays && displays[0] && displays[0].fireVRDisplayConnect_) {
displays[0].fireVRDisplayConnect_();
}
});
}
}

Expand Down

0 comments on commit 73e6bb0

Please sign in to comment.