all files / src/ cardboard-button.js

20% Statements 2/10
0% Branches 0/2
0% Functions 0/4
20% Lines 2/10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120                                                                                                                                                                                                                                           
import window from 'global/window';
import videojs from 'video.js';
// Add Cardboard button
const Button = videojs.getComponent('Button');
 
class CardboardButton extends Button {
  constructor(player, options) {
    super(player, options);
 
    // this.handleVrDisplayActivate_ = videojs.bind(this, this.handleVrDisplayActivate_);
    // this.handleVrDisplayDeactivate_ = videojs.bind(this, this.handleVrDisplayDeactivate_);
    // this.handleVrDisplayPresentChange_ = videojs.bind(this, this.handleVrDisplayPresentChange_);
    // this.handleOrientationChange_ = videojs.bind(this, this.handleOrientationChange_);
    // window.addEventListener('orientationchange', this.handleOrientationChange_);
    // window.addEventListener('vrdisplayactivate', this.handleVrDisplayActivate_);
    // window.addEventListener('vrdisplaydeactivate', this.handleVrDisplayDeactivate_);
 
    // vrdisplaypresentchange does not fire activate or deactivate
    // and happens when hitting the back button during cardboard mode
    // so we need to make sure we stay in the correct state by
    // listening to it and checking if we are presenting it or not
    // window.addEventListener('vrdisplaypresentchange', this.handleVrDisplayPresentChange_);
 
    // we cannot show the cardboard button in fullscreen on
    // android as it breaks the controls, and makes it impossible
    // to exit cardboard mode
    // if (videojs.browser.IS_ANDROID) {
    //   this.on(player, 'fullscreenchange', () => {
    //     if (player.isFullscreen()) {
    //       this.hide();
    //     } else {
    //       this.show();
    //     }
    //   });
    // }
  }
 
  buildCSSClass() {
    return `vjs-button-vr ${super.buildCSSClass()}`;
  }
 
//   handleVrDisplayPresentChange_() {
//     if (!this.player_.vr().vrDisplay.isPresenting && this.active_) {
//       this.handleVrDisplayDeactivate_();
//     }
//     if (this.player_.vr().vrDisplay.isPresenting && !this.active_) {
//       this.handleVrDisplayActivate_();
//     }
//   }
 
//   handleOrientationChange_() {
//     if (this.active_ && videojs.browser.IS_IOS) {
//       this.changeSize_();
//     }
//   }
 
//   changeSize_() {
//     this.player_.width(window.innerWidth);
//     this.player_.height(window.innerHeight);
//     window.dispatchEvent(new window.Event('resize'));
//   }
 
//   handleVrDisplayActivate_() {
//     // we mimic fullscreen on IOS
//     if (videojs.browser.IS_IOS) {
//       this.oldWidth_ = this.player_.currentWidth();
//       this.oldHeight_ = this.player_.currentHeight();
//       this.player_.enterFullWindow();
//       this.changeSize_();
//     }
 
//     this.active_ = true;
//   }
 
//   handleVrDisplayDeactivate_() {
//     // un-mimic fullscreen on iOS
//     if (videojs.browser.IS_IOS) {
//       if (this.oldWidth_) {
//         this.player_.width(this.oldWidth_);
//       }
//       if (this.oldHeight_) {
//         this.player_.height(this.oldHeight_);
//       }
//       this.player_.exitFullWindow();
//     }
 
//     this.active_ = false;
//   }
 
  handleClick(event) {
    // if cardboard mode display is not active, activate it
    // otherwise deactivate it
    if (!this.active_) {
      // This starts playback mode when the cardboard button
      // is clicked on Andriod. We need to do this as the controls
      // disappear
    //   if (!this.player_.hasStarted() && videojs.browser.IS_ANDROID) {
    //     this.player_.play();
    //   }
      window.dispatchEvent(new window.Event('vrdisplayactivate'));
      this.active_ = true;
    } else {
      window.dispatchEvent(new window.Event('vrdisplaydeactivate'));
      this.active_ = false;
    }
  }
 
  dispose() {
    super.dispose();
    // window.removeEventListener('vrdisplayactivate', this.handleVrDisplayActivate_);
    // window.removeEventListener('vrdisplaydeactivate', this.handleVrDisplayDeactivate_);
    // window.removeEventListener('vrdisplaypresentchange', this.handleVrDisplayPresentChange_);
  }
 
}
 
videojs.registerComponent('CardboardButton', CardboardButton);
 
export default CardboardButton;