Merge pull request 'LINXD-2842-log-protocol-change' (#36) from LINXD-2842-log-protocol-change into develop

Reviewed-on: #36
Reviewed-by: Cristi Ene <cristi.ene@safemobile.com>
This commit is contained in:
Sergiu Toma 2025-03-05 21:40:24 +00:00
commit dd5af12c7c
5 changed files with 1153 additions and 50 deletions

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

30
app.js
View File

@ -12,6 +12,11 @@ try {
console.log('https support is disabled!');
}
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';
const isTcpPreferred = process.env.PREFER_TCP === 'true';
let currentConnectionType = isUdpPreferred ? 'udp' : 'tcp';
let worker;
/**
@ -555,14 +560,33 @@ const createWebRtcTransportLayer = async (callId, callback) => {
announcedIp: process.env.ANNOUNCED_IP, // Announced IPv4 or IPv6 (useful when running mediasoup behind NAT with private IP).
},
],
enableUdp: process.env.ENABLE_UDP === 'true',
enableTcp: process.env.ENABLE_TCP === 'true',
preferUdp: process.env.PREFER_UDP === 'true',
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;
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) => {
console.log(`transport | dtlsstatechange | calldId ${callId} | dtlsState ${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",