change event bind

This commit is contained in:
Harvey Zack committed 2018-10-15 09:02:18 +08:00
1 parent a79a3cef87
commit e4518d21ce
4 files changed
+31 -66

No files matched your search

+15 -35
View File
@@ -388,7 +388,6 @@
classCallCheck(this, Player);
this.art = art;
this.eventFn = this.eventFn.bind(this);
this.init();
this.eventBind();
}
@@ -413,14 +412,11 @@
var $video = this.art.refs.$video;
var events = mediaElement.events;
events.forEach(function (eventName) {
proxy($video, eventName, _this.eventFn);
proxy($video, eventName, function (event) {
_this.art.emit("video:".concat(event.type), event);
});
});
}
}, {
key: "eventFn",
value: function eventFn(event) {
this.art.emit("video:".concat(event.type), event);
}
}]);
return Player;
@@ -457,10 +453,6 @@
this.art = art;
this.setMimeCodec();
this.mediaSourceEventFn = this.mediaSourceEventFn.bind(this);
this.sourceBufferEventFn = this.sourceBufferEventFn.bind(this);
this.sourceBuffersEventFn = this.sourceBuffersEventFn.bind(this);
this.activeSourceBuffersEventFn = this.activeSourceBuffersEventFn.bind(this);
this.init();
this.eventBind();
this.eventStart();
@@ -505,11 +497,17 @@
var instance = mseConfig.instance,
sourceBufferList = mseConfig.sourceBufferList;
instance.events.forEach(function (eventName) {
proxy(_this.mediaSource, eventName, _this.mediaSourceEventFn);
proxy(_this.mediaSource, eventName, function (event) {
_this.art.emit("mediaSource:".concat(event.type), event);
});
});
sourceBufferList.events.forEach(function (eventName) {
proxy(_this.mediaSource.sourceBuffers, eventName, _this.sourceBuffersEventFn);
proxy(_this.mediaSource.activeSourceBuffers, eventName, _this.activeSourceBuffersEventFn);
proxy(_this.mediaSource.sourceBuffers, eventName, function (event) {
_this.art.emit("sourceBuffers:".concat(event.type), event);
});
proxy(_this.mediaSource.activeSourceBuffers, eventName, function (event) {
_this.art.emit("activeSourceBuffers:".concat(event.type), event);
});
});
}
}, {
@@ -523,7 +521,9 @@
this.art.on('mediaSource:sourceopen', function () {
_this2.sourceBuffer = _this2.mediaSource.addSourceBuffer(option.mimeCodec);
sourceBuffer.events.forEach(function (eventName) {
proxy(_this2.sourceBuffer, eventName, _this2.sourceBufferEventFn);
proxy(_this2.sourceBuffer, eventName, function (event) {
_this2.art.emit("sourceBuffer:".concat(event.type), event);
});
});
});
this.art.on('sourceBuffer:updateend', function () {
@@ -533,26 +533,6 @@
_this2.sourceBuffer.appendBuffer(response);
});
}
}, {
key: "mediaSourceEventFn",
value: function mediaSourceEventFn(event) {
this.art.emit("mediaSource:".concat(event.type), event);
}
}, {
key: "sourceBufferEventFn",
value: function sourceBufferEventFn(event) {
this.art.emit("sourceBuffer:".concat(event.type), event);
}
}, {
key: "sourceBuffersEventFn",
value: function sourceBuffersEventFn(event) {
this.art.emit("sourceBuffers:".concat(event.type), event);
}
}, {
key: "activeSourceBuffersEventFn",
value: function activeSourceBuffersEventFn(event) {
this.art.emit("activeSourceBuffers:".concat(event.type), event);
}
}]);
return Mse;
+1 -1
View File
@@ -1 +1 @@
{"version":3,"file":"artplayer.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","../../node_modules/@babel/runtime/helpers/isNativeFunction.js","../../node_modules/@babel/runtime/helpers/construct.js","../../node_modules/@babel/runtime/helpers/wrapNativeSuper.js","../../src/utils/ArtPlayerError.js","../../src/utils/index.js","../../src/utils/verification.js","../../node_modules/tiny-emitter/index.js","../../src/template.js","../../src/i18n/zh-CN.js","../../src/i18n/zh-TW.js","../../src/i18n/en.js","../../src/i18n/jp.js","../../src/i18n/index.js","../../src/utils/mediaElement.js","../../src/player.js","../../src/utils/mimeCodeces.js","../../src/utils/mseConfig.js","../../src/mse.js","../../src/controls/index.js","../../src/contextmenu.js","../../src/danmaku.js","../../src/info.js","../../src/subtitle.js","../../src/events.js","../../src/hotkey.js","../../src/layers.js","../../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 _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\" |Line truncated
{"version":3,"file":"artplayer.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","../../node_modules/@babel/runtime/helpers/isNativeFunction.js","../../node_modules/@babel/runtime/helpers/construct.js","../../node_modules/@babel/runtime/helpers/wrapNativeSuper.js","../../src/utils/ArtPlayerError.js","../../src/utils/index.js","../../src/utils/verification.js","../../node_modules/tiny-emitter/index.js","../../src/template.js","../../src/i18n/zh-CN.js","../../src/i18n/zh-TW.js","../../src/i18n/en.js","../../src/i18n/jp.js","../../src/i18n/index.js","../../src/utils/mediaElement.js","../../src/player.js","../../src/utils/mimeCodeces.js","../../src/utils/mseConfig.js","../../src/mse.js","../../src/controls/index.js","../../src/contextmenu.js","../../src/danmaku.js","../../src/info.js","../../src/subtitle.js","../../src/events.js","../../src/hotkey.js","../../src/layers.js","../../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 _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\" |Line truncated
+12 -24
View File
@@ -6,10 +6,6 @@ export default class Mse {
constructor(art) {
this.art = art;
this.setMimeCodec();
this.mediaSourceEventFn = this.mediaSourceEventFn.bind(this);
this.sourceBufferEventFn = this.sourceBufferEventFn.bind(this);
this.sourceBuffersEventFn = this.sourceBuffersEventFn.bind(this);
this.activeSourceBuffersEventFn = this.activeSourceBuffersEventFn.bind(this);
this.init();
this.eventBind();
this.eventStart();
@@ -57,12 +53,18 @@ export default class Mse {
const { instance, sourceBufferList } = mseConfig;
instance.events.forEach(eventName => {
proxy(this.mediaSource, eventName, this.mediaSourceEventFn);
proxy(this.mediaSource, eventName, event => {
this.art.emit(`mediaSource:${event.type}`, event);
});
});
sourceBufferList.events.forEach(eventName => {
proxy(this.mediaSource.sourceBuffers, eventName, this.sourceBuffersEventFn);
proxy(this.mediaSource.activeSourceBuffers, eventName, this.activeSourceBuffersEventFn);
proxy(this.mediaSource.sourceBuffers, eventName, event => {
this.art.emit(`sourceBuffers:${event.type}`, event);
});
proxy(this.mediaSource.activeSourceBuffers, eventName, event => {
this.art.emit(`activeSourceBuffers:${event.type}`, event);
});
});
}
@@ -74,7 +76,9 @@ export default class Mse {
this.art.on('mediaSource:sourceopen', () => {
this.sourceBuffer = this.mediaSource.addSourceBuffer(option.mimeCodec);
sourceBuffer.events.forEach(eventName => {
proxy(this.sourceBuffer, eventName, this.sourceBufferEventFn);
proxy(this.sourceBuffer, eventName, event => {
this.art.emit(`sourceBuffer:${event.type}`, event);
});
});
});
@@ -86,20 +90,4 @@ export default class Mse {
this.sourceBuffer.appendBuffer(response);
});
}
mediaSourceEventFn(event) {
this.art.emit(`mediaSource:${event.type}`, event);
}
sourceBufferEventFn(event) {
this.art.emit(`sourceBuffer:${event.type}`, event);
}
sourceBuffersEventFn(event) {
this.art.emit(`sourceBuffers:${event.type}`, event);
}
activeSourceBuffersEventFn(event) {
this.art.emit(`activeSourceBuffers:${event.type}`, event);
}
}
+3 -6
View File
@@ -4,7 +4,6 @@ import mediaElement from './utils/mediaElement';
export default class Player {
constructor(art) {
this.art = art;
this.eventFn = this.eventFn.bind(this);
this.init();
this.eventBind();
}
@@ -24,11 +23,9 @@ export default class Player {
const { $video } = this.art.refs;
const { events } = mediaElement;
events.forEach(eventName => {
proxy($video, eventName, this.eventFn);
proxy($video, eventName, event => {
this.art.emit(`video:${event.type}`, event);
});
});
}
eventFn(event) {
this.art.emit(`video:${event.type}`, event);
}
}