Refactor RTC configuration to use 'all' iceTransportPolicy, reintroduce STUN server URLs, and remove credentialed TURN server handling.

This commit is contained in:
Xin Wang
2026-07-21 22:25:36 +08:00
parent e1f147d773
commit cdecc25bb7

View File

@@ -14,10 +14,13 @@
const $self = {
rtcConfig: {
iceTransportPolicy: 'relay', // TURN only
// WebRTC has no "STUN-only" transport policy. Using `all` with only
// STUN servers configured allows host and server-reflexive candidates,
// while ensuring that no TURN relay candidate can be created.
iceTransportPolicy: 'all',
iceServers: [
// { urls: 'stun:stun.l.google.com:19302' },
// { urls: 'stun:stun1.l.google.com:19302' },
{ urls: 'stun:stun.l.google.com:19302' },
{ urls: 'stun:stun1.l.google.com:19302' },
],
},
mediaConstraints: { audio: true, video: true },
@@ -626,13 +629,10 @@ function handleScConnect() {
console.log(`Self ID: ${$self.id}`);
}
function handleScConnectedPeers({ peers, credentials }) {
function handleScConnectedPeers({ peers }) {
const ids = peers;
console.log(`Connected peer IDs: ${ids.join(', ')}`);
console.log(`TURN Credentials: ${JSON.stringify(credentials)}`);
addCredentialedTurnServer('turn:182.92.86.220:3478', credentials);
for (let id of ids) {
if (id === $self.id) continue;
// be polite with already-connected peers
@@ -736,15 +736,6 @@ async function handleScSignal({ sender,
* Utility Functions
*/
function addCredentialedTurnServer(server_string, { username, password }) {
// Add TURN server and credentials to iceServers array
$self.rtcConfig.iceServers.push({
urls: server_string,
username: username,
credential: password,
});
}
function prepareNamespace(hash, set_location) {
let ns = hash.replace(/^#/, ''); // remove # from the hash
if (/^[a-z]{4}-[a-z]{4}-[a-z]{4}$/.test(ns)) {