add test turn (#3236)
* add test turn * removed stun * add ice candidates buffer and removed config to another socket event * removed config from NEW_AGENTS * changed WEBRTC_CONFIG event receiver * fixed error * fixed errors * add buffer cleaning
This commit is contained in:
parent
f61c5e99b5
commit
c27213c65d
6 changed files with 525 additions and 394 deletions
|
|
@ -26,7 +26,8 @@ EVENTS_DEFINITION.emit = {
|
||||||
NO_SESSIONS: "SESSION_DISCONNECTED",
|
NO_SESSIONS: "SESSION_DISCONNECTED",
|
||||||
SESSION_ALREADY_CONNECTED: "SESSION_ALREADY_CONNECTED",
|
SESSION_ALREADY_CONNECTED: "SESSION_ALREADY_CONNECTED",
|
||||||
SESSION_RECONNECTED: "SESSION_RECONNECTED",
|
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 = {
|
const BASE_sessionInfo = {
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ const findSessionSocketId = async (io, roomId, tabId) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
async function getRoomData(io, roomID) {
|
async function getRoomData(io, roomID) {
|
||||||
let tabsCount = 0, agentsCount = 0, tabIDs = [], agentIDs = [];
|
let tabsCount = 0, agentsCount = 0, tabIDs = [], agentIDs = [], config = null;
|
||||||
const connected_sockets = await io.in(roomID).fetchSockets();
|
const connected_sockets = await io.in(roomID).fetchSockets();
|
||||||
if (connected_sockets.length > 0) {
|
if (connected_sockets.length > 0) {
|
||||||
for (let socket of connected_sockets) {
|
for (let socket of connected_sockets) {
|
||||||
|
|
@ -52,13 +52,16 @@ async function getRoomData(io, roomID) {
|
||||||
} else {
|
} else {
|
||||||
agentsCount++;
|
agentsCount++;
|
||||||
agentIDs.push(socket.id);
|
agentIDs.push(socket.id);
|
||||||
|
if (socket.handshake.query.config !== undefined) {
|
||||||
|
config = socket.handshake.query.config;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
tabsCount = -1;
|
tabsCount = -1;
|
||||||
agentsCount = -1;
|
agentsCount = -1;
|
||||||
}
|
}
|
||||||
return {tabsCount, agentsCount, tabIDs, agentIDs};
|
return {tabsCount, agentsCount, tabIDs, agentIDs, config};
|
||||||
}
|
}
|
||||||
|
|
||||||
function processNewSocket(socket) {
|
function processNewSocket(socket) {
|
||||||
|
|
@ -78,7 +81,7 @@ async function onConnect(socket) {
|
||||||
IncreaseOnlineConnections(socket.handshake.query.identity);
|
IncreaseOnlineConnections(socket.handshake.query.identity);
|
||||||
|
|
||||||
const io = getServer();
|
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) {
|
if (socket.handshake.query.identity === IDENTITIES.session) {
|
||||||
// Check if session with the same tabID already connected, if so, refuse new connexion
|
// Check if session with the same tabID already connected, if so, refuse new connexion
|
||||||
|
|
@ -100,6 +103,7 @@ async function onConnect(socket) {
|
||||||
// Inform all connected agents about reconnected session
|
// Inform all connected agents about reconnected session
|
||||||
if (agentsCount > 0) {
|
if (agentsCount > 0) {
|
||||||
logger.debug(`notifying new session about agent-existence`);
|
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);
|
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);
|
socket.to(socket.handshake.query.roomId).emit(EVENTS_DEFINITION.emit.SESSION_RECONNECTED, socket.id);
|
||||||
}
|
}
|
||||||
|
|
@ -118,7 +122,8 @@ async function onConnect(socket) {
|
||||||
// Stats
|
// Stats
|
||||||
startAssist(socket, socket.handshake.query.agentID);
|
startAssist(socket, socket.handshake.query.agentID);
|
||||||
}
|
}
|
||||||
socket.to(socket.handshake.query.roomId).emit(EVENTS_DEFINITION.emit.NEW_AGENT, socket.id, { ...socket.handshake.query.agentInfo, config: socket.handshake.query.config });
|
io.to(socket.handshake.query.roomId).emit(EVENTS_DEFINITION.emit.WEBRTC_CONFIG, socket.handshake.query.config);
|
||||||
|
socket.to(socket.handshake.query.roomId).emit(EVENTS_DEFINITION.emit.NEW_AGENT, socket.id, { ...socket.handshake.query.agentInfo });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set disconnect handler
|
// Set disconnect handler
|
||||||
|
|
|
||||||
|
|
@ -375,7 +375,7 @@ export default class AssistManager {
|
||||||
'stun:stun1.l.google.com:19302',
|
'stun:stun1.l.google.com:19302',
|
||||||
'stun:stun2.l.google.com:19302',
|
'stun:stun2.l.google.com:19302',
|
||||||
'stun:stun3.l.google.com:19302',
|
'stun:stun3.l.google.com:19302',
|
||||||
'stun:stun4.l.google.com:19302'
|
'stun:stun4.l.google.com:19302',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
] as RTCIceServer[];
|
] as RTCIceServer[];
|
||||||
|
|
|
||||||
|
|
@ -365,10 +365,7 @@ export default class Call {
|
||||||
const pc = this.connections[callId];
|
const pc = this.connections[callId];
|
||||||
if (!pc) return;
|
if (!pc) return;
|
||||||
// if there are ice candidates then add candidate to peer
|
// if there are ice candidates then add candidate to peer
|
||||||
if (
|
if (data.candidate) {
|
||||||
data.candidate &&
|
|
||||||
(data.candidate.sdpMid || data.candidate.sdpMLineIndex !== null)
|
|
||||||
) {
|
|
||||||
try {
|
try {
|
||||||
await pc.addIceCandidate(new RTCIceCandidate(data.candidate));
|
await pc.addIceCandidate(new RTCIceCandidate(data.candidate));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
||||||
Binary file not shown.
File diff suppressed because it is too large
Load diff
Loading…
Add table
Reference in a new issue