Skip to content

Commit

Permalink
fix error in reading empty danmaku list
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed Jan 11, 2018
1 parent 6f61076 commit 6524114
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 31 deletions.
40 changes: 20 additions & 20 deletions demo/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,26 +149,26 @@ function initPlayers () {
// }
// });

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

function clearPlayers () {
Expand Down
2 changes: 1 addition & 1 deletion demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ <h2 id="flv-support">FLV support</h2>

<h2 id="live">Live</h2>
<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>

Expand Down
2 changes: 1 addition & 1 deletion dist/DPlayer.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/DPlayer.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dplayer",
"version": "1.19.0",
"version": "1.19.1",
"description": "Wow, such a lovely HTML5 danmaku video player",
"main": "dist/DPlayer.min.js",
"style": "dist/DPlayer.min.css",
Expand Down
19 changes: 12 additions & 7 deletions src/js/danmaku.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,18 @@ class Danmaku {
}
else {
const typeMap = ['right', 'top', 'bottom'];
results[i] = data.map((item) => ({
time: item[0],
type: typeMap[item[1]],
color: item[2],
author: item[3],
text: item[4]
}));
if (data) {
results[i] = data.map((item) => ({
time: item[0],
type: typeMap[item[1]],
color: item[2],
author: item[3],
text: item[4]
}));
}
else {
results[i] = [];
}
}
if (readCount === endpoints.length) {
return callback(results);
Expand Down

0 comments on commit 6524114

Please sign in to comment.