add ice candidates buffer and removed config to another socket event

This commit is contained in:
Андрей Бабушкин 2025-03-31 17:21:48 +02:00
parent aff0a96f15
commit eb1f95017b
7 changed files with 529 additions and 396 deletions

View file

@ -26,7 +26,8 @@ EVENTS_DEFINITION.emit = {
NO_SESSIONS: "SESSION_DISCONNECTED",
SESSION_ALREADY_CONNECTED: "SESSION_ALREADY_CONNECTED",
SESSION_RECONNECTED: "SESSION_RECONNECTED",
UPDATE_EVENT: EVENTS_DEFINITION.listen.UPDATE_EVENT
UPDATE_EVENT: EVENTS_DEFINITION.listen.UPDATE_EVENT,
WEBRTC_CONFIG: "WEBRTC_CONFIG",
};
const BASE_sessionInfo = {

View file

@ -42,7 +42,7 @@ const findSessionSocketId = async (io, roomId, tabId) => {
};
async function getRoomData(io, roomID) {
let tabsCount = 0, agentsCount = 0, tabIDs = [], agentIDs = [];
let tabsCount = 0, agentsCount = 0, tabIDs = [], agentIDs = [], agentsInfo = [], config = null;
const connected_sockets = await io.in(roomID).fetchSockets();
if (connected_sockets.length > 0) {
for (let socket of connected_sockets) {
@ -52,13 +52,17 @@ async function getRoomData(io, roomID) {
} else {
agentsCount++;
agentIDs.push(socket.id);
agentsInfo.push(socket.handshake.query.agentInfo);
if (socket.handshake.query.config !== undefined) {
config = socket.handshake.query.config;
}
}
}
} else {
tabsCount = -1;
agentsCount = -1;
}
return {tabsCount, agentsCount, tabIDs, agentIDs};
return {tabsCount, agentsCount, tabIDs, agentIDs, agentsInfo, config};
}
function processNewSocket(socket) {
@ -78,7 +82,7 @@ async function onConnect(socket) {
IncreaseOnlineConnections(socket.handshake.query.identity);
const io = getServer();
const {tabsCount, agentsCount, tabIDs, agentIDs} = await getRoomData(io, socket.handshake.query.roomId);
const {tabsCount, agentsCount, tabIDs, agentIDs, config} = await getRoomData(io, socket.handshake.query.roomId);
if (socket.handshake.query.identity === IDENTITIES.session) {
// Check if session with the same tabID already connected, if so, refuse new connexion
@ -100,6 +104,7 @@ async function onConnect(socket) {
// Inform all connected agents about reconnected session
if (agentsCount > 0) {
logger.debug(`notifying new session about agent-existence`);
io.to(socket.id).emit(EVENTS_DEFINITION.emit.WEBRTC_CONFIG, config);
io.to(socket.id).emit(EVENTS_DEFINITION.emit.AGENTS_CONNECTED, agentIDs);
socket.to(socket.handshake.query.roomId).emit(EVENTS_DEFINITION.emit.SESSION_RECONNECTED, socket.id);
}

View file

@ -369,19 +369,19 @@ export default class AssistManager {
return this.config;
}
return [
// {
// urls: [
// 'stun:stun.l.google.com:19302',
// 'stun:stun1.l.google.com:19302',
// 'stun:stun2.l.google.com:19302',
// 'stun:stun3.l.google.com:19302',
// 'stun:stun4.l.google.com:19302',
// ],
// },
{
urls: 'turn:global.relay.metered.ca:443',
username: 'e63d65356e9516340ab2199d',
credential: 'aMREG9wSfzxdT6rD',
urls: [
'stun:stun.l.google.com:19302',
'stun:stun1.l.google.com:19302',
'stun:stun2.l.google.com:19302',
'stun:stun3.l.google.com:19302',
'stun:stun4.l.google.com:19302',
],
},
{
urls: 'turn:turn.openreplay.com:443?transport=udp',
username: '1743592972:Bd6D7C671f5d47382EcafB9d3d4Db4b80f21',
credential: 'qpyYRCfxOLLFIQAxiHf3Gpj/JW0=',
},
] as RTCIceServer[];
};

View file

@ -147,6 +147,7 @@ export default class Call {
const pc = new RTCPeerConnection({
iceServers: this.config,
iceTransportPolicy: 'relay',
});
// If there is a local stream, add its tracks to the connection
@ -365,10 +366,7 @@ export default class Call {
const pc = this.connections[callId];
if (!pc) return;
// if there are ice candidates then add candidate to peer
if (
data.candidate &&
(data.candidate.sdpMid || data.candidate.sdpMLineIndex !== null)
) {
if (data.candidate) {
try {
await pc.addIceCandidate(new RTCIceCandidate(data.candidate));
} catch (e) {

View file

@ -69,6 +69,7 @@ export default class CanvasReceiver {
iceServers: this.config
? this.config
: [{ urls: 'stun:stun.l.google.com:19302' }],
iceTransportPolicy: 'relay',
});
// Save the connection

File diff suppressed because it is too large Load diff