react-player-custom
Version:
A React component for playing a variety of URLs, including file paths, YouTube, Facebook, Twitch, SoundCloud, Streamable, Vimeo, Wistia and DailyMotion
182 lines (155 loc) • 6.35 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Wistia = undefined;
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
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 = '//fast.wistia.com/assets/external/E-v1.js';
var SDK_GLOBAL = 'Wistia';
var MATCH_URL = /(?:wistia\.com|wi\.st)\/(?:medias|embed)\/(.*)$/;
var Wistia = exports.Wistia = function (_Component) {
_inherits(Wistia, _Component);
function Wistia() {
var _ref;
var _temp, _this, _ret;
_classCallCheck(this, Wistia);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = Wistia.__proto__ || Object.getPrototypeOf(Wistia)).call.apply(_ref, [this].concat(args))), _this), _this.callPlayer = _utils.callPlayer, _this.mute = function () {
_this.callPlayer('mute');
}, _this.unmute = function () {
_this.callPlayer('unmute');
}, _temp), _possibleConstructorReturn(_this, _ret);
}
_createClass(Wistia, [{
key: 'getID',
value: function getID(url) {
return url && url.match(MATCH_URL)[1];
}
}, {
key: 'load',
value: function load(url) {
var _this2 = this;
var _props = this.props,
playing = _props.playing,
muted = _props.muted,
controls = _props.controls,
_onReady = _props.onReady,
onPlay = _props.onPlay,
onPause = _props.onPause,
onSeek = _props.onSeek,
onEnded = _props.onEnded,
config = _props.config,
onError = _props.onError;
(0, _utils.getSDK)(SDK_URL, SDK_GLOBAL).then(function () {
window._wq = window._wq || [];
window._wq.push({
id: _this2.getID(url),
options: _extends({
autoPlay: playing,
silentAutoPlay: 'allow',
muted: muted,
controlsVisibleOnLoad: controls
}, config.wistia.options),
onReady: function onReady(player) {
_this2.player = player;
_this2.unbind();
_this2.player.bind('play', onPlay);
_this2.player.bind('pause', onPause);
_this2.player.bind('seek', onSeek);
_this2.player.bind('end', onEnded);
_onReady();
}
});
}, onError);
}
}, {
key: 'play',
value: function play() {
this.callPlayer('play');
}
}, {
key: 'pause',
value: function pause() {
this.callPlayer('pause');
}
}, {
key: 'unbind',
value: function unbind() {
var _props2 = this.props,
onPlay = _props2.onPlay,
onPause = _props2.onPause,
onSeek = _props2.onSeek,
onEnded = _props2.onEnded;
this.player.unbind('play', onPlay);
this.player.unbind('pause', onPause);
this.player.unbind('seek', onSeek);
this.player.unbind('end', onEnded);
}
}, {
key: 'stop',
value: function stop() {
this.unbind();
this.callPlayer('remove');
}
}, {
key: 'seekTo',
value: function seekTo(seconds) {
this.callPlayer('time', seconds);
}
}, {
key: 'setVolume',
value: function setVolume(fraction) {
this.callPlayer('volume', fraction);
}
}, {
key: 'setPlaybackRate',
value: function setPlaybackRate(rate) {
this.callPlayer('playbackRate', rate);
}
}, {
key: 'getDuration',
value: function getDuration() {
return this.callPlayer('duration');
}
}, {
key: 'getCurrentTime',
value: function getCurrentTime() {
return this.callPlayer('time');
}
}, {
key: 'getSecondsLoaded',
value: function getSecondsLoaded() {
return null;
}
}, {
key: 'render',
value: function render() {
var id = this.getID(this.props.url);
var className = 'wistia_embed wistia_async_' + id;
var style = {
width: '100%',
height: '100%'
};
return _react2['default'].createElement('div', { key: id, className: className, style: style });
}
}]);
return Wistia;
}(_react.Component);
Wistia.displayName = 'Wistia';
Wistia.canPlay = function (url) {
return MATCH_URL.test(url);
};
Wistia.loopOnEnded = true;
exports['default'] = (0, _singlePlayer2['default'])(Wistia);
;