-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
107 lines (103 loc) · 2.61 KB
/
main.js
File metadata and controls
107 lines (103 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import flvjs from "flv.js";
import DPlayer from "dplayer";
import Hls from "hls.js";
const WS_URL = "ws://live.bitnp.net:8888/websocket";
let ws;
let _flvPlayer = null;
let last_send_time = new Date().getTime();
const dp = new DPlayer({
container: document.getElementById("dplayer"),
autoplay: true,
// screenshot: true,
// hotkey: true,
video: {
// url: url,
type: "customFlv",
customType: {
customFlv: function(video, player) {
if (_flvPlayer) {
console.log("destroy flvPlayer");
_flvPlayer.destroy();
}
const flvPlayer = flvjs.createPlayer({
type: "flv",
url: video.src
});
_flvPlayer = flvPlayer;
flvPlayer.attachMediaElement(video);
flvPlayer.load();
console.log("create flvPlayer");
console.log(flvPlayer);
},
customHls: function(video, player) {
const hls = new Hls();
hls.loadSource(video.src);
hls.attachMedia(video);
}
},
quality: [
{
name: "720P",
url: "http://live.bitnp.net/nplive/livestream_720.flv",
type: "customFlv"
},
{
name: "1080P",
url: "http://live.bitnp.net/nplive/livestream_1080.flv",
type: "customFlv"
}
// {
// name: "手机备用",
// url: "http://live.bitnp.net/nplive/livestream_720-86.ts",
// type: "customHls"
// }
],
defaultQuality: 0
},
apiBackend: {
read: function(options) {
try {
ws = new WebSocket(WS_URL);
options.success();
} catch (e) {
dp.notice("弹幕暂时无法使用哦");
options.error();
}
},
send: function(options) {
// console.log("Pretend to send danamku via WebSocket", options);
if (options.data.text.length > 30) {
dp.notice("弹幕长度不要超过 30 字哦");
return;
}
if (last_send_time + 3000 > new Date().getTime()) {
dp.notice("弹幕发送间隔要大于 3s 哦");
return;
}
const data = {
type: "danmaku",
data: {
text: options.data.text,
color: options.data.color,
type: options.data.type
}
};
last_send_time = new Date().getTime();
ws.send(JSON.stringify(data));
dp.notice("弹幕发送成功");
}
},
danmaku: {
maximum: 100,
bottom: "15%",
unlimited: true
},
live: true
});
ws.onmessage = function(e) {
const data = JSON.parse(e.data);
if (data.type === "danmaku") {
dp.danmaku.draw(data.data);
}
};
dp.danmaku.dan = dp.danmaku.dan.filter(v => v);