弹幕池支持异步返回

This commit is contained in:
Harvey Zack committed 2019-04-26 12:05:59 +08:00
1 parent 9bd1452030
commit 9d730146c0
5 files changed
+64 -64

No files matched your search

@@ -1,24 +1,21 @@
export function bilibiliDanmuParseFromXml(xmlString) {
if (typeof xmlString !== 'string') return [];
const regSrt = '<d p="(.+)">(.+)</d>';
const listReg = new RegExp(regSrt, 'gi');
const itemReg = new RegExp(regSrt, 'i');
const srtList = xmlString.match(listReg);
const srtList = xmlString.match(/<d([\S ]*?>[\S ]*?)<\/d>/gi);
return srtList.length
? srtList.map(item => {
const [, attrStr, text] = item.match(itemReg);
const attr = attrStr.split(',').map(Number);
const [, attrStr, text] = item.match(/<d p="(.+)">(.+)<\/d>/);
const attr = attrStr.split(',');
return attr.length === 8 && text.trim()
? {
text,
time: attr[0],
mode: attr[1],
size: attr[2],
color: `#${attr[3].toString(16)}`,
timestamp: attr[4],
pool: attr[5],
time: Number(attr[0]),
mode: Number(attr[1]),
size: Number(attr[2]),
color: `#${Number(attr[3]).toString(16)}`,
timestamp: Number(attr[4]),
pool: Number(attr[5]),
userID: attr[6],
rowID: attr[7],
rowID: Number(attr[7]),
}
: null;
})
+12 -14
View File
@@ -2,14 +2,21 @@ export default class Danmuku {
constructor(art, option = {}) {
this.art = art;
this.queue = {};
this.option = Object.assign({}, Danmuku.option, option);
art.constructor.validator(this.option, Danmuku.scheme);
this.option.danmus.forEach(this.emit);
this.current = [];
this.layer = {};
this.isStop = false;
this.timer = null;
this.init();
this.option = Object.assign({}, Danmuku.option, option);
art.constructor.validator(this.option, Danmuku.scheme);
if (typeof this.option.danmus === 'function') {
this.option.danmus().then(danmus => {
danmus.forEach(this.emit);
this.init();
});
} else {
this.option.danmus.forEach(this.emit);
this.init();
}
}
static get option() {
@@ -24,16 +31,7 @@ export default class Danmuku {
static get scheme() {
return {
danmus: {
type: 'array',
child: {
text: 'string',
size: 'number',
time: 'number',
color: 'string',
mode: 'number',
},
},
danmus: 'array|function',
speed: 'number',
opacity: 'number',
color: 'string',