maestro-react-player
Version:
A React component for playing a variety of URLs, including file paths, YouTube, Facebook, Twitch, SoundCloud, Streamable, Vimeo, Wistia and DailyMotion
187 lines (161 loc) • 6.44 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.FaceMask = undefined;
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _utils = require('../utils');
var _singlePlayer = require('../singlePlayer');
var _singlePlayer2 = _interopRequireDefault(_singlePlayer);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var SDK_URL = 'https://www.nfl.com/libs/playaction/api.js';
var SDK_GLOBAL = 'nfl';
var MATCH_FILE_URL = /nflent-vh\.akamaihd\.net\/.+\.m3u8/;
var PLAYER_ID_PREFIX = 'facemask-player-';
var FaceMask = exports.FaceMask = function (_Component) {
_inherits(FaceMask, _Component);
function FaceMask() {
var _ref;
var _temp, _this, _ret;
_classCallCheck(this, FaceMask);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = FaceMask.__proto__ || Object.getPrototypeOf(FaceMask)).call.apply(_ref, [this].concat(args))), _this), _this.callPlayer = _utils.callPlayer, _this.duration = null, _this.volume = null, _this.currentTime = null, _this.secondsLoaded = null, _this.playerID = PLAYER_ID_PREFIX + (0, _utils.randomString)(), _this.ref = function (container) {
_this.container = container;
}, _temp), _possibleConstructorReturn(_this, _ret);
}
_createClass(FaceMask, [{
key: 'load',
value: function load(url) {
var _this2 = this;
this.duration = null;
(0, _utils.getSDK)(SDK_URL, SDK_GLOBAL).then(function (nfl) {
if (!_this2.container) return;
// eslint-disable-next-line new-cap
_this2.player = new nfl.playaction({
containerId: _this2.playerID,
initialVideo: { url: url },
height: '100%',
width: '100%'
});
var _nfl$playaction$EVENT = nfl.playaction.EVENTS,
PLAYER_READY = _nfl$playaction$EVENT.PLAYER_READY,
STATUS = _nfl$playaction$EVENT.STATUS,
TIME_UPDATE = _nfl$playaction$EVENT.TIME_UPDATE,
VOLUME = _nfl$playaction$EVENT.VOLUME;
var _nfl$playaction$STATU = nfl.playaction.STATUS,
COMPLETE = _nfl$playaction$STATU.COMPLETE,
ERROR = _nfl$playaction$STATU.ERROR,
PAUSED = _nfl$playaction$STATU.PAUSED,
PLAYING = _nfl$playaction$STATU.PLAYING;
_this2.player.on(PLAYER_READY, _this2.props.onReady);
_this2.player.on(VOLUME, _this2.props.onVolumeChange);
_this2.player.on(STATUS, function (e) {
switch (e.status) {
case COMPLETE:
{
_this2.props.onEnded();
break;
}
case ERROR:
{
_this2.props.onError(e);
break;
}
case PAUSED:
{
_this2.props.onPause();
break;
}
case PLAYING:
{
_this2.props.onPlay();
break;
}
}
});
_this2.player.on(TIME_UPDATE, function (_ref2) {
var currentTime = _ref2.currentTime,
duration = _ref2.duration;
_this2.currentTime = currentTime;
_this2.duration = duration || Infinity;
});
}, this.props.onError);
}
}, {
key: 'play',
value: function play() {
this.callPlayer('play');
}
}, {
key: 'pause',
value: function pause() {
this.callPlayer('pause');
}
}, {
key: 'stop',
value: function stop() {
this.callPlayer('destroy');
}
}, {
key: 'seekTo',
value: function seekTo(seconds) {
this.callPlayer('seek', seconds);
}
}, {
key: 'setVolume',
value: function setVolume(fraction) {
// not supported
}
}, {
key: 'mute',
value: function mute() {
this.callPlayer('mute');
}
}, {
key: 'unmute',
value: function unmute() {
this.callPlayer('unmute');
}
}, {
key: 'getDuration',
value: function getDuration() {
return this.duration;
}
}, {
key: 'getCurrentTime',
value: function getCurrentTime() {
return this.currentTime;
}
}, {
key: 'getSecondsLoaded',
value: function getSecondsLoaded() {
return this.secondsLoaded;
}
}, {
key: 'render',
value: function render() {
var style = {
width: '100%',
height: '100%'
};
return _react2['default'].createElement('div', {
id: this.playerID,
ref: this.ref,
style: style
});
}
}]);
return FaceMask;
}(_react.Component);
FaceMask.displayName = 'FaceMask';
FaceMask.canPlay = function (url) {
return MATCH_FILE_URL.test(url);
};
exports['default'] = (0, _singlePlayer2['default'])(FaceMask);