From 63c53bbb36d6befba24b66d2c7bd40c22edffd37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A7=89?= Date: Sun, 1 Oct 2023 14:19:38 +0800 Subject: [PATCH] TURN DEBUG --- index.js | 11 ++++++----- public/client.js | 10 +++++----- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index c137240..0811277 100644 --- a/index.js +++ b/index.js @@ -5,11 +5,12 @@ import { exec } from 'child_process' // 创建 TURN 服务器 const turnServer = new turn({ - authMech: 'long-term', - credentials: { - username: 'your-username', - password: 'your-password', - }, + //authMech: 'long-term', + //credentials: { + // username: 'your-username', + // password: 'your-password', + //}, + authMech: 'none', debugLevel: 'ALL', listeningIps: ['0.0.0.0'], listeningPort: 3478, diff --git a/public/client.js b/public/client.js index 49a024e..ddb0932 100644 --- a/public/client.js +++ b/public/client.js @@ -15,12 +15,12 @@ export default class ClientList { const websocket = new WebSocket(`${protocol}://${host}/webrtc/music?name=${username}`) websocket.onmessage = async event => { const data = JSON.parse(event.data) - const webrtc_init = () => { + const webrtc_init = async () => { const webrtc = new RTCPeerConnection({ iceServers: [{ urls: 'turn:satori.love:3478', - username: 'your-username', - credential: 'your-password', + username: '', // 'your-username', + credential: '', // await crypto.subtle.digest('SHA-1', new TextEncoder().encode('your-password')), credentialType: 'password' }] }) @@ -73,7 +73,7 @@ export default class ClientList { } if (data.type === 'list') { //console.log('取得在线对端列表:', data) - const { webrtc, channels } = webrtc_init() + const { webrtc, channels } = await webrtc_init() //console.log('发送给对方 offer') const offer = await webrtc.createOffer() await webrtc.setLocalDescription(offer) @@ -92,7 +92,7 @@ export default class ClientList { } if (data.type === 'offer') { //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 }) //console.log('发送给对方 answer') await webrtc.setRemoteDescription(data.offer)