清理调试信息

This commit is contained in:
2023-10-19 07:03:21 +08:00
parent edae22db79
commit 2c00cb8ef9
3 changed files with 20 additions and 20 deletions

View File

@ -154,7 +154,7 @@
// 只有一个基本信道, 用于交换和调度信息 // 只有一个基本信道, 用于交换和调度信息
clientList.setChannel('base', { clientList.setChannel('base', {
onopen: async event => { onopen: async event => {
console.debug('打开信道', event.target.label, '广播请求音乐列表和身份信息') //console.debug('打开信道', event.target.label, '广播请求音乐列表和身份信息')
clientList.send('base', JSON.stringify({ type: 'get_music_list' })) // 要求对方发送音乐列表 clientList.send('base', JSON.stringify({ type: 'get_music_list' })) // 要求对方发送音乐列表
clientList.send('base', JSON.stringify({ type: 'get_user_profile' })) // 要求对方发送身份信息 clientList.send('base', JSON.stringify({ type: 'get_user_profile' })) // 要求对方发送身份信息
}, },

View File

@ -78,11 +78,11 @@ export default class ClientList {
} }
}) })
webrtc.ondatachannel = ({ channel }) => { webrtc.ondatachannel = ({ channel }) => {
console.debug(data.name, '建立', channel.label, '数据通道') //console.debug(data.name, '建立', channel.label, '数据通道')
const client = this.clientlist.find(x => x.id === data.id) const client = this.clientlist.find(x => x.id === data.id)
const option = this.channels[channel.label] const option = this.channels[channel.label]
channel.onopen = event => { channel.onopen = event => {
console.debug('对方打开', channel.label, '数据通道') //console.debug('对方打开', channel.label, '数据通道')
if (option && option.onopen) { if (option && option.onopen) {
option.onopen(event, client) option.onopen(event, client)
} }
@ -120,7 +120,7 @@ export default class ClientList {
console.error(data.name, '需要添加新的 candidate') console.error(data.name, '需要添加新的 candidate')
// 添加新的 candidate // 添加新的 candidate
} else if (webrtc.iceConnectionState === 'connected' || webrtc.iceConnectionState === 'completed') { } else if (webrtc.iceConnectionState === 'connected' || webrtc.iceConnectionState === 'completed') {
console.debug(data.name, 'WebRTC 连接已经建立成功') //console.debug(data.name, 'WebRTC 连接已经建立成功')
} }
} }
const channels = Object.entries(this.channels).map(([name, callback]) => { const channels = Object.entries(this.channels).map(([name, callback]) => {
@ -137,9 +137,9 @@ export default class ClientList {
return { webrtc, channels } return { webrtc, channels }
} }
if (data.type === 'list') { if (data.type === 'list') {
console.debug('取得在线对端列表:', data) //console.debug('取得在线对端列表:', data)
const { webrtc, channels } = await webrtc_init() const { webrtc, channels } = await webrtc_init()
console.debug('发送给对方 offer') //console.debug('发送给对方 offer')
const offer = await webrtc.createOffer() const offer = await webrtc.createOffer()
await webrtc.setLocalDescription(offer) await webrtc.setLocalDescription(offer)
this.clientlist.push({ id: data.id, name: data.name, webrtc, channels }) this.clientlist.push({ id: data.id, name: data.name, webrtc, channels })
@ -149,7 +149,7 @@ export default class ClientList {
return return
} }
if (data.type === 'push') { if (data.type === 'push') {
console.debug('新上线客户端:', data) //console.debug('新上线客户端:', data)
return return
} }
if (data.type === 'pull') { if (data.type === 'pull') {
@ -157,12 +157,12 @@ export default class ClientList {
return this.exit(data) return this.exit(data)
} }
if (data.type === 'offer') { if (data.type === 'offer') {
console.debug('收到对方 offer', data) //console.debug('收到对方 offer', data)
const { webrtc, channels } = await webrtc_init() const { webrtc, channels } = await webrtc_init()
this.clientlist.push({ id: data.id, name: data.name, webrtc, channels }) this.clientlist.push({ id: data.id, name: data.name, webrtc, channels })
// 传递正确的指针给元素, 以便其能够调取正确的头像 // 传递正确的指针给元素, 以便其能够调取正确的头像
this.push(this.clientlist.find(client => client.id === data.id)) this.push(this.clientlist.find(client => client.id === data.id))
console.debug('发送给对方 answer') //console.debug('发送给对方 answer')
await webrtc.setRemoteDescription(data.offer) await webrtc.setRemoteDescription(data.offer)
const answer = await webrtc.createAnswer() const answer = await webrtc.createAnswer()
await webrtc.setLocalDescription(answer) await webrtc.setLocalDescription(answer)
@ -170,13 +170,13 @@ export default class ClientList {
return return
} }
if (data.type === 'answer') { if (data.type === 'answer') {
console.debug('收到对方 answer', data) //console.debug('收到对方 answer', data)
const webrtc = this.clientlist.find(client => client.id === data.id).webrtc const webrtc = this.clientlist.find(client => client.id === data.id).webrtc
await webrtc.setRemoteDescription(data.answer) await webrtc.setRemoteDescription(data.answer)
return return
} }
if (data.type === 'candidate') { if (data.type === 'candidate') {
console.debug(data.name, '发来 candidate 候选通道') //console.debug(data.name, '发来 candidate 候选通道')
const webrtc = this.clientlist.find(client => client.id === data.id).webrtc const webrtc = this.clientlist.find(client => client.id === data.id).webrtc
await webrtc.addIceCandidate(data.candidate) await webrtc.addIceCandidate(data.candidate)
return return
@ -227,11 +227,11 @@ export default class ClientList {
} }
getAvatar(id) { } getAvatar(id) { }
setAvatar(user) { setAvatar(user) {
console.info('更新avatar', user) //console.info('更新avatar', user)
document.getElementById(user.id).querySelector('img').src = user.avatar document.getElementById(user.id).querySelector('img').src = user.avatar
const u = this.clientlist.find(client => client.id === user.id) const u = this.clientlist.find(client => client.id === user.id)
u.avatar = user.avatar u.avatar = user.avatar
console.log(u, user) //console.log(u, user)
//.avatar = user.avatar //.avatar = user.avatar
} }
exit(item) { exit(item) {

View File

@ -85,20 +85,20 @@ const musicList = new MusicList({
} }
}, },
onban: item => { onban: item => {
console.info('禁止音乐', item.name) //console.info('禁止音乐', item.name)
}, },
onunban: item => { onunban: item => {
console.info('解禁音乐', item.name) //console.info('解禁音乐', item.name)
}, },
onremove: item => { onremove: item => {
console.info('移除音乐', item.name) //console.info('移除音乐', item.name)
musicStore.delete(item.id) musicStore.delete(item.id)
}, },
onadd: (item, list) => { onadd: (item, list) => {
console.info('添加音乐', item.name) //console.info('添加音乐', item.name)
}, },
onupdate: item => { onupdate: item => {
console.info('更新音乐', item.name) //console.info('更新音乐', item.name)
musicStore.put(item) musicStore.put(item)
}, },
onerror: error => { onerror: error => {
@ -154,7 +154,7 @@ const chat = new Chat({
// 与每个客户端都建立聊天信道 // 与每个客户端都建立聊天信道
clientList.setChannel('chat', { clientList.setChannel('chat', {
onopen: async event => { onopen: async event => {
console.debug('打开信道', event.target.label) //console.debug('打开信道', event.target.label)
}, },
onmessage: async (event, client) => { onmessage: async (event, client) => {
const data = JSON.parse(event.data) const data = JSON.parse(event.data)
@ -268,7 +268,7 @@ clientList.setChannel('profile', {
// 与每个客户端都建立基本信道, 用于交换和调度信息 // 与每个客户端都建立基本信道, 用于交换和调度信息
clientList.setChannel('base', { clientList.setChannel('base', {
onopen: async event => { onopen: async event => {
console.debug('打开信道', event.target.label, '广播请求音乐列表和身份信息') //console.debug('打开信道', event.target.label, '广播请求音乐列表和身份信息')
clientList.send('base', JSON.stringify({ type: 'get_music_list' })) // 要求对方发送音乐列表 clientList.send('base', JSON.stringify({ type: 'get_music_list' })) // 要求对方发送音乐列表
//clientList.send('base', JSON.stringify({ type: 'get_user_profile' })) // 要求对方发送身份信息 //clientList.send('base', JSON.stringify({ type: 'get_user_profile' })) // 要求对方发送身份信息
}, },