From f8400002c2deaa2c3614af4d384029787002382a Mon Sep 17 00:00:00 2001 From: Harvey Zack Date: Fri, 14 Dec 2018 16:32:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E7=A6=BBflv=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=A4=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/uncompiled/artplayer-plugin-flv.js | 294 +++++++++++++++++- docs/uncompiled/artplayer-plugin-flv.js.map | 2 +- packages/artplayer-plugin-flv/package.json | 5 +- .../artplayer-plugin-flv/src/checkSupport.js | 18 -- .../src/flv/checkSupport.js | 17 + .../src/{ => flv}/creatMediaSource.js | 0 .../artplayer-plugin-flv/src/flv/index.js | 16 + .../artplayer-plugin-flv/src/flv/utils.js | 15 + packages/artplayer-plugin-flv/src/index.js | 26 +- 9 files changed, 339 insertions(+), 54 deletions(-) delete mode 100644 packages/artplayer-plugin-flv/src/checkSupport.js create mode 100644 packages/artplayer-plugin-flv/src/flv/checkSupport.js rename packages/artplayer-plugin-flv/src/{ => flv}/creatMediaSource.js (100%) create mode 100644 packages/artplayer-plugin-flv/src/flv/index.js create mode 100644 packages/artplayer-plugin-flv/src/flv/utils.js diff --git a/docs/uncompiled/artplayer-plugin-flv.js b/docs/uncompiled/artplayer-plugin-flv.js index 21e4a347b..19e3cd436 100644 --- a/docs/uncompiled/artplayer-plugin-flv.js +++ b/docs/uncompiled/artplayer-plugin-flv.js @@ -12,15 +12,263 @@ var classCallCheck = _classCallCheck; - function checkSupport(art) { - var _art$constructor = art.constructor, - errorHandle = _art$constructor.utils.errorHandle, - mimeCodec = _art$constructor.config.mimeCodec; - var $video = art.template.$video; - var canPlay = $video.canPlayType(mimeCodec.mp4); - errorHandle(window.MediaSource && window.MediaSource.isTypeSupported(mimeCodec.mp4) && (canPlay === 'probably' || canPlay === 'maybe'), "Unsupported MIME type or codec: ".concat(mimeCodec.mp4)); + function createCommonjsModule(fn, module) { + return module = { exports: {} }, fn(module, module.exports), module.exports; } + 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 _typeof(obj) { + if (typeof Symbol === "function" && _typeof2(Symbol.iterator) === "symbol") { + module.exports = _typeof = function _typeof(obj) { + return _typeof2(obj); + }; + } else { + module.exports = _typeof = function _typeof(obj) { + return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : _typeof2(obj); + }; + } + + return _typeof(obj); + } + + module.exports = _typeof; + }); + + function _assertThisInitialized(self) { + if (self === void 0) { + throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + } + + return self; + } + + var assertThisInitialized = _assertThisInitialized; + + function _possibleConstructorReturn(self, call) { + if (call && (_typeof_1(call) === "object" || typeof call === "function")) { + return call; + } + + return assertThisInitialized(self); + } + + var possibleConstructorReturn = _possibleConstructorReturn; + + var getPrototypeOf = createCommonjsModule(function (module) { + function _getPrototypeOf(o) { + module.exports = _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { + return o.__proto__ || Object.getPrototypeOf(o); + }; + return _getPrototypeOf(o); + } + + module.exports = _getPrototypeOf; + }); + + var setPrototypeOf = createCommonjsModule(function (module) { + function _setPrototypeOf(o, p) { + module.exports = _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { + o.__proto__ = p; + return o; + }; + + return _setPrototypeOf(o, p); + } + + module.exports = _setPrototypeOf; + }); + + function _inherits(subClass, superClass) { + if (typeof superClass !== "function" && superClass !== null) { + throw new TypeError("Super expression must either be null or a function"); + } + + subClass.prototype = Object.create(superClass && superClass.prototype, { + constructor: { + value: subClass, + writable: true, + configurable: true + } + }); + if (superClass) setPrototypeOf(subClass, superClass); + } + + var inherits = _inherits; + + 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) + } + + E.prototype = { + on: function on(name, callback, ctx) { + var e = this.e || (this.e = {}); + (e[name] || (e[name] = [])).push({ + fn: callback, + ctx: ctx + }); + return this; + }, + once: function once(name, callback, ctx) { + var self = this; + + function listener() { + self.off(name, listener); + callback.apply(ctx, arguments); + } + listener._ = callback; + return this.on(name, listener, ctx); + }, + emit: function emit(name) { + var data = [].slice.call(arguments, 1); + var evtArr = ((this.e || (this.e = {}))[name] || []).slice(); + var i = 0; + var len = evtArr.length; + + for (i; i < len; i++) { + evtArr[i].fn.apply(evtArr[i].ctx, data); + } + + return this; + }, + off: function off(name, callback) { + var e = this.e || (this.e = {}); + var evts = e[name]; + var liveEvents = []; + + if (evts && callback) { + for (var i = 0, len = evts.length; i < len; i++) { + if (evts[i].fn !== callback && evts[i].fn._ !== callback) liveEvents.push(evts[i]); + } + } // Remove event from queue to prevent memory leak + // Suggested by https://github.com/lazd + // Ref: https://github.com/scottcorgan/tiny-emitter/commit/c6ebfaa9bc973b33d110a84a307742b7cf94c953#commitcomment-5024910 + + + liveEvents.length ? e[name] = liveEvents : delete e[name]; + return this; + } + }; + var tinyEmitter = E; + + function _isNativeFunction(fn) { + return Function.toString.call(fn).indexOf("[native code]") !== -1; + } + + var isNativeFunction = _isNativeFunction; + + var construct = createCommonjsModule(function (module) { + function isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + + try { + Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); + return true; + } catch (e) { + return false; + } + } + + function _construct(Parent, args, Class) { + if (isNativeReflectConstruct()) { + module.exports = _construct = Reflect.construct; + } else { + module.exports = _construct = function _construct(Parent, args, Class) { + var a = [null]; + a.push.apply(a, args); + var Constructor = Function.bind.apply(Parent, a); + var instance = new Constructor(); + if (Class) setPrototypeOf(instance, Class.prototype); + return instance; + }; + } + + return _construct.apply(null, arguments); + } + + module.exports = _construct; + }); + + var wrapNativeSuper = createCommonjsModule(function (module) { + function _wrapNativeSuper(Class) { + var _cache = typeof Map === "function" ? new Map() : undefined; + + module.exports = _wrapNativeSuper = function _wrapNativeSuper(Class) { + if (Class === null || !isNativeFunction(Class)) return Class; + + if (typeof Class !== "function") { + throw new TypeError("Super expression must either be null or a function"); + } + + if (typeof _cache !== "undefined") { + if (_cache.has(Class)) return _cache.get(Class); + + _cache.set(Class, Wrapper); + } + + function Wrapper() { + return construct(Class, arguments, getPrototypeOf(this).constructor); + } + + Wrapper.prototype = Object.create(Class.prototype, { + constructor: { + value: Wrapper, + enumerable: false, + writable: true, + configurable: true + } + }); + return setPrototypeOf(Wrapper, Class); + }; + + return _wrapNativeSuper(Class); + } + + module.exports = _wrapNativeSuper; + }); + + var FlvError = + /*#__PURE__*/ + function (_Error) { + inherits(FlvError, _Error); + + function FlvError(message, context) { + var _this; + + classCallCheck(this, FlvError); + + _this = possibleConstructorReturn(this, getPrototypeOf(FlvError).call(this, message)); + + if (typeof Error.captureStackTrace === 'function') { + Error.captureStackTrace(assertThisInitialized(assertThisInitialized(_this)), context || _this.constructor); + } + + _this.name = 'FlvError'; + return _this; + } + + return FlvError; + }(wrapNativeSuper(Error)); + function errorHandle(condition, msg) { + if (!condition) { + throw new FlvError(msg); + } + } + + var CheckSupport = function CheckSupport() { + classCallCheck(this, CheckSupport); + + var MP4H264MimeCodec = 'video/mp4; codecs="avc1.42001E, mp4a.40.2"'; + var videoElement = window.document.createElement('video'); + var canPlay = videoElement.canPlayType(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.fetch === 'function', "Unsupported 'fetch' method"); + }; + var CreatMediaSource = function CreatMediaSource(art) { classCallCheck(this, CreatMediaSource); @@ -28,23 +276,35 @@ this.url = URL.createObjectURL(this.mediaSource); }; - var Flv = function Flv(art) { - classCallCheck(this, Flv); + var Flv = + /*#__PURE__*/ + function (_Emitter) { + inherits(Flv, _Emitter); - checkSupport(art); - this.mediaSource = new CreatMediaSource(art); + function Flv(mediaElement, url) { + var _this; - this.load = function (url) { - console.log(url); - }; - }; + classCallCheck(this, Flv); + + _this = possibleConstructorReturn(this, getPrototypeOf(Flv).call(this)); + _this.mediaElement = mediaElement; + _this.url = url; + _this.support = new CheckSupport(); + _this.mediaSource = new CreatMediaSource(); + return _this; + } + + return Flv; + }(tinyEmitter); + + window.Flv = Flv; function artplayerPluginFlv(art) { - var flv = new Flv(art); + var $video = art.template.$video; return { load: function load(url) { return new Promise(function (resolve) { - flv.load(url); + var flv = new Flv($video, url); return resolve(flv.mediaSource.url); }); } diff --git a/docs/uncompiled/artplayer-plugin-flv.js.map b/docs/uncompiled/artplayer-plugin-flv.js.map index b02a3dcfc..a0a9535d8 100644 --- a/docs/uncompiled/artplayer-plugin-flv.js.map +++ b/docs/uncompiled/artplayer-plugin-flv.js.map @@ -1 +1 @@ -{"version":3,"file":"artplayer-plugin-flv.js","sources":["../../node_modules/@babel/runtime/helpers/classCallCheck.js","../../packages/artplayer-plugin-flv/src/checkSupport.js","../../packages/artplayer-plugin-flv/src/creatMediaSource.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;","export default function checkSupport(art) {\n const {\n utils: { errorHandle },\n config: { mimeCodec },\n } = art.constructor;\n\n const {\n template: { $video },\n } = art;\n\n const canPlay = $video.canPlayType(mimeCodec.mp4);\n errorHandle(\n window.MediaSource &&\n window.MediaSource.isTypeSupported(mimeCodec.mp4) &&\n (canPlay === 'probably' || canPlay === 'maybe'),\n `Unsupported MIME type or codec: ${mimeCodec.mp4}`,\n );\n}\n","export default class CreatMediaSource {\n constructor(art) {\n this.mediaSource = new MediaSource();\n this.url = URL.createObjectURL(this.mediaSource);\n }\n}","import checkSupport from './checkSupport';\nimport CreatMediaSource from './creatMediaSource';\n\nclass Flv {\n constructor(art) {\n checkSupport(art);\n this.mediaSource = new CreatMediaSource(art);\n this.load = url => {\n console.log(url);\n };\n }\n}\n\nfunction artplayerPluginFlv(art) {\n const flv = new Flv(art);\n return {\n load: url => new Promise(resolve => {\n flv.load(url);\n return resolve(flv.mediaSource.url);\n }),\n };\n}\n\nwindow.artplayerPluginFlv = artplayerPluginFlv;\nexport default artplayerPluginFlv;\n"],"names":["checkSupport","art","constructor","errorHandle","utils","mimeCodec","config","$video","template","canPlay","canPlayType","mp4","window","MediaSource","isTypeSupported","CreatMediaSource","mediaSource","url","URL","createObjectURL","Flv","load","console","log","artplayerPluginFlv","flv","Promise","resolve"],"mappings":";;;;;;EAAA,SAAS,eAAe,CAAC,QAAQ,EAAE,WAAW,EAAE;IAC9C,IAAI,EAAE,QAAQ,YAAY,WAAW,CAAC,EAAE;MACtC,MAAM,IAAI,SAAS,CAAC,mCAAmC,CAAC,CAAC;KAC1D;GACF;;EAED,kBAAc,GAAG,eAAe;;ECNjB,SAASA,YAAT,CAAsBC,GAAtB,EAA2B;EAAA,yBAIlCA,GAAG,CAACC,WAJ8B;EAAA,MAEzBC,WAFyB,oBAElCC,KAFkC,CAEzBD,WAFyB;EAAA,MAGxBE,SAHwB,oBAGlCC,MAHkC,CAGxBD,SAHwB;EAAA,MAOtBE,MAPsB,GAQlCN,GARkC,CAOlCO,QAPkC,CAOtBD,MAPsB;EAUtC,MAAME,OAAO,GAAGF,MAAM,CAACG,WAAP,CAAmBL,SAAS,CAACM,GAA7B,CAAhB;EACAR,EAAAA,WAAW,CACPS,MAAM,CAACC,WAAP,IACID,MAAM,CAACC,WAAP,CAAmBC,eAAnB,CAAmCT,SAAS,CAACM,GAA7C,CADJ,KAEKF,OAAO,KAAK,UAAZ,IAA0BA,OAAO,KAAK,OAF3C,CADO,4CAI4BJ,SAAS,CAACM,GAJtC,EAAX;EAMH;;MCjBoBI,mBACjB,0BAAYd,GAAZ,EAAiB;EAAA;;EACb,OAAKe,WAAL,GAAmB,IAAIH,WAAJ,EAAnB;EACA,OAAKI,GAAL,GAAWC,GAAG,CAACC,eAAJ,CAAoB,KAAKH,WAAzB,CAAX;EACH;;MCDCI,MACF,aAAYnB,GAAZ,EAAiB;EAAA;;EACbD,EAAAA,YAAY,CAACC,GAAD,CAAZ;EACA,OAAKe,WAAL,GAAmB,IAAID,gBAAJ,CAAqBd,GAArB,CAAnB;;EACA,OAAKoB,IAAL,GAAY,UAAAJ,GAAG,EAAI;EACfK,IAAAA,OAAO,CAACC,GAAR,CAAYN,GAAZ;EACH,GAFD;EAGH;;EAGL,SAASO,kBAAT,CAA4BvB,GAA5B,EAAiC;EAC7B,MAAMwB,GAAG,GAAG,IAAIL,GAAJ,CAAQnB,GAAR,CAAZ;EACA,SAAO;EACHoB,IAAAA,IAAI,EAAE,cAAAJ,GAAG;EAAA,aAAI,IAAIS,OAAJ,CAAY,UAAAC,OAAO,EAAI;EAChCF,QAAAA,GAAG,CAACJ,IAAJ,CAASJ,GAAT;EACA,eAAOU,OAAO,CAACF,GAAG,CAACT,WAAJ,CAAgBC,GAAjB,CAAd;EACH,OAHY,CAAJ;EAAA;EADN,GAAP;EAMH;;EAEDL,MAAM,CAACY,kBAAP,GAA4BA,kBAA5B;;;;;;;;;;;;"} \ No newline at end of file +{"version":3,"file":"artplayer-plugin-flv.js","sources":["../../node_modules/@babel/runtime/helpers/classCallCheck.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 _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);\n };\n\n listener._ = callback\n return this.on(name, listener, ctx);\n },\n\n emit: function (name) {\n var data = [].slice.call(arguments, 1);\n var evtArr = ((this.e || (this.e = {}))[name] || []).slice();\n var i = 0;\n var len = evtArr.length;\n\n for (i; i < len; i++) {\n evtArr[i].fn.apply(evtArr[i].ctx, data);\n }\n\n return this;\n },\n\n off: function (name, callback) {\n var e = this.e || (this.e = {});\n var evts = e[name];\n var liveEvents = [];\n\n if (evts && callback) {\n for (var i = 0, len = evts.length; i < len; i++) {\n if (evts[i].fn !== callback && evts[i].fn._ !== callback)\n liveEvents.push(evts[i]);\n }\n }\n\n // Remove event from queue to prevent memory leak\n // Suggested by https://github.com/lazd\n // Ref: https://github.com/scottcorgan/tiny-emitter/commit/c6ebfaa9bc973b33d110a84a307742b7cf94c953#commitcomment-5024910\n\n (liveEvents.length)\n ? e[name] = liveEvents\n : delete e[name];\n\n return this;\n }\n};\n\nmodule.exports = E;\n","function _isNativeFunction(fn) {\n return Function.toString.call(fn).indexOf(\"[native code]\") !== -1;\n}\n\nmodule.exports = _isNativeFunction;","var setPrototypeOf = require(\"./setPrototypeOf\");\n\nfunction isNativeReflectConstruct() {\n if (typeof Reflect === \"undefined\" || !Reflect.construct) return false;\n if (Reflect.construct.sham) return false;\n if (typeof Proxy === \"function\") return true;\n\n try {\n Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));\n return true;\n } catch (e) {\n return false;\n }\n}\n\nfunction _construct(Parent, args, Class) {\n if (isNativeReflectConstruct()) {\n module.exports = _construct = Reflect.construct;\n } else {\n module.exports = _construct = function _construct(Parent, args, Class) {\n var a = [null];\n a.push.apply(a, args);\n var Constructor = Function.bind.apply(Parent, a);\n var instance = new Constructor();\n if (Class) setPrototypeOf(instance, Class.prototype);\n return instance;\n };\n }\n\n return _construct.apply(null, arguments);\n}\n\nmodule.exports = _construct;","var getPrototypeOf = require(\"./getPrototypeOf\");\n\nvar setPrototypeOf = require(\"./setPrototypeOf\");\n\nvar isNativeFunction = require(\"./isNativeFunction\");\n\nvar construct = require(\"./construct\");\n\nfunction _wrapNativeSuper(Class) {\n var _cache = typeof Map === \"function\" ? new Map() : undefined;\n\n module.exports = _wrapNativeSuper = function _wrapNativeSuper(Class) {\n if (Class === null || !isNativeFunction(Class)) return Class;\n\n if (typeof Class !== \"function\") {\n throw new TypeError(\"Super expression must either be null or a function\");\n }\n\n if (typeof _cache !== \"undefined\") {\n if (_cache.has(Class)) return _cache.get(Class);\n\n _cache.set(Class, Wrapper);\n }\n\n function Wrapper() {\n return construct(Class, arguments, getPrototypeOf(this).constructor);\n }\n\n Wrapper.prototype = Object.create(Class.prototype, {\n constructor: {\n value: Wrapper,\n enumerable: false,\n writable: true,\n configurable: true\n }\n });\n return setPrototypeOf(Wrapper, Class);\n };\n\n return _wrapNativeSuper(Class);\n}\n\nmodule.exports = _wrapNativeSuper;","export class FlvError extends Error {\n constructor(message, context) {\n super(message);\n if (typeof Error.captureStackTrace === 'function') {\n Error.captureStackTrace(this, context || this.constructor);\n }\n this.name = 'FlvError';\n }\n}\n\nexport function errorHandle(condition, msg) {\n if (!condition) {\n throw new FlvError(msg);\n }\n}","import { errorHandle } from './utils';\n\nexport default class CheckSupport {\n constructor() {\n const MP4H264MimeCodec = 'video/mp4; codecs=\"avc1.42001E, mp4a.40.2\"';\n const videoElement = window.document.createElement('video');\n const canPlay = videoElement.canPlayType(MP4H264MimeCodec);\n errorHandle(\n window.MediaSource &&\n window.MediaSource.isTypeSupported(MP4H264MimeCodec) &&\n (canPlay === 'probably' || canPlay === 'maybe'),\n `Unsupported MIME type or codec: ${MP4H264MimeCodec}`,\n );\n errorHandle(typeof window.Promise === 'function', \"Unsupported 'Promise' method\");\n errorHandle(typeof window.fetch === 'function', \"Unsupported 'fetch' method\");\n }\n}\n","export default class CreatMediaSource {\n constructor(art) {\n this.mediaSource = new MediaSource();\n this.url = URL.createObjectURL(this.mediaSource);\n }\n}","import Emitter from 'tiny-emitter';\nimport CheckSupport from './checkSupport';\nimport CreatMediaSource from './creatMediaSource';\n\nclass Flv extends Emitter {\n constructor(mediaElement, url) {\n super();\n this.mediaElement = mediaElement;\n this.url = url;\n this.support = new CheckSupport();\n this.mediaSource = new CreatMediaSource();\n }\n}\n\nwindow.Flv = Flv;\nexport default Flv;","import Flv from './flv';\n\nfunction artplayerPluginFlv(art) {\n const {\n template: { $video },\n } = art;\n return {\n load: url =>\n new Promise(resolve => {\n const flv = new Flv($video, url);\n return resolve(flv.mediaSource.url);\n }),\n };\n}\n\nwindow.artplayerPluginFlv = artplayerPluginFlv;\nexport default artplayerPluginFlv;\n"],"names":["_typeof","E","prototype","on","name","callback","ctx","e","push","fn","once","self","listener","off","apply","arguments","_","emit","data","slice","call","evtArr","i","len","length","evts","liveEvents","FlvError","message","context","Error","captureStackTrace","constructor","errorHandle","condition","msg","CheckSupport","MP4H264MimeCodec","videoElement","window","document","createElement","canPlay","canPlayType","MediaSource","isTypeSupported","Promise","fetch","CreatMediaSource","art","mediaSource","url","URL","createObjectURL","Flv","mediaElement","support","Emitter","artplayerPluginFlv","$video","template","load","resolve","flv"],"mappings":";;;;;;EAAA,SAAS,eAAe,CAAC,QAAQ,EAAE,WAAW,EAAE;IAC9C,IAAI,EAAE,QAAQ,YAAY,WAAW,CAAC,EAAE;MACtC,MAAM,IAAI,SAAS,CAAC,mCAAmC,CAAC,CAAC;KAC1D;GACF;;EAED,kBAAc,GAAG,eAAe;;;;;;;ECNhC,SAAS,QAAQ,CAAC,GAAG,EAAE,EAAE,IAAI,OAAO,MAAM,KAAK,UAAU,IAAI,OAAO,MAAM,CAAC,QAAQ,KAAK,QAAQ,EAAE,EAAE,QAAQ,GAAG,SAAS,QAAQ,CAAC,GAAG,EAAE,EAAE,OAAO,OAAO,GAAG,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,QAAQ,GAAG,SAAS,QAAQ,CAAC,GAAG,EAAE,EAAE,OAAO,GAAG,IAAI,OAAO,MAAM,KAAK,UAAU,IAAI,GAAG,CAAC,WAAW,KAAK,MAAM,IAAI,GAAG,KAAK,MAAM,CAAC,SAAS,GAAG,QAAQ,GAAG,OAAO,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE;;EAErW,SAAS,OAAO,CAAC,GAAG,EAAE;IACpB,IAAI,OAAO,MAAM,KAAK,UAAU,IAAI,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,QAAQ,EAAE;MAC1E,cAAc,GAAG,OAAO,GAAG,SAAS,OAAO,CAAC,GAAG,EAAE;QAC/C,OAAO,QAAQ,CAAC,GAA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;;;;;;;;;"} \ No newline at end of file diff --git a/packages/artplayer-plugin-flv/package.json b/packages/artplayer-plugin-flv/package.json index 251e6eeda..a7640bbfb 100644 --- a/packages/artplayer-plugin-flv/package.json +++ b/packages/artplayer-plugin-flv/package.json @@ -19,5 +19,8 @@ "bugs": { "url": "https://github.com/zhw2590582/ArtPlayer/issues" }, - "homepage": "https://github.com/zhw2590582/ArtPlayer#readme" + "homepage": "https://github.com/zhw2590582/ArtPlayer#readme", + "dependencies": { + "tiny-emitter": "^2.0.2" + } } diff --git a/packages/artplayer-plugin-flv/src/checkSupport.js b/packages/artplayer-plugin-flv/src/checkSupport.js deleted file mode 100644 index fd711ac2e..000000000 --- a/packages/artplayer-plugin-flv/src/checkSupport.js +++ /dev/null @@ -1,18 +0,0 @@ -export default function checkSupport(art) { - const { - utils: { errorHandle }, - config: { mimeCodec }, - } = art.constructor; - - const { - template: { $video }, - } = art; - - const canPlay = $video.canPlayType(mimeCodec.mp4); - errorHandle( - window.MediaSource && - window.MediaSource.isTypeSupported(mimeCodec.mp4) && - (canPlay === 'probably' || canPlay === 'maybe'), - `Unsupported MIME type or codec: ${mimeCodec.mp4}`, - ); -} diff --git a/packages/artplayer-plugin-flv/src/flv/checkSupport.js b/packages/artplayer-plugin-flv/src/flv/checkSupport.js new file mode 100644 index 000000000..0a1189e26 --- /dev/null +++ b/packages/artplayer-plugin-flv/src/flv/checkSupport.js @@ -0,0 +1,17 @@ +import { errorHandle } from './utils'; + +export default class CheckSupport { + constructor() { + const MP4H264MimeCodec = 'video/mp4; codecs="avc1.42001E, mp4a.40.2"'; + const videoElement = window.document.createElement('video'); + const canPlay = videoElement.canPlayType(MP4H264MimeCodec); + errorHandle( + window.MediaSource && + window.MediaSource.isTypeSupported(MP4H264MimeCodec) && + (canPlay === 'probably' || canPlay === 'maybe'), + `Unsupported MIME type or codec: ${MP4H264MimeCodec}`, + ); + errorHandle(typeof window.Promise === 'function', "Unsupported 'Promise' method"); + errorHandle(typeof window.fetch === 'function', "Unsupported 'fetch' method"); + } +} diff --git a/packages/artplayer-plugin-flv/src/creatMediaSource.js b/packages/artplayer-plugin-flv/src/flv/creatMediaSource.js similarity index 100% rename from packages/artplayer-plugin-flv/src/creatMediaSource.js rename to packages/artplayer-plugin-flv/src/flv/creatMediaSource.js diff --git a/packages/artplayer-plugin-flv/src/flv/index.js b/packages/artplayer-plugin-flv/src/flv/index.js new file mode 100644 index 000000000..50916db70 --- /dev/null +++ b/packages/artplayer-plugin-flv/src/flv/index.js @@ -0,0 +1,16 @@ +import Emitter from 'tiny-emitter'; +import CheckSupport from './checkSupport'; +import CreatMediaSource from './creatMediaSource'; + +class Flv extends Emitter { + constructor(mediaElement, url) { + super(); + this.mediaElement = mediaElement; + this.url = url; + this.support = new CheckSupport(); + this.mediaSource = new CreatMediaSource(); + } +} + +window.Flv = Flv; +export default Flv; \ No newline at end of file diff --git a/packages/artplayer-plugin-flv/src/flv/utils.js b/packages/artplayer-plugin-flv/src/flv/utils.js new file mode 100644 index 000000000..d7a372e91 --- /dev/null +++ b/packages/artplayer-plugin-flv/src/flv/utils.js @@ -0,0 +1,15 @@ +export class FlvError extends Error { + constructor(message, context) { + super(message); + if (typeof Error.captureStackTrace === 'function') { + Error.captureStackTrace(this, context || this.constructor); + } + this.name = 'FlvError'; + } +} + +export function errorHandle(condition, msg) { + if (!condition) { + throw new FlvError(msg); + } +} \ No newline at end of file diff --git a/packages/artplayer-plugin-flv/src/index.js b/packages/artplayer-plugin-flv/src/index.js index 9c9f56826..b68135665 100644 --- a/packages/artplayer-plugin-flv/src/index.js +++ b/packages/artplayer-plugin-flv/src/index.js @@ -1,23 +1,15 @@ -import checkSupport from './checkSupport'; -import CreatMediaSource from './creatMediaSource'; - -class Flv { - constructor(art) { - checkSupport(art); - this.mediaSource = new CreatMediaSource(art); - this.load = url => { - console.log(url); - }; - } -} +import Flv from './flv'; function artplayerPluginFlv(art) { - const flv = new Flv(art); + const { + template: { $video }, + } = art; return { - load: url => new Promise(resolve => { - flv.load(url); - return resolve(flv.mediaSource.url); - }), + load: url => + new Promise(resolve => { + const flv = new Flv($video, url); + return resolve(flv.mediaSource.url); + }), }; }