add scheme

This commit is contained in:
Harvey Zack committed 2018-10-26 10:29:27 +08:00
1 parent 4da0ac7650
commit 5d48d3a437
8 files changed
+332 -160

No files matched your search

+8 -8
View File
@@ -30,7 +30,7 @@
url: './video/one-more-time-one-more-chance.mp4',
poster: './img/one-more-time-one-more-chance.jpg',
subtitle: {
url: './subtitle/one-more-time-one-more-chance.srt'
url: './subtitle/one-more-time-one-more-chance.srt',
},
thumbnails: {
url: './img/thumbnails.png',
@@ -81,15 +81,15 @@
});
});
console.dir(Artplayer);
// console.dir(Artplayer);
console.log(player);
// console.log(player);
Artplayer.config.video.events.forEach(item => {
player.on('video:' + item, event => {
console.log('video', event);
});
});
// Artplayer.config.video.events.forEach(item => {
// player.on('video:' + item, event => {
// console.log('video', event);
// });
// });
</script>
</body>
+156 -59
View File
@@ -391,68 +391,166 @@
});
}
function validOption(DEFAULTS, option) {
var scheme = {
container: {
type: 'string',
required: true
},
url: {
type: 'string',
required: true
},
poster: {
type: 'string'
},
volume: {
type: 'number'
},
thumbnails: {
type: 'object',
child: {
url: {
type: 'string'
},
number: {
type: 'number'
},
width: {
type: 'number'
},
height: {
type: 'number'
},
column: {
type: 'number'
}
}
},
autoplay: {
type: 'boolean'
},
loop: {
type: 'boolean'
},
type: {
type: 'string'
},
mimeCodec: {
type: 'string'
},
layers: {
type: 'array',
child: {
name: {
type: 'string'
},
index: {
type: 'number'
},
html: {
type: 'string'
},
style: {
type: 'object'
}
}
},
contextmenu: {
type: 'array',
child: {
name: {
type: 'string'
},
html: {
type: 'string'
},
click: {
type: 'function'
}
}
},
loading: {
type: 'string'
},
theme: {
type: 'string'
},
hotkey: {
type: 'boolean'
},
subtitle: {
type: 'object',
child: {
url: {
type: 'string'
},
style: {
type: 'object'
}
}
},
controls: {
type: 'array',
child: {
option: {
disable: {
type: 'boolean'
},
position: {
type: 'string'
},
index: {
type: 'number'
}
}
}
},
highlight: {
type: 'array',
child: {
time: {
type: 'number'
},
text: {
type: 'string'
}
}
},
moreVideoAttr: {
type: 'object'
},
lang: {
type: 'string'
}
};
function validOption(option) {
var param = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : scheme;
var path = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ['option'];
Object.keys(DEFAULTS).forEach(function (key) {
var defaultValue = DEFAULTS[key];
Object.keys(option).some(function (key) {
if (!param[key]) {
return true;
}
var value = option[key];
var defaultType = getType(defaultValue);
var type = getType(value);
var requiredType = param[key].type;
var isRequired = param[key].required;
var requiredChild = param[key].child;
if (key === 'container' || key === 'html') {
errorHandle(type === 'string' || value instanceof Element, "'".concat(path.join('.'), ".").concat(key, "' require 'string' or 'Element' type, but got '").concat(type, "'"));
} else {
errorHandle(defaultType === type, "'".concat(path.join('.'), ".").concat(key, "' require '").concat(defaultType, "' type, but got '").concat(type, "'"));
if (type === 'object' && requiredChild) {
validOption(value, requiredChild, path.concat(key));
}
if (type === 'object') {
validOption(defaultValue, value, path.concat(key));
if (type === 'array' && requiredChild) {
value.forEach(function (item, index) {
validOption(item, requiredChild, path.concat("".concat(key, "[").concat(index, "]")));
});
}
if (path.length === 1) {
if (key === 'layers') {
value.forEach(function (item, index) {
validOption({
name: '',
index: 0,
html: '',
style: {}
}, item, path.concat("".concat(key, "[").concat(index, "]")));
});
}
if (key === 'contextmenu') {
value.forEach(function (item, index) {
validOption({
name: '',
click: new Function(),
html: '',
style: {}
}, item, path.concat("".concat(key, "[").concat(index, "]")));
});
}
if (key === 'highlight') {
value.forEach(function (item, index) {
validOption({
time: 0,
text: ''
}, item, path.concat("".concat(key, "[").concat(index, "]")));
});
}
if (key === 'controls') {
value.forEach(function (item, index) {
if (item.option) {
validOption({
disable: false,
position: '',
index: 0
}, item.option, path.concat("".concat(key, "[").concat(index, "]")));
}
});
}
}
errorHandle(!isRequired || value, "'".concat(path.join('.'), ".").concat(key, "' is required"));
errorHandle(requiredType === type, "'".concat(path.join('.'), ".").concat(key, "' require '").concat(requiredType, "' type, but got '").concat(type, "'"));
return false;
});
}
@@ -679,10 +777,9 @@
});
$video.volume = clamp(option.volume, 0, 1);
$video.poster = option.poster;
$video.autoplay = option.autoplay;
sleep().then(function () {
$video.src = option.url;
});
$video.autoplay = option.autoplay; // TODO
$video.src = option.url;
}
}, {
key: "eventBind",
@@ -2407,7 +2504,7 @@
_this.emit('init:start');
_this.option = deepMerge({}, Artplayer.DEFAULTS, option);
validOption(Artplayer.DEFAULTS, _this.option);
validOption(_this.option);
_this.init();
+1 -1
View File
@@ -1 +1 @@
{"version":3,"file":"artplayer.js","sources":["../../node_modules/@babel/runtime/helpers/setPrototypeOf.js","../../node_modules/@babel/runtime/helpers/construct.js","../../node_modules/@babel/runtime/helpers/arrayWithoutHoles.js","../../node_modules/@babel/runtime/helpers/iterableToArray.js","../../node_modules/@babel/runtime/helpers/nonIterableSpread.js","../../node_modules/@babel/runtime/helpers/toConsumableArray.js","../../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/inherits.js","../../node_modules/@babel/runtime/helpers/defineProperty.js","../../node_modules/@babel/runtime/helpers/objectSpread.js","../../node_modules/@babel/runtime/helpers/isNativeFunction.js","../../node_modules/@babel/runtime/helpers/wrapNativeSuper.js","../../src/utils/index.js","../../src/verification/player.js","../../src/config/mimeCodec.js","../../src/config/mse.js","../../src/config/video.js","../../src/config/index.js","../../node_modules/tiny-emitter/index.js","../../src/template.js","../../src/i18n.js","../../src/player.js","../../src/controls/danmu.js","../../src/controls/fullscreen.js","../../src/controls/pip.js","../../node_modules/@babel/runtime/helpers/arrayWithHoles.js","../../node_modules/@babel/runtime/helpers/iterableToArrayLimit.js","../../node_modules/@babel/runtime/helpers/nonIterableRest.js","../../node_modules/@babel/runtime/helpers/slicedToArray.js","../../src/icons/index.js","../../src/controls/playAndPause.js","../../src/controls/progress.js","../../src/controls/subtitle.js","../../src/controls/time.js","../../src/controls/volume.js","../../src/controls/setting.js","../../src/controls/thumbnails.js","../../src/controls/index.js","../../src/contextmenu.js","../../src/danmu.js","../../src/info.js","../../src/subtitle.js","../../src/events.js","../../src/hotkey.js","../../src/layers.js","../../src/loading.js","../../src/notice.js","../../src/mask.js","../../src/index.js"],"sourcesContent":["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 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;","function _arrayWithoutHoles(arr) {\n if (Array.isArray(arr)) {\n for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) {\n arr2[i] = arr[i];\n }\n\n return arr2;\n }\n}\n\nmodule.exports = _arrayWithoutHoles;","function _iterableToArray(iter) {\n if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === \"[object Arguments]\") return Array.from(iter);\n}\n\nmodule.exports = _iterableToArray;","function _nonIterableSpread() {\n throw new TypeError(\"Invalid attempt to spread non-iterable instance\");\n}\n\nmodule.exports = _nonIterableSpread;","var arrayWithoutHoles = require(\"./arrayWithoutHoles\");\n\nvar iterableToArray = require(\"./iterableToArray\");\n\nvar nonIterableSpread = require(\"./nonIterableSpread\");\n\nfunction _toConsumableArray(arr) {\n return arrayWithoutHoles(arr) || iterableToArray(arr) || nonIterableSpread();\n}\n\nmodule.exports = _toConsumableArray;","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, Line truncated
{"version":3,"file":"artplayer.js","sources":["../../node_modules/@babel/runtime/helpers/setPrototypeOf.js","../../node_modules/@babel/runtime/helpers/construct.js","../../node_modules/@babel/runtime/helpers/arrayWithoutHoles.js","../../node_modules/@babel/runtime/helpers/iterableToArray.js","../../node_modules/@babel/runtime/helpers/nonIterableSpread.js","../../node_modules/@babel/runtime/helpers/toConsumableArray.js","../../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/inherits.js","../../node_modules/@babel/runtime/helpers/defineProperty.js","../../node_modules/@babel/runtime/helpers/objectSpread.js","../../node_modules/@babel/runtime/helpers/isNativeFunction.js","../../node_modules/@babel/runtime/helpers/wrapNativeSuper.js","../../src/utils/index.js","../../src/verification/scheme.js","../../src/verification/index.js","../../src/config/mimeCodec.js","../../src/config/mse.js","../../src/config/video.js","../../src/config/index.js","../../node_modules/tiny-emitter/index.js","../../src/template.js","../../src/i18n.js","../../src/player.js","../../src/controls/danmu.js","../../src/controls/fullscreen.js","../../src/controls/pip.js","../../node_modules/@babel/runtime/helpers/arrayWithHoles.js","../../node_modules/@babel/runtime/helpers/iterableToArrayLimit.js","../../node_modules/@babel/runtime/helpers/nonIterableRest.js","../../node_modules/@babel/runtime/helpers/slicedToArray.js","../../src/icons/index.js","../../src/controls/playAndPause.js","../../src/controls/progress.js","../../src/controls/subtitle.js","../../src/controls/time.js","../../src/controls/volume.js","../../src/controls/setting.js","../../src/controls/thumbnails.js","../../src/controls/index.js","../../src/contextmenu.js","../../src/danmu.js","../../src/info.js","../../src/subtitle.js","../../src/events.js","../../src/hotkey.js","../../src/layers.js","../../src/loading.js","../../src/notice.js","../../src/mask.js","../../src/index.js"],"sourcesContent":["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 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;","function _arrayWithoutHoles(arr) {\n if (Array.isArray(arr)) {\n for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) {\n arr2[i] = arr[i];\n }\n\n return arr2;\n }\n}\n\nmodule.exports = _arrayWithoutHoles;","function _iterableToArray(iter) {\n if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === \"[object Arguments]\") return Array.from(iter);\n}\n\nmodule.exports = _iterableToArray;","function _nonIterableSpread() {\n throw new TypeError(\"Invalid attempt to spread non-iterable instance\");\n}\n\nmodule.exports = _nonIterableSpread;","var arrayWithoutHoles = require(\"./arrayWithoutHoles\");\n\nvar iterableToArray = require(\"./iterableToArray\");\n\nvar nonIterableSpread = require(\"./nonIterableSpread\");\n\nfunction _toConsumableArray(arr) {\n return arrayWithoutHoles(arr) || iterableToArray(arr) || nonIterableSpread();\n}\n\nmodule.exports = _toConsumableArray;","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.definLine truncated
+2 -2
View File
@@ -1,7 +1,7 @@
import './style';
import 'balloon-css/balloon.min.css';
import { deepMerge } from './utils';
import validOption from './verification/player';
import validOption from './verification';
import config from './config';
import Emitter from 'tiny-emitter';
import Template from './template';
@@ -27,7 +27,7 @@ class Artplayer extends Emitter {
super();
this.emit('init:start');
this.option = deepMerge({}, Artplayer.DEFAULTS, option);
validOption(Artplayer.DEFAULTS, this.option);
validOption(this.option);
this.init();
this.emit('init:end');
}
+3 -3
View File
@@ -20,9 +20,9 @@ export default class Player {
$video.volume = clamp(option.volume, 0, 1);
$video.poster = option.poster;
$video.autoplay = option.autoplay;
sleep().then(() => {
$video.src = option.url;
});
// TODO
$video.src = option.url;
}
eventBind() {
+30
View File
@@ -0,0 +1,30 @@
import { errorHandle, getType } from '../utils';
import scheme from './scheme';
export default function validOption(option, param = scheme, path = ['option']) {
Object.keys(option).some(key => {
if (!param[key]) {
return true;
}
const value = option[key];
const type = getType(value);
const requiredType = param[key].type;
const isRequired = param[key].required;
const requiredChild = param[key].child;
if (type === 'object' && requiredChild) {
validOption(value, requiredChild, path.concat(key));
}
if (type === 'array' && requiredChild) {
value.forEach((item, index) => {
validOption(item, requiredChild, path.concat(`${key}[${index}]`));
});
}
errorHandle(!isRequired || value, `'${path.join('.')}.${key}' is required`);
errorHandle(requiredType === type, `'${path.join('.')}.${key}' require '${requiredType}' type, but got '${type}'`);
return false;
});
}
-87
View File
@@ -1,87 +0,0 @@
import { errorHandle, getType } from '../utils';
export default function validOption(DEFAULTS, option, path = ['option']) {
Object.keys(DEFAULTS).forEach(key => {
const defaultValue = DEFAULTS[key];
const value = option[key];
const defaultType = getType(defaultValue);
const type = getType(value);
if (key === 'container' || key === 'html') {
errorHandle(
type === 'string' || value instanceof Element,
`'${path.join('.')}.${key}' require 'string' or 'Element' type, but got '${type}'`
);
} else {
errorHandle(
defaultType === type,
`'${path.join('.')}.${key}' require '${defaultType}' type, but got '${type}'`
);
}
if (type === 'object') {
validOption(defaultValue, value, path.concat(key));
}
if (path.length === 1) {
if (key === 'layers') {
value.forEach((item, index) => {
validOption(
{
name: '',
index: 0,
html: '',
style: {}
},
item,
path.concat(`${key}[${index}]`)
);
});
}
if (key === 'contextmenu') {
value.forEach((item, index) => {
validOption(
{
name: '',
click: new Function(),
html: '',
style: {}
},
item,
path.concat(`${key}[${index}]`)
);
});
}
if (key === 'highlight') {
value.forEach((item, index) => {
validOption(
{
time: 0,
text: ''
},
item,
path.concat(`${key}[${index}]`)
);
});
}
if (key === 'controls') {
value.forEach((item, index) => {
if (item.option) {
validOption(
{
disable: false,
position: '',
index: 0
},
item.option,
path.concat(`${key}[${index}]`)
);
}
});
}
}
});
}
+132
View File
@@ -0,0 +1,132 @@
export default {
container: {
type: 'string',
required: true
},
url: {
type: 'string',
required: true
},
poster: {
type: 'string'
},
volume: {
type: 'number'
},
thumbnails: {
type: 'object',
child: {
url: {
type: 'string'
},
number: {
type: 'number'
},
width: {
type: 'number'
},
height: {
type: 'number'
},
column: {
type: 'number'
}
}
},
autoplay: {
type: 'boolean'
},
loop: {
type: 'boolean'
},
type: {
type: 'string'
},
mimeCodec: {
type: 'string'
},
layers: {
type: 'array',
child: {
name: {
type: 'string'
},
index: {
type: 'number'
},
html: {
type: 'string'
},
style: {
type: 'object'
}
}
},
contextmenu: {
type: 'array',
child: {
name: {
type: 'string'
},
html: {
type: 'string'
},
click: {
type: 'function'
}
}
},
loading: {
type: 'string'
},
theme: {
type: 'string'
},
hotkey: {
type: 'boolean'
},
subtitle: {
type: 'object',
child: {
url: {
type: 'string'
},
style: {
type: 'object'
}
}
},
controls: {
type: 'array',
child: {
option: {
disable: {
type: 'boolean'
},
position: {
type: 'string'
},
index: {
type: 'number'
}
}
}
},
highlight: {
type: 'array',
child: {
time: {
type: 'number'
},
text: {
type: 'string'
}
}
},
moreVideoAttr: {
type: 'object'
},
lang: {
type: 'string'
}
};