TURN DEBUG
This commit is contained in:
		
							
								
								
									
										11
									
								
								index.js
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								index.js
									
									
									
									
									
								
							@@ -5,11 +5,12 @@ import { exec } from 'child_process'
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// 创建 TURN 服务器
 | 
					// 创建 TURN 服务器
 | 
				
			||||||
const turnServer = new turn({
 | 
					const turnServer = new turn({
 | 
				
			||||||
    authMech: 'long-term',
 | 
					    //authMech: 'long-term',
 | 
				
			||||||
    credentials: {
 | 
					    //credentials: {
 | 
				
			||||||
        username: 'your-username',
 | 
					    //    username: 'your-username',
 | 
				
			||||||
        password: 'your-password',
 | 
					    //    password: 'your-password',
 | 
				
			||||||
    },
 | 
					    //},
 | 
				
			||||||
 | 
					    authMech: 'none',
 | 
				
			||||||
    debugLevel: 'ALL',
 | 
					    debugLevel: 'ALL',
 | 
				
			||||||
    listeningIps: ['0.0.0.0'],
 | 
					    listeningIps: ['0.0.0.0'],
 | 
				
			||||||
    listeningPort: 3478,
 | 
					    listeningPort: 3478,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -15,12 +15,12 @@ export default class ClientList {
 | 
				
			|||||||
            const websocket = new WebSocket(`${protocol}://${host}/webrtc/music?name=${username}`)
 | 
					            const websocket = new WebSocket(`${protocol}://${host}/webrtc/music?name=${username}`)
 | 
				
			||||||
            websocket.onmessage = async event => {
 | 
					            websocket.onmessage = async event => {
 | 
				
			||||||
                const data = JSON.parse(event.data)
 | 
					                const data = JSON.parse(event.data)
 | 
				
			||||||
                const webrtc_init = () => {
 | 
					                const webrtc_init = async () => {
 | 
				
			||||||
                    const webrtc = new RTCPeerConnection({
 | 
					                    const webrtc = new RTCPeerConnection({
 | 
				
			||||||
                        iceServers: [{
 | 
					                        iceServers: [{
 | 
				
			||||||
                            urls: 'turn:satori.love:3478',
 | 
					                            urls: 'turn:satori.love:3478',
 | 
				
			||||||
                            username: 'your-username',
 | 
					                            username: '',   // 'your-username',
 | 
				
			||||||
                            credential: 'your-password',
 | 
					                            credential: '', // await crypto.subtle.digest('SHA-1', new TextEncoder().encode('your-password')),
 | 
				
			||||||
                            credentialType: 'password'
 | 
					                            credentialType: 'password'
 | 
				
			||||||
                        }]
 | 
					                        }]
 | 
				
			||||||
                    })
 | 
					                    })
 | 
				
			||||||
@@ -73,7 +73,7 @@ export default class ClientList {
 | 
				
			|||||||
                }
 | 
					                }
 | 
				
			||||||
                if (data.type === 'list') {
 | 
					                if (data.type === 'list') {
 | 
				
			||||||
                    //console.log('取得在线对端列表:', data)
 | 
					                    //console.log('取得在线对端列表:', data)
 | 
				
			||||||
                    const { webrtc, channels } = webrtc_init()
 | 
					                    const { webrtc, channels } = await webrtc_init()
 | 
				
			||||||
                    //console.log('发送给对方 offer')
 | 
					                    //console.log('发送给对方 offer')
 | 
				
			||||||
                    const offer = await webrtc.createOffer()
 | 
					                    const offer = await webrtc.createOffer()
 | 
				
			||||||
                    await webrtc.setLocalDescription(offer)
 | 
					                    await webrtc.setLocalDescription(offer)
 | 
				
			||||||
@@ -92,7 +92,7 @@ export default class ClientList {
 | 
				
			|||||||
                }
 | 
					                }
 | 
				
			||||||
                if (data.type === 'offer') {
 | 
					                if (data.type === 'offer') {
 | 
				
			||||||
                    //console.log('收到对方 offer', data)
 | 
					                    //console.log('收到对方 offer', data)
 | 
				
			||||||
                    const { webrtc, channels } = 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 })
 | 
				
			||||||
                    //console.log('发送给对方 answer')
 | 
					                    //console.log('发送给对方 answer')
 | 
				
			||||||
                    await webrtc.setRemoteDescription(data.offer)
 | 
					                    await webrtc.setRemoteDescription(data.offer)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user