Closed allen7593 closed 3 years ago
你好, 根据 https://github.com/lovelyyoshino/Bilibili-Live-API/blob/master/API.WebSocket.md 实现了一个前端获取弹幕的工具,但是现在测试下来我有且只能获取到NOTICE_MSG类型的数据包(op==8和op==3同样会正常接收)。 this.$axios.get(/room/${this.roomid}).then((res) => { const userid = res.data.data.uid this.$axios.get(/danmuku_info/${this.roomid}).then((res) => { const data = res.data.data this.ws = new WebSocket('wss://broadcastlv.chat.bilibili.com/sub') this.ws.onopen = () => { this.ws.send(this.encode(JSON.stringify({ roomid: this.roomid, protover: 1, platform: 'web', type: 2, clientver: '2.4.16', key: data.token, uid: userid }), 7)) } this.ws.onclose = this.disconnect this.heartBeat = setInterval(() => { this.ws.send(this.encode('', 2)) }, 30000) this.ws.onmessage = this.onDanmaku this.busy = false }) }) 后续我还根据ver分别decode body信息 if (result.ver === 2) { body = this.textDecoder.decode(pako.inflate(data)) if (body) { result.body.push(JSON.parse(body.slice(body.indexOf('{')))) } } else if (result.ver === 0) { body = this.textDecoder.decode(data) if (body) { result.body.push(JSON.parse(body)) } } 我目前完全无法获取其他类型的弹幕,是我哪里写错了还是b站又有了新的机制?
this.$axios.get(
).then((res) => { const userid = res.data.data.uid this.$axios.get(
).then((res) => { const data = res.data.data this.ws = new WebSocket('wss://broadcastlv.chat.bilibili.com/sub') this.ws.onopen = () => { this.ws.send(this.encode(JSON.stringify({ roomid: this.roomid, protover: 1, platform: 'web', type: 2, clientver: '2.4.16', key: data.token, uid: userid }), 7)) } this.ws.onclose = this.disconnect this.heartBeat = setInterval(() => { this.ws.send(this.encode('', 2)) }, 30000) this.ws.onmessage = this.onDanmaku this.busy = false }) })
if (result.ver === 2) { body = this.textDecoder.decode(pako.inflate(data)) if (body) { result.body.push(JSON.parse(body.slice(body.indexOf('{')))) } } else if (result.ver === 0) { body = this.textDecoder.decode(data) if (body) { result.body.push(JSON.parse(body)) } }
您好已更新
你好, 根据 https://github.com/lovelyyoshino/Bilibili-Live-API/blob/master/API.WebSocket.md 实现了一个前端获取弹幕的工具,但是现在测试下来我有且只能获取到NOTICE_MSG类型的数据包(op==8和op==3同样会正常接收)。
this.$axios.get(
/room/${this.roomid}).then((res) => { const userid = res.data.data.uid this.$axios.get(
/danmuku_info/${this.roomid}).then((res) => { const data = res.data.data this.ws = new WebSocket('wss://broadcastlv.chat.bilibili.com/sub') this.ws.onopen = () => { this.ws.send(this.encode(JSON.stringify({ roomid: this.roomid, protover: 1, platform: 'web', type: 2, clientver: '2.4.16', key: data.token, uid: userid }), 7)) } this.ws.onclose = this.disconnect this.heartBeat = setInterval(() => { this.ws.send(this.encode('', 2)) }, 30000) this.ws.onmessage = this.onDanmaku this.busy = false }) })
后续我还根据ver分别decode body信息if (result.ver === 2) { body = this.textDecoder.decode(pako.inflate(data)) if (body) { result.body.push(JSON.parse(body.slice(body.indexOf('{')))) } } else if (result.ver === 0) { body = this.textDecoder.decode(data) if (body) { result.body.push(JSON.parse(body)) } }
我目前完全无法获取其他类型的弹幕,是我哪里写错了还是b站又有了新的机制?