Sha256: a39ec21af830aa699063fed8c8a8016bc1bfe1b7a7c1449c17bdc306d7f7fdf9

Contents?: true

Size: 1.9 KB

Versions: 6

Compression:

Stored size: 1.9 KB

Contents

//= require_self
//= require ./player/media_events

pageflow.vr.Player = pageflow.Object.extend({
  initialize: function(iframe) {
    this.iframe = iframe;
    this.cachedVolume = 1;
    this.cachedPaused = iframe.src.indexOf('no_autoplay=true') >= 0;
    this.id = getIdParam(iframe.src);

    this.messageListener = this.onMessage.bind(this);

    if (this.id) {
      window.addEventListener('message', this.messageListener);
    }
  },

  dispose: function() {
    this.off(null, null, null);
    window.removeEventListener('message', this.messageListener);
  },

  play: function() {
    this.cachedPaused = false;
    this.sendCommand('play');
  },

  pause: function() {
    this.cachedPaused = true;
    this.sendCommand('pause');
  },

  paused: function() {
    return this.cachedPaused;
  },

  volume: function(value) {
    if (typeof value === 'undefined') {
      return this.cachedVolume;
    }
    else {
      this.cachedVolume = value;
      this.sendCommand('volume', Math.max(0, Math.min(1, value)));
    }
  },

  enterVRMode: function() {
    this.sendCommand('enterVRMode');
  },

  sendCommand: function(name, value) {
    this.iframe.contentWindow.postMessage({
      type: 'PlayerCommand',
      command: name,
      value: value
    }, '*');
  },

  onMessage: function(event) {
    var message = event.data;

    if (message.type == 'VrViewEvent' &&
        message.vrViewId == this.id) {

      this.trigger(message.event, message.eventData);
    }
  },

  one: function() {
    this.once.apply(this, arguments);
  }
});

function getIdParam(url) {
  var result = url.match(/id=(\d+)/);
  return result && result[1];
}

pageflow.vr.Player.create = function(iframe, options) {
  if (!iframe) {
    return null;
  }

  var player = new pageflow.vr.Player(iframe);

  pageflow.mediaPlayer.enhance(player, {
    volumeFading: true
  });

  pageflow.vr.Player.mediaEvents(player, options.context);

  return player;
};

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
pageflow-vr-1.5.0 app/assets/javascripts/pageflow/vr/player.js
pageflow-vr-1.4.0 app/assets/javascripts/pageflow/vr/player.js
pageflow-vr-1.3.0 app/assets/javascripts/pageflow/vr/player.js
pageflow-vr-1.2.0 app/assets/javascripts/pageflow/vr/player.js
pageflow-vr-1.1.0 app/assets/javascripts/pageflow/vr/player.js
pageflow-vr-1.0.0 app/assets/javascripts/pageflow/vr/player.js