fix error in reading empty danmaku list

This commit is contained in:
DIYgod 2018-01-12 00:45:09 +08:00
parent 6f61076345
commit 6524114f05
No known key found for this signature in database
GPG Key ID: EC0B76A252D3EF67
6 changed files with 36 additions and 31 deletions

View File

@ -149,26 +149,26 @@ function initPlayers () {
// } // }
// }); // });
// window.dp6 = new DPlayer({ window.dp6 = new DPlayer({
// container: document.getElementById('dplayer6'), container: document.getElementById('dplayer6'),
// preload: 'none', preload: 'none',
// live: true, live: true,
// danmaku: true, danmaku: true,
// apiBackend: { apiBackend: {
// read: function (endpoint, callback) { read: function (endpoint, callback) {
// console.log('假装 WebSocket 连接成功'); console.log('假装 WebSocket 连接成功');
// callback(); callback();
// }, },
// send: function (endpoint, danmakuData, callback) { send: function (endpoint, danmakuData, callback) {
// console.log('假装通过 WebSocket 发送数据', danmakuData); console.log('假装通过 WebSocket 发送数据', danmakuData);
// callback(); callback();
// } }
// }, },
// video: { video: {
// url: 'https://moeplayer.b0.upaiyun.com/dplayer/hls/hikarunara.m3u8', url: 'https://moeplayer.b0.upaiyun.com/dplayer/hls/hikarunara.m3u8',
// type: 'hls' type: 'hls'
// } }
// }); });
} }
function clearPlayers () { function clearPlayers () {

View File

@ -56,7 +56,7 @@
<h2 id="live">Live</h2> <h2 id="live">Live</h2>
<div class="example"> <div class="example">
<button class="btn" onclick="drawDanmaku()">假装收到 WebSocket 弹幕</button> <button class="btn" onclick="dp6.danmaku.draw({text: '假装收到 WebSocket 弹幕', color: '#fff', type: 'right'})">假装收到 WebSocket 弹幕</button>
<div id="dplayer6"></div> <div id="dplayer6"></div>
</div> </div>

2
dist/DPlayer.min.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
{ {
"name": "dplayer", "name": "dplayer",
"version": "1.19.0", "version": "1.19.1",
"description": "Wow, such a lovely HTML5 danmaku video player", "description": "Wow, such a lovely HTML5 danmaku video player",
"main": "dist/DPlayer.min.js", "main": "dist/DPlayer.min.js",
"style": "dist/DPlayer.min.css", "style": "dist/DPlayer.min.css",

View File

@ -68,13 +68,18 @@ class Danmaku {
} }
else { else {
const typeMap = ['right', 'top', 'bottom']; const typeMap = ['right', 'top', 'bottom'];
results[i] = data.map((item) => ({ if (data) {
time: item[0], results[i] = data.map((item) => ({
type: typeMap[item[1]], time: item[0],
color: item[2], type: typeMap[item[1]],
author: item[3], color: item[2],
text: item[4] author: item[3],
})); text: item[4]
}));
}
else {
results[i] = [];
}
} }
if (readCount === endpoints.length) { if (readCount === endpoints.length) {
return callback(results); return callback(results);