LINXD-2842-log-protocol-change #36

Merged
sergiu merged 3 commits from LINXD-2842-log-protocol-change into develop 2025-03-05 21:40:25 +00:00
4 changed files with 1132 additions and 44 deletions
Showing only changes of commit af21774d17 - Show all commits

1
.env
View File

@ -8,3 +8,4 @@ SERVER_KEY="./server/ssl/key.pem"
ENABLE_UDP=true
ENABLE_TCP=true
PREFER_UDP=true
PREFER_TCP=false

21
app.js
View File

@ -15,7 +15,8 @@ const mediasoup = require('mediasoup');
const isUdpEnabled = process.env.ENABLE_UDP === 'true';
const isTcpEnabled = process.env.ENABLE_TCP === 'true';
const isUdpPreferred = process.env.PREFER_UDP === 'true';
let initialConnection = isUdpPreferred ? 'udp' : 'tcp';
const isTcpPreferred = process.env.PREFER_TCP === 'true';
let currentConnectionType = isUdpPreferred ? 'udp' : 'tcp';
let worker;
/**
@ -562,21 +563,29 @@ const createWebRtcTransportLayer = async (callId, callback) => {
enableUdp: isUdpEnabled,
enableTcp: isTcpEnabled,
preferUdp: isUdpPreferred,
preferTcp: isTcpPreferred,
iceConsentTimeout: 3
};
// https://mediasoup.org/documentation/v3/mediasoup/api/#router-createWebRtcTransport
let transport = await videoCalls[callId].router.createWebRtcTransport(webRtcTransport_options);
// `iceselectedtuplechange`: Fires when ICE switches transport (e.g., UDP → TCP).
transport.on('iceselectedtuplechange', (selectedTuple) => {
const { protocol } = selectedTuple;
const switchedTo = protocol === 'udp' ? 'tcp' : 'udp';
if (initialConnection !== protocol) {
console.warn(`⚠️ ${protocol.toUpperCase()} blocked! Switching to ${switchedTo.toUpperCase()} for callId: ${callId}`);
initialConnection = protocol;
if (currentConnectionType !== protocol) {
console.warn(`⚠️ ${currentConnectionType.toUpperCase()} blocked! Switching to ${protocol.toUpperCase()} for callId: ${callId}`);
currentConnectionType = protocol;
}
});
// `icestatechange`: Fires when ICE connection state changes (e.g., new, connected, failed).
transport.on('icestatechange', (iceState) => {
console.log(`[ICE STATE CHANGE] callId: ${callId} | State: ${iceState}`);
if (iceState === 'failed' || iceState === 'disconnected') {
console.warn(`⚠️ ICE failure detected for callId: ${callId}! Possible UDP blockage.`);
}
});
// Handler for when DTLS(Datagram Transport Layer Security) changes
transport.on('dtlsstatechange', (dtlsState) => {

1150
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -16,7 +16,7 @@
"@types/express": "^4.17.13",
"dotenv": "^16.0.1",
"express": "^4.18.1",
"mediasoup": "^3.10.4",
"mediasoup": "^3.15.5",
"mediasoup-client": "^3.6.54",
"parcel": "^2.7.0",
"socket.io": "^2.0.3",