DEBUG
This commit is contained in:
parent
56c9d2c8f5
commit
f7035e5d76
|
@ -95,7 +95,7 @@
|
||||||
const { type, id, channel, list } = JSON.parse(event.data)
|
const { type, id, channel, list } = JSON.parse(event.data)
|
||||||
console.log('收到 base 基本信道数据:', type, id, channel)
|
console.log('收到 base 基本信道数据:', type, id, channel)
|
||||||
if (type === 'get_music_list') {
|
if (type === 'get_music_list') {
|
||||||
console.log('发送音乐列表:', musicList.list)
|
console.log(client.name, '请求音乐列表:', musicList.list)
|
||||||
clientList.send('base', JSON.stringify({
|
clientList.send('base', JSON.stringify({
|
||||||
type: 'set_music_list',
|
type: 'set_music_list',
|
||||||
list: musicList.list.map(({ id, name, size, type }) => ({ id, name, size, type }))
|
list: musicList.list.map(({ id, name, size, type }) => ({ id, name, size, type }))
|
||||||
|
@ -103,7 +103,7 @@
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (type === 'set_music_list') {
|
if (type === 'set_music_list') {
|
||||||
console.log('接收音乐列表:', event)
|
console.log(client.name, '发来音乐列表:', event)
|
||||||
// 将音乐列表添加到本地
|
// 将音乐列表添加到本地
|
||||||
const ids = musicList.list.map(item => item.id)
|
const ids = musicList.list.map(item => item.id)
|
||||||
list.filter(item => !ids.includes(item.id)).forEach(item => {
|
list.filter(item => !ids.includes(item.id)).forEach(item => {
|
||||||
|
@ -113,11 +113,11 @@
|
||||||
}
|
}
|
||||||
if (type === 'get_music_data') {
|
if (type === 'get_music_data') {
|
||||||
// 建立一个信道, 用于传输音乐数据(接收方已经准备好摘要信息)
|
// 建立一个信道, 用于传输音乐数据(接收方已经准备好摘要信息)
|
||||||
console.log('建立一个信道, 用于传输音乐数据', musicList.list)
|
console.log(client.name, '建立一个信道, 用于传输音乐数据', musicList.list)
|
||||||
musicList.list.filter(item => item.id === id).forEach(item => {
|
musicList.list.filter(item => item.id === id).forEach(item => {
|
||||||
const ch = client.webrtc.createDataChannel(channel, { reliable: true })
|
const ch = client.webrtc.createDataChannel(channel, { reliable: true })
|
||||||
ch.onopen = async event => {
|
ch.onopen = async event => {
|
||||||
console.log(`打开 ${channel} 信道, 传输音乐数据`)
|
console.log(client.name, `打开 ${channel} 信道, 传输音乐数据`)
|
||||||
// 将音乐数据分成多个小块,并逐个发送
|
// 将音乐数据分成多个小块,并逐个发送
|
||||||
async function sendChunk(dataChannel, data, index = 0, buffer = new ArrayBuffer(0)) {
|
async function sendChunk(dataChannel, data, index = 0, buffer = new ArrayBuffer(0)) {
|
||||||
while (index < data.byteLength) {
|
while (index < data.byteLength) {
|
||||||
|
|
Loading…
Reference in New Issue