优化结构

This commit is contained in:
Harvey Zack committed 2018-12-14 17:03:41 +08:00
1 parent c6869686c3
commit f2658673dc
6 files changed
+369 -404

No files matched your search

+6 -2
View File
@@ -24,8 +24,12 @@
new Artplayer({ new Artplayer({
container: '.artplayer', container: '.artplayer',
url: function () { url: $urlInput.value,
return this.plugins.artplayerPluginFlv.load($urlInput.value) type: 'flv',
customType: {
flv: function(video, url) {
this.plugins.artplayerPluginFlv.init(video, url);
},
}, },
plugins: [artplayerPluginFlv] plugins: [artplayerPluginFlv]
}); });
+344 -365
View File
@@ -1,371 +1,350 @@
(function (global, factory) { (function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) : typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global['artplayer-plugin-flv'] = {}))); (factory((global['artplayer-plugin-flv'] = {})));
}(this, (function (exports) { 'use strict'; }(this, (function (exports) { 'use strict';
function createCommonjsModule(fn, module) { function _classCallCheck(instance, Constructor) {
return module = { exports: {} }, fn(module, module.exports), module.exports; if (!(instance instanceof Constructor)) {
} throw new TypeError("Cannot call a class as a function");
}
var _typeof_1 = createCommonjsModule(function (module) { }
function _typeof2(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof2 = function _typeof2(obj) { return typeof obj; }; } else { _typeof2 = function _typeof2(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof2(obj); }
var classCallCheck = _classCallCheck;
function _typeof(obj) {
if (typeof Symbol === "function" && _typeof2(Symbol.iterator) === "symbol") { function _defineProperties(target, props) {
module.exports = _typeof = function _typeof(obj) { for (var i = 0; i < props.length; i++) {
return _typeof2(obj); var descriptor = props[i];
}; descriptor.enumerable = descriptor.enumerable || false;
} else { descriptor.configurable = true;
module.exports = _typeof = function _typeof(obj) { if ("value" in descriptor) descriptor.writable = true;
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : _typeof2(obj); Object.defineProperty(target, descriptor.key, descriptor);
}; }
} }
return _typeof(obj); function _createClass(Constructor, protoProps, staticProps) {
} if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
module.exports = _typeof; return Constructor;
}); }
function _classCallCheck(instance, Constructor) { var createClass = _createClass;
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function"); function createCommonjsModule(fn, module) {
} return module = { exports: {} }, fn(module, module.exports), module.exports;
} }
var classCallCheck = _classCallCheck; var _typeof_1 = createCommonjsModule(function (module) {
function _typeof2(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof2 = function _typeof2(obj) { return typeof obj; }; } else { _typeof2 = function _typeof2(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof2(obj); }
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) { function _typeof(obj) {
var descriptor = props[i]; if (typeof Symbol === "function" && _typeof2(Symbol.iterator) === "symbol") {
descriptor.enumerable = descriptor.enumerable || false; module.exports = _typeof = function _typeof(obj) {
descriptor.configurable = true; return _typeof2(obj);
if ("value" in descriptor) descriptor.writable = true; };
Object.defineProperty(target, descriptor.key, descriptor); } else {
} module.exports = _typeof = function _typeof(obj) {
} return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : _typeof2(obj);
};
function _createClass(Constructor, protoProps, staticProps) { }
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps); return _typeof(obj);
return Constructor; }
}
module.exports = _typeof;
var createClass = _createClass; });
function _assertThisInitialized(self) { function _assertThisInitialized(self) {
if (self === void 0) { if (self === void 0) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
} }
return self; return self;
} }
var assertThisInitialized = _assertThisInitialized; var assertThisInitialized = _assertThisInitialized;
function _possibleConstructorReturn(self, call) { function _possibleConstructorReturn(self, call) {
if (call && (_typeof_1(call) === "object" || typeof call === "function")) { if (call && (_typeof_1(call) === "object" || typeof call === "function")) {
return call; return call;
} }
return assertThisInitialized(self); return assertThisInitialized(self);
} }
var possibleConstructorReturn = _possibleConstructorReturn; var possibleConstructorReturn = _possibleConstructorReturn;
var getPrototypeOf = createCommonjsModule(function (module) { var getPrototypeOf = createCommonjsModule(function (module) {
function _getPrototypeOf(o) { function _getPrototypeOf(o) {
module.exports = _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { module.exports = _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
return o.__proto__ || Object.getPrototypeOf(o); return o.__proto__ || Object.getPrototypeOf(o);
}; };
return _getPrototypeOf(o); return _getPrototypeOf(o);
} }
module.exports = _getPrototypeOf; module.exports = _getPrototypeOf;
}); });
var setPrototypeOf = createCommonjsModule(function (module) { var setPrototypeOf = createCommonjsModule(function (module) {
function _setPrototypeOf(o, p) { function _setPrototypeOf(o, p) {
module.exports = _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { module.exports = _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
o.__proto__ = p; o.__proto__ = p;
return o; return o;
}; };
return _setPrototypeOf(o, p); return _setPrototypeOf(o, p);
} }
module.exports = _setPrototypeOf; module.exports = _setPrototypeOf;
}); });
function _inherits(subClass, superClass) { function _inherits(subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) { if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function"); throw new TypeError("Super expression must either be null or a function");
} }
subClass.prototype = Object.create(superClass && superClass.prototype, { subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: { constructor: {
value: subClass, value: subClass,
writable: true, writable: true,
configurable: true configurable: true
} }
}); });
if (superClass) setPrototypeOf(subClass, superClass); if (superClass) setPrototypeOf(subClass, superClass);
} }
var inherits = _inherits; var inherits = _inherits;
function E() {// Keep this empty so it's easier to inherit from function E() {// Keep this empty so it's easier to inherit from
// (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3) // (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3)
} }
E.prototype = { E.prototype = {
on: function on(name, callback, ctx) { on: function on(name, callback, ctx) {
var e = this.e || (this.e = {}); var e = this.e || (this.e = {});
(e[name] || (e[name] = [])).push({ (e[name] || (e[name] = [])).push({
fn: callback, fn: callback,
ctx: ctx ctx: ctx
}); });
return this; return this;
}, },
once: function once(name, callback, ctx) { once: function once(name, callback, ctx) {
var self = this; var self = this;
function listener() { function listener() {
self.off(name, listener); self.off(name, listener);
callback.apply(ctx, arguments); callback.apply(ctx, arguments);
} }
listener._ = callback; listener._ = callback;
return this.on(name, listener, ctx); return this.on(name, listener, ctx);
}, },
emit: function emit(name) { emit: function emit(name) {
var data = [].slice.call(arguments, 1); var data = [].slice.call(arguments, 1);
var evtArr = ((this.e || (this.e = {}))[name] || []).slice(); var evtArr = ((this.e || (this.e = {}))[name] || []).slice();
var i = 0; var i = 0;
var len = evtArr.length; var len = evtArr.length;
for (i; i < len; i++) { for (i; i < len; i++) {
evtArr[i].fn.apply(evtArr[i].ctx, data); evtArr[i].fn.apply(evtArr[i].ctx, data);
} }
return this; return this;
}, },
off: function off(name, callback) { off: function off(name, callback) {
var e = this.e || (this.e = {}); var e = this.e || (this.e = {});
var evts = e[name]; var evts = e[name];
var liveEvents = []; var liveEvents = [];
if (evts && callback) { if (evts && callback) {
for (var i = 0, len = evts.length; i < len; i++) { for (var i = 0, len = evts.length; i < len; i++) {
if (evts[i].fn !== callback && evts[i].fn._ !== callback) liveEvents.push(evts[i]); if (evts[i].fn !== callback && evts[i].fn._ !== callback) liveEvents.push(evts[i]);
} }
} // Remove event from queue to prevent memory leak } // Remove event from queue to prevent memory leak
// Suggested by https://github.com/lazd // Suggested by https://github.com/lazd
// Ref: https://github.com/scottcorgan/tiny-emitter/commit/c6ebfaa9bc973b33d110a84a307742b7cf94c953#commitcomment-5024910 // Ref: https://github.com/scottcorgan/tiny-emitter/commit/c6ebfaa9bc973b33d110a84a307742b7cf94c953#commitcomment-5024910
liveEvents.length ? e[name] = liveEvents : delete e[name]; liveEvents.length ? e[name] = liveEvents : delete e[name];
return this; return this;
} }
}; };
var tinyEmitter = E; var tinyEmitter = E;
function _isNativeFunction(fn) { function _isNativeFunction(fn) {
return Function.toString.call(fn).indexOf("[native code]") !== -1; return Function.toString.call(fn).indexOf("[native code]") !== -1;
} }
var isNativeFunction = _isNativeFunction; var isNativeFunction = _isNativeFunction;
var construct = createCommonjsModule(function (module) { var construct = createCommonjsModule(function (module) {
function isNativeReflectConstruct() { function isNativeReflectConstruct() {
if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (typeof Reflect === "undefined" || !Reflect.construct) return false;
if (Reflect.construct.sham) return false; if (Reflect.construct.sham) return false;
if (typeof Proxy === "function") return true; if (typeof Proxy === "function") return true;
try { try {
Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
return true; return true;
} catch (e) { } catch (e) {
return false; return false;
} }
} }
function _construct(Parent, args, Class) { function _construct(Parent, args, Class) {
if (isNativeReflectConstruct()) { if (isNativeReflectConstruct()) {
module.exports = _construct = Reflect.construct; module.exports = _construct = Reflect.construct;
} else { } else {
module.exports = _construct = function _construct(Parent, args, Class) { module.exports = _construct = function _construct(Parent, args, Class) {
var a = [null]; var a = [null];
a.push.apply(a, args); a.push.apply(a, args);
var Constructor = Function.bind.apply(Parent, a); var Constructor = Function.bind.apply(Parent, a);
var instance = new Constructor(); var instance = new Constructor();
if (Class) setPrototypeOf(instance, Class.prototype); if (Class) setPrototypeOf(instance, Class.prototype);
return instance; return instance;
}; };
} }
return _construct.apply(null, arguments); return _construct.apply(null, arguments);
} }
module.exports = _construct; module.exports = _construct;
}); });
var wrapNativeSuper = createCommonjsModule(function (module) { var wrapNativeSuper = createCommonjsModule(function (module) {
function _wrapNativeSuper(Class) { function _wrapNativeSuper(Class) {
var _cache = typeof Map === "function" ? new Map() : undefined; var _cache = typeof Map === "function" ? new Map() : undefined;
module.exports = _wrapNativeSuper = function _wrapNativeSuper(Class) { module.exports = _wrapNativeSuper = function _wrapNativeSuper(Class) {
if (Class === null || !isNativeFunction(Class)) return Class; if (Class === null || !isNativeFunction(Class)) return Class;
if (typeof Class !== "function") { if (typeof Class !== "function") {
throw new TypeError("Super expression must either be null or a function"); throw new TypeError("Super expression must either be null or a function");
} }
if (typeof _cache !== "undefined") { if (typeof _cache !== "undefined") {
if (_cache.has(Class)) return _cache.get(Class); if (_cache.has(Class)) return _cache.get(Class);
_cache.set(Class, Wrapper); _cache.set(Class, Wrapper);
} }
function Wrapper() { function Wrapper() {
return construct(Class, arguments, getPrototypeOf(this).constructor); return construct(Class, arguments, getPrototypeOf(this).constructor);
} }
Wrapper.prototype = Object.create(Class.prototype, { Wrapper.prototype = Object.create(Class.prototype, {
constructor: { constructor: {
value: Wrapper, value: Wrapper,
enumerable: false, enumerable: false,
writable: true, writable: true,
configurable: true configurable: true
} }
}); });
return setPrototypeOf(Wrapper, Class); return setPrototypeOf(Wrapper, Class);
}; };
return _wrapNativeSuper(Class); return _wrapNativeSuper(Class);
} }
module.exports = _wrapNativeSuper; module.exports = _wrapNativeSuper;
}); });
var FlvError = var FlvError =
/*#__PURE__*/ /*#__PURE__*/
function (_Error) { function (_Error) {
inherits(FlvError, _Error); inherits(FlvError, _Error);
function FlvError(message, context) { function FlvError(message, context) {
var _this; var _this;
classCallCheck(this, FlvError); classCallCheck(this, FlvError);
_this = possibleConstructorReturn(this, getPrototypeOf(FlvError).call(this, message)); _this = possibleConstructorReturn(this, getPrototypeOf(FlvError).call(this, message));
if (typeof Error.captureStackTrace === 'function') { if (typeof Error.captureStackTrace === 'function') {
Error.captureStackTrace(assertThisInitialized(assertThisInitialized(_this)), context || _this.constructor); Error.captureStackTrace(assertThisInitialized(assertThisInitialized(_this)), context || _this.constructor);
} }
_this.name = 'FlvError'; _this.name = 'FlvError';
return _this; return _this;
} }
return FlvError; return FlvError;
}(wrapNativeSuper(Error)); }(wrapNativeSuper(Error));
function errorHandle(condition, msg) { function errorHandle(condition, msg) {
if (!condition) { if (!condition) {
throw new FlvError(msg); throw new FlvError(msg);
} }
} }
var CheckSupport = function CheckSupport() { var CheckSupport = function CheckSupport() {
classCallCheck(this, CheckSupport); classCallCheck(this, CheckSupport);
var MP4H264MimeCodec = 'video/mp4; codecs="avc1.42001E, mp4a.40.2"'; var MP4H264MimeCodec = 'video/mp4; codecs="avc1.42001E, mp4a.40.2"';
var videoElement = window.document.createElement('video'); var videoElement = window.document.createElement('video');
var canPlay = videoElement.canPlayType(MP4H264MimeCodec); var canPlay = videoElement.canPlayType(MP4H264MimeCodec);
errorHandle(window.MediaSource && window.MediaSource.isTypeSupported(MP4H264MimeCodec) && (canPlay === 'probably' || canPlay === 'maybe'), "Unsupported MIME type or codec: ".concat(MP4H264MimeCodec)); errorHandle(window.MediaSource && window.MediaSource.isTypeSupported(MP4H264MimeCodec) && (canPlay === 'probably' || canPlay === 'maybe'), "Unsupported MIME type or codec: ".concat(MP4H264MimeCodec));
errorHandle(typeof window.Promise === 'function', "Unsupported 'Promise' method"); errorHandle(typeof window.Promise === 'function', "Unsupported 'Promise' method");
errorHandle(typeof window.fetch === 'function', "Unsupported 'fetch' method"); errorHandle(typeof window.fetch === 'function', "Unsupported 'fetch' method");
}; };
var CreatMediaSource = function CreatMediaSource(art) { var CreatMediaSource = function CreatMediaSource(flv) {
classCallCheck(this, CreatMediaSource); classCallCheck(this, CreatMediaSource);
this.mediaSource = new MediaSource(); this.mediaSource = new MediaSource();
this.url = URL.createObjectURL(this.mediaSource); this.url = URL.createObjectURL(this.mediaSource);
}; flv.mediaElement.src = this.url;
};
var Flv =
/*#__PURE__*/ var Flv =
function (_Emitter) { /*#__PURE__*/
inherits(Flv, _Emitter); function (_Emitter) {
inherits(Flv, _Emitter);
function Flv(mediaElement, url) {
var _this; function Flv(mediaElement, url) {
var _this;
classCallCheck(this, Flv);
classCallCheck(this, Flv);
_this = possibleConstructorReturn(this, getPrototypeOf(Flv).call(this));
_this.support = new CheckSupport(); _this = possibleConstructorReturn(this, getPrototypeOf(Flv).call(this));
_this.mediaElement = mediaElement;
if (mediaElement) { _this.url = url;
_this.attachMediaElement(mediaElement); _this.support = new CheckSupport(assertThisInitialized(assertThisInitialized(_this)));
} _this.mediaSource = new CreatMediaSource(assertThisInitialized(assertThisInitialized(_this)));
return _this;
if (url) { }
_this.loadUrl(url);
} createClass(Flv, [{
key: "destroy",
return _this; value: function destroy() {
} console.log(this);
}
createClass(Flv, [{ }]);
key: "attachMediaElement",
value: function attachMediaElement(mediaElement) { return Flv;
errorHandle(mediaElement instanceof HTMLVideoElement && mediaElement.tagName === 'VIDEO', "The 'mediaElement' does not seem to be a HTMLVideoElement"); }(tinyEmitter);
this.mediaElement = mediaElement;
return this; window.Flv = Flv;
}
}, { function artplayerPluginFlv(art) {
key: "loadUrl", var flv = null;
value: function loadUrl(url) { art.on('destroy', function () {
var type = _typeof_1(url); if (flv) {
flv.destroy();
errorHandle(type === 'string', "The 'url' require 'string' type, but got '".concat(type, "'")); }
this.url = url; });
return this; return {
} flv: flv,
}, { init: function init(mediaElement, url) {
key: "start", flv = new Flv(mediaElement, url);
value: function start() { }
this.mediaSource = new CreatMediaSource(); };
console.log('start'); }
return this;
} window.artplayerPluginFlv = artplayerPluginFlv;
}]);
exports.default = artplayerPluginFlv;
return Flv;
}(tinyEmitter); Object.defineProperty(exports, '__esModule', { value: true });
window.Flv = Flv;
function artplayerPluginFlv(art) {
var $video = art.template.$video;
var flv = new Flv($video);
return {
load: function load(url) {
return new Promise(function (resolve) {
flv.loadUrl(url).start();
return resolve(flv.mediaSource.url);
});
}
};
}
window.artplayerPluginFlv = artplayerPluginFlv;
exports.default = artplayerPluginFlv;
Object.defineProperty(exports, '__esModule', { value: true });
}))); })));
//# sourceMappingURL=artplayer-plugin-flv.js.map //# sourceMappingURL=artplayer-plugin-flv.js.map
+1 -1
View File
@@ -1 +1 @@
{"version":3,"file":"artplayer-plugin-flv.js","sources":["../../node_modules/@babel/runtime/helpers/typeof.js","../../node_modules/@babel/runtime/helpers/classCallCheck.js","../../node_modules/@babel/runtime/helpers/createClass.js","../../node_modules/@babel/runtime/helpers/assertThisInitialized.js","../../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js","../../node_modules/@babel/runtime/helpers/getPrototypeOf.js","../../node_modules/@babel/runtime/helpers/setPrototypeOf.js","../../node_modules/@babel/runtime/helpers/inherits.js","../../packages/artplayer-plugin-flv/node_modules/tiny-emitter/index.js","../../node_modules/@babel/runtime/helpers/isNativeFunction.js","../../node_modules/@babel/runtime/helpers/construct.js","../../node_modules/@babel/runtime/helpers/wrapNativeSuper.js","../../packages/artplayer-plugin-flv/src/flv/utils.js","../../packages/artplayer-plugin-flv/src/flv/checkSupport.js","../../packages/artplayer-plugin-flv/src/flv/creatMediaSource.js","../../packages/artplayer-plugin-flv/src/flv/index.js","../../packages/artplayer-plugin-flv/src/index.js"],"sourcesContent":["function _typeof2(obj) { if (typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\") { _typeof2 = function _typeof2(obj) { return typeof obj; }; } else { _typeof2 = function _typeof2(obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; }; } return _typeof2(obj); }\n\nfunction _typeof(obj) {\n if (typeof Symbol === \"function\" && _typeof2(Symbol.iterator) === \"symbol\") {\n module.exports = _typeof = function _typeof(obj) {\n return _typeof2(obj);\n };\n } else {\n module.exports = _typeof = function _typeof(obj) {\n return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : _typeof2(obj);\n };\n }\n\n return _typeof(obj);\n}\n\nmodule.exports = _typeof;","function _classCallCheck(instance, Constructor) {\n if (!(instance instanceof Constructor)) {\n throw new TypeError(\"Cannot call a class as a function\");\n }\n}\n\nmodule.exports = _classCallCheck;","function _defineProperties(target, props) {\n for (var i = 0; i < props.length; i++) {\n var descriptor = props[i];\n descriptor.enumerable = descriptor.enumerable || false;\n descriptor.configurable = true;\n if (\"value\" in descriptor) descriptor.writable = true;\n Object.defineProperty(target, descriptor.key, descriptor);\n }\n}\n\nfunction _createClass(Constructor, protoProps, staticProps) {\n if (protoProps) _defineProperties(Constructor.prototype, protoProps);\n if (staticProps) _defineProperties(Constructor, staticProps);\n return Constructor;\n}\n\nmodule.exports = _createClass;","function _assertThisInitialized(self) {\n if (self === void 0) {\n throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\");\n }\n\n return self;\n}\n\nmodule.exports = _assertThisInitialized;","var _typeof = require(\"../helpers/typeof\");\n\nvar assertThisInitialized = require(\"./assertThisInitialized\");\n\nfunction _possibleConstructorReturn(self, call) {\n if (call && (_typeof(call) === \"object\" || typeof call === \"function\")) {\n return call;\n }\n\n return assertThisInitialized(self);\n}\n\nmodule.exports = _possibleConstructorReturn;","function _getPrototypeOf(o) {\n module.exports = _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {\n return o.__proto__ || Object.getPrototypeOf(o);\n };\n return _getPrototypeOf(o);\n}\n\nmodule.exports = _getPrototypeOf;","function _setPrototypeOf(o, p) {\n module.exports = _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {\n o.__proto__ = p;\n return o;\n };\n\n return _setPrototypeOf(o, p);\n}\n\nmodule.exports = _setPrototypeOf;","var setPrototypeOf = require(\"./setPrototypeOf\");\n\nfunction _inherits(subClass, superClass) {\n if (typeof superClass !== \"function\" && superClass !== null) {\n throw new TypeError(\"Super expression must either be null or a function\");\n }\n\n subClass.prototype = Object.create(superClass && superClass.prototype, {\n constructor: {\n value: subClass,\n writable: true,\n configurable: true\n }\n });\n if (superClass) setPrototypeOf(subClass, superClass);\n}\n\nmodule.exports = _inherits;","function E () {\n // Keep this empty so it's easier to inherit from\n // (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3)\n}\n\nE.prototype = {\n on: function (name, callback, ctx) {\n var e = this.e || (this.e = {});\n\n (e[name] || (e[name] = [])).push({\n fn: callback,\n ctx: ctx\n });\n\n return this;\n },\n\n once: function (name, callback, ctx) {\n var self = this;\n function listener () {\n self.off(name, listener);\n callback.apply(ctx, arguments);\nLine truncated {"version":3,"file":"artplayer-plugin-flv.js","sources":["../../node_modules/@babel/runtime/helpers/classCallCheck.js","../../node_modules/@babel/runtime/helpers/createClass.js","../../node_modules/@babel/runtime/helpers/typeof.js","../../node_modules/@babel/runtime/helpers/assertThisInitialized.js","../../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js","../../node_modules/@babel/runtime/helpers/getPrototypeOf.js","../../node_modules/@babel/runtime/helpers/setPrototypeOf.js","../../node_modules/@babel/runtime/helpers/inherits.js","../../packages/artplayer-plugin-flv/node_modules/tiny-emitter/index.js","../../node_modules/@babel/runtime/helpers/isNativeFunction.js","../../node_modules/@babel/runtime/helpers/construct.js","../../node_modules/@babel/runtime/helpers/wrapNativeSuper.js","../../packages/artplayer-plugin-flv/src/flv/utils.js","../../packages/artplayer-plugin-flv/src/flv/checkSupport.js","../../packages/artplayer-plugin-flv/src/flv/creatMediaSource.js","../../packages/artplayer-plugin-flv/src/flv/index.js","../../packages/artplayer-plugin-flv/src/index.js"],"sourcesContent":["function _classCallCheck(instance, Constructor) {\n if (!(instance instanceof Constructor)) {\n throw new TypeError(\"Cannot call a class as a function\");\n }\n}\n\nmodule.exports = _classCallCheck;","function _defineProperties(target, props) {\n for (var i = 0; i < props.length; i++) {\n var descriptor = props[i];\n descriptor.enumerable = descriptor.enumerable || false;\n descriptor.configurable = true;\n if (\"value\" in descriptor) descriptor.writable = true;\n Object.defineProperty(target, descriptor.key, descriptor);\n }\n}\n\nfunction _createClass(Constructor, protoProps, staticProps) {\n if (protoProps) _defineProperties(Constructor.prototype, protoProps);\n if (staticProps) _defineProperties(Constructor, staticProps);\n return Constructor;\n}\n\nmodule.exports = _createClass;","function _typeof2(obj) { if (typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\") { _typeof2 = function _typeof2(obj) { return typeof obj; }; } else { _typeof2 = function _typeof2(obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; }; } return _typeof2(obj); }\n\nfunction _typeof(obj) {\n if (typeof Symbol === \"function\" && _typeof2(Symbol.iterator) === \"symbol\") {\n module.exports = _typeof = function _typeof(obj) {\n return _typeof2(obj);\n };\n } else {\n module.exports = _typeof = function _typeof(obj) {\n return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : _typeof2(obj);\n };\n }\n\n return _typeof(obj);\n}\n\nmodule.exports = _typeof;","function _assertThisInitialized(self) {\n if (self === void 0) {\n throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\");\n }\n\n return self;\n}\n\nmodule.exports = _assertThisInitialized;","var _typeof = require(\"../helpers/typeof\");\n\nvar assertThisInitialized = require(\"./assertThisInitialized\");\n\nfunction _possibleConstructorReturn(self, call) {\n if (call && (_typeof(call) === \"object\" || typeof call === \"function\")) {\n return call;\n }\n\n return assertThisInitialized(self);\n}\n\nmodule.exports = _possibleConstructorReturn;","function _getPrototypeOf(o) {\n module.exports = _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {\n return o.__proto__ || Object.getPrototypeOf(o);\n };\n return _getPrototypeOf(o);\n}\n\nmodule.exports = _getPrototypeOf;","function _setPrototypeOf(o, p) {\n module.exports = _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {\n o.__proto__ = p;\n return o;\n };\n\n return _setPrototypeOf(o, p);\n}\n\nmodule.exports = _setPrototypeOf;","var setPrototypeOf = require(\"./setPrototypeOf\");\n\nfunction _inherits(subClass, superClass) {\n if (typeof superClass !== \"function\" && superClass !== null) {\n throw new TypeError(\"Super expression must either be null or a function\");\n }\n\n subClass.prototype = Object.create(superClass && superClass.prototype, {\n constructor: {\n value: subClass,\n writable: true,\n configurable: true\n }\n });\n if (superClass) setPrototypeOf(subClass, superClass);\n}\n\nmodule.exports = _inherits;","function E () {\n // Keep this empty so it's easier to inherit from\n // (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3)\n}\n\nE.prototype = {\n on: function (name, callback, ctx) {\n var e = this.e || (this.e = {});\n\n (e[name] || (e[name] = [])).push({\n fn: callback,\n ctx: ctx\n });\n\n return this;\n },\n\n once: function (name, callback, ctx) {\n var self = this;\n function listener () {\n self.off(name, listener);\n callback.apply(ctx, arguments);\nLine truncated
@@ -1,6 +1,7 @@
export default class CreatMediaSource { export default class CreatMediaSource {
constructor(art) { constructor(flv) {
this.mediaSource = new MediaSource(); this.mediaSource = new MediaSource();
this.url = URL.createObjectURL(this.mediaSource); this.url = URL.createObjectURL(this.mediaSource);
flv.mediaElement.src = this.url;
} }
} }
+4 -26
View File
@@ -1,40 +1,18 @@
import Emitter from 'tiny-emitter'; import Emitter from 'tiny-emitter';
import CheckSupport from './checkSupport'; import CheckSupport from './checkSupport';
import CreatMediaSource from './creatMediaSource'; import CreatMediaSource from './creatMediaSource';
import { errorHandle } from './utils';
class Flv extends Emitter { class Flv extends Emitter {
constructor(mediaElement, url) { constructor(mediaElement, url) {
super(); super();
this.support = new CheckSupport();
if (mediaElement) {
this.attachMediaElement(mediaElement);
}
if (url) {
this.loadUrl(url);
}
}
attachMediaElement(mediaElement) {
errorHandle(
mediaElement instanceof HTMLVideoElement && mediaElement.tagName === 'VIDEO',
"The 'mediaElement' does not seem to be a HTMLVideoElement",
);
this.mediaElement = mediaElement; this.mediaElement = mediaElement;
return this;
}
loadUrl(url) {
const type = typeof url;
errorHandle(type === 'string', `The 'url' require 'string' type, but got '${type}'`);
this.url = url; this.url = url;
return this; this.support = new CheckSupport(this);
this.mediaSource = new CreatMediaSource(this);
} }
start() { destroy() {
this.mediaSource = new CreatMediaSource(); console.log(this);
console.log('start');
return this;
} }
} }
+12 -9
View File
@@ -1,16 +1,19 @@
import Flv from './flv'; import Flv from './flv';
function artplayerPluginFlv(art) { function artplayerPluginFlv(art) {
const { let flv = null;
template: { $video },
} = art; art.on('destroy', () => {
const flv = new Flv($video); if (flv) {
flv.destroy();
}
});
return { return {
load: url => flv,
new Promise(resolve => { init: (mediaElement, url) => {
flv.loadUrl(url).start(); flv = new Flv(mediaElement, url);
return resolve(flv.mediaSource.url); },
}),
}; };
} }