请求到单个目标防止接收到重复分片数据
This commit is contained in:
parent
5d423aedb4
commit
e3176301f8
@ -3,6 +3,8 @@ webrtc 实现的 p2p 信道
|
|||||||
|
|
||||||
- [x] P2P通信
|
- [x] P2P通信
|
||||||
- [x] 音乐播放
|
- [x] 音乐播放
|
||||||
|
- [x] 请求到单个目标防止接收到重复分片数据
|
||||||
|
- [x] 主机记录各自曲目列表以供查询
|
||||||
- [ ] 集群分发
|
- [ ] 集群分发
|
||||||
- [ ] 下载加速
|
- [ ] 下载加速
|
||||||
- [ ] 即时通讯
|
- [ ] 即时通讯
|
||||||
|
@ -153,7 +153,6 @@ export default class ClientList {
|
|||||||
}
|
}
|
||||||
// 通过指定通道发送数据(单播)
|
// 通过指定通道发送数据(单播)
|
||||||
sendto(id, name, data) {
|
sendto(id, name, data) {
|
||||||
//console.log('发送数据:', data, '到通道:', name, '到客户端:', id)
|
|
||||||
const client = this.clientlist.find(client => client.id === id)
|
const client = this.clientlist.find(client => client.id === id)
|
||||||
if (!client) {
|
if (!client) {
|
||||||
console.log('客户端不存在:', id)
|
console.log('客户端不存在:', id)
|
||||||
@ -169,9 +168,7 @@ export default class ClientList {
|
|||||||
}
|
}
|
||||||
// 通过指定通道发送数据(广播)
|
// 通过指定通道发送数据(广播)
|
||||||
send(name, data) {
|
send(name, data) {
|
||||||
//console.log('广播数据:', data, '到通道:', name, '到所有客户端')
|
|
||||||
this.clientlist.forEach(client => {
|
this.clientlist.forEach(client => {
|
||||||
//console.log('发送数据到客户端:', client.id, client.name, '通道:', name, '数据:', data)
|
|
||||||
client.channels.filter(ch => ch.label === name).forEach(async ch => {
|
client.channels.filter(ch => ch.label === name).forEach(async ch => {
|
||||||
// 等待 datachannel 打开(临时解决方案)
|
// 等待 datachannel 打开(临时解决方案)
|
||||||
while (ch.readyState !== 'open') {
|
while (ch.readyState !== 'open') {
|
||||||
|
@ -87,7 +87,13 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
clientList.send('base', JSON.stringify({ type: 'get_music_data', id: item.id, channel: `music-data-${item.id}` }))
|
console.log('TODO: 重复请求改为指向目标主机(需要主机各自保存列表/收到列表时)')
|
||||||
|
const client = clientList.clientlist.find(client => {
|
||||||
|
return client.musicList.find(x => x.id === item.id)
|
||||||
|
})
|
||||||
|
clientList.sendto(client.id, 'base', JSON.stringify({
|
||||||
|
type: 'get_music_data', id: item.id, channel: `music-data-${item.id}`
|
||||||
|
}))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -124,12 +130,9 @@
|
|||||||
}
|
}
|
||||||
if (type === 'set_music_list') {
|
if (type === 'set_music_list') {
|
||||||
console.log(client.name, '发来音乐列表:', `x${JSON.parse(event.data).list.length}`)
|
console.log(client.name, '发来音乐列表:', `x${JSON.parse(event.data).list.length}`)
|
||||||
// 将音乐列表添加到本地
|
console.log('将列表保存到本机记录:', client)
|
||||||
|
client.musicList = list
|
||||||
list.forEach(item => musicList.add(item))
|
list.forEach(item => musicList.add(item))
|
||||||
//const ids = musicList.list.map(item => item.id)
|
|
||||||
//list.filter(item => !ids.includes(item.id)).forEach(item => {
|
|
||||||
// musicList.add(item)
|
|
||||||
//})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (type === 'get_music_data') {
|
if (type === 'get_music_data') {
|
||||||
|
Loading…
Reference in New Issue
Block a user