parent
1c1a41bb55
commit
c793d9d177
2 changed files with 15 additions and 1 deletions
|
|
@ -10,7 +10,8 @@ const EVENTS_DEFINITION = {
|
||||||
UPDATE_EVENT: "UPDATE_SESSION", // tab become active/inactive, page title change, changed session object (rare case), call start/end
|
UPDATE_EVENT: "UPDATE_SESSION", // tab become active/inactive, page title change, changed session object (rare case), call start/end
|
||||||
CONNECT_ERROR: "connect_error",
|
CONNECT_ERROR: "connect_error",
|
||||||
CONNECT_FAILED: "connect_failed",
|
CONNECT_FAILED: "connect_failed",
|
||||||
ERROR: "error"
|
ERROR: "error",
|
||||||
|
WEBRTC_AGENT_CALL: "WEBRTC_AGENT_CALL",
|
||||||
},
|
},
|
||||||
//The following list of events will be only emitted by the server
|
//The following list of events will be only emitted by the server
|
||||||
server: {
|
server: {
|
||||||
|
|
|
||||||
|
|
@ -127,6 +127,9 @@ async function onConnect(socket) {
|
||||||
// Handle update event
|
// Handle update event
|
||||||
socket.on(EVENTS_DEFINITION.listen.UPDATE_EVENT, (...args) => onUpdateEvent(socket, ...args));
|
socket.on(EVENTS_DEFINITION.listen.UPDATE_EVENT, (...args) => onUpdateEvent(socket, ...args));
|
||||||
|
|
||||||
|
// Handle webrtc events
|
||||||
|
socket.on(EVENTS_DEFINITION.listen.WEBRTC_AGENT_CALL, (...args) => onWebrtcAgentHandler(socket, ...args));
|
||||||
|
|
||||||
// Handle errors
|
// Handle errors
|
||||||
socket.on(EVENTS_DEFINITION.listen.ERROR, err => errorHandler(EVENTS_DEFINITION.listen.ERROR, err));
|
socket.on(EVENTS_DEFINITION.listen.ERROR, err => errorHandler(EVENTS_DEFINITION.listen.ERROR, err));
|
||||||
socket.on(EVENTS_DEFINITION.listen.CONNECT_ERROR, err => errorHandler(EVENTS_DEFINITION.listen.CONNECT_ERROR, err));
|
socket.on(EVENTS_DEFINITION.listen.CONNECT_ERROR, err => errorHandler(EVENTS_DEFINITION.listen.CONNECT_ERROR, err));
|
||||||
|
|
@ -186,6 +189,16 @@ async function onUpdateEvent(socket, ...args) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function onWebrtcAgentHandler(socket, ...args) {
|
||||||
|
if (socket.handshake.query.identity === IDENTITIES.agent) {
|
||||||
|
const agentIdToConnect = args[0]?.data?.toAgentId;
|
||||||
|
logger.debug(`${socket.id} sent webrtc event to agent:${agentIdToConnect}`);
|
||||||
|
if (agentIdToConnect && socket.handshake.sessionData.AGENTS_CONNECTED.includes(agentIdToConnect)) {
|
||||||
|
socket.to(agentIdToConnect).emit(EVENTS_DEFINITION.listen.WEBRTC_AGENT_CALL, args[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function onAny(socket, eventName, ...args) {
|
async function onAny(socket, eventName, ...args) {
|
||||||
if (Object.values(EVENTS_DEFINITION.listen).indexOf(eventName) >= 0) {
|
if (Object.values(EVENTS_DEFINITION.listen).indexOf(eventName) >= 0) {
|
||||||
logger.debug(`received event:${eventName}, should be handled by another listener, stopping onAny.`);
|
logger.debug(`received event:${eventName}, should be handled by another listener, stopping onAny.`);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue