Merge branch 'main' of https://github.com/InvisibleFuture/webrtc
This commit is contained in:
commit
08ddae09f9
11
README.md
11
README.md
@ -1,10 +1,15 @@
|
||||
# webRTC
|
||||
webrtc 实现的 p2p 信道
|
||||
|
||||
rtc rtc rtc
|
||||
channel channel channel channel
|
||||
part-server
|
||||
rtc rtc rtc: 稳定, 多重连接
|
||||
channel channel channel: 细流
|
||||
part-server: 调谐, 从不同服务器请求资源分片
|
||||
webrtc://用户@域名:端口/信道标识/资源ID
|
||||
|
||||
1. 每个节点都公开持有的资源列表, 和连接的节点列表
|
||||
2. 每当资源变动时告知所有连接的节点
|
||||
3. 与节点创建多个RTC时, 不发送多份, 以ID为准, id随机生成给不同机器, 无法通过ID锁定其它机器
|
||||
4. 通过WS交换信息时, ID是否固定? 向WS提供连接?
|
||||
|
||||
- [x] P2P通信
|
||||
- [ ] 分离出主要功能, 作为库或桁架使用
|
||||
|
@ -29,10 +29,14 @@
|
||||
return tmp.buffer
|
||||
}
|
||||
|
||||
// 读取本地图像
|
||||
const imageStore = new IndexedDB('musicDatabase', 1, 'imageObjectStore')
|
||||
await imageStore.open()
|
||||
|
||||
// 读取本地音乐列表并标识为缓存状态(本地缓存)
|
||||
const database = new IndexedDB('musicDatabase', 1, 'musicObjectStore')
|
||||
await database.open()
|
||||
const list = (await database.getAll()).map(item => {
|
||||
const musicStore = new IndexedDB('musicDatabase', 1, 'musicObjectStore')
|
||||
await musicStore.open()
|
||||
const list = (await musicStore.getAll()).map(item => {
|
||||
return { save: true, ...item }
|
||||
})
|
||||
|
||||
@ -73,7 +77,7 @@
|
||||
onlike: (item, list) => {
|
||||
console.log('喜欢音乐', item.name)
|
||||
if (item.arrayBuffer) {
|
||||
database.add(item)
|
||||
musicStore.add(item)
|
||||
clientList.send('base', JSON.stringify({
|
||||
type: 'set_music_list',
|
||||
list: list.map(({ id, name, size, type }) => ({ id, name, size, type }))
|
||||
@ -83,7 +87,7 @@
|
||||
onunlike: (item, list) => {
|
||||
console.log('取消喜欢', item.name)
|
||||
if (item.arrayBuffer) {
|
||||
database.delete(item.id)
|
||||
musicStore.delete(item.id)
|
||||
clientList.send('base', JSON.stringify({
|
||||
type: 'set_music_list',
|
||||
list: list.map(({ id, name, size, type }) => ({ id, name, size, type }))
|
||||
@ -98,14 +102,14 @@
|
||||
},
|
||||
onremove: item => {
|
||||
console.info('移除音乐', item.name)
|
||||
database.delete(item.id)
|
||||
musicStore.delete(item.id)
|
||||
},
|
||||
onadd: (item, list) => {
|
||||
console.info('添加音乐', item.name)
|
||||
},
|
||||
onupdate: item => {
|
||||
console.info('更新音乐', item.name)
|
||||
database.put(item)
|
||||
musicStore.put(item)
|
||||
},
|
||||
onerror: error => {
|
||||
console.error('音乐列表错误', error)
|
||||
@ -145,6 +149,8 @@
|
||||
}
|
||||
})
|
||||
|
||||
const ImageList = []
|
||||
|
||||
// 只有一个基本信道, 用于交换和调度信息
|
||||
clientList.setChannel('base', {
|
||||
onopen: async event => {
|
||||
@ -174,6 +180,9 @@
|
||||
clientList.setAvatar({ id:client.id, ...data })
|
||||
return
|
||||
}
|
||||
if (data.type === 'get_image_list') {
|
||||
// webrtc://用户@域名:端口/信道标识/资源ID
|
||||
}
|
||||
if (data.type === 'get_music_list') {
|
||||
const ms = musicList.list.filter(item => item.arrayBuffer)
|
||||
console.log(client.name, '请求音乐列表:', ms)
|
||||
|
Loading…
Reference in New Issue
Block a user