fix(assist): fixed broken assist stats
This commit is contained in:
parent
938914be99
commit
f2b40f4622
2 changed files with 51 additions and 51 deletions
|
|
@ -30,12 +30,12 @@ const error_log = process.env.ERROR === "1";
|
||||||
const findSessionSocketId = async (io, roomId, tabId) => {
|
const findSessionSocketId = async (io, roomId, tabId) => {
|
||||||
let pickFirstSession = tabId === undefined;
|
let pickFirstSession = tabId === undefined;
|
||||||
const connected_sockets = await io.in(roomId).fetchSockets();
|
const connected_sockets = await io.in(roomId).fetchSockets();
|
||||||
for (let item of connected_sockets) {
|
for (let socket of connected_sockets) {
|
||||||
if (item.handshake.query.identity === IDENTITIES.session) {
|
if (socket.handshake.query.identity === IDENTITIES.session) {
|
||||||
if (pickFirstSession) {
|
if (pickFirstSession) {
|
||||||
return item.id;
|
return socket.id;
|
||||||
} else if (item.tabId === tabId) {
|
} else if (socket.handshake.query.tabId === tabId) {
|
||||||
return item.id;
|
return socket.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -46,13 +46,13 @@ async function getRoomData(io, roomID) {
|
||||||
let tabsCount = 0, agentsCount = 0, tabIDs = [], agentIDs = [];
|
let tabsCount = 0, agentsCount = 0, tabIDs = [], agentIDs = [];
|
||||||
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 sock of connected_sockets) {
|
for (let socket of connected_sockets) {
|
||||||
if (sock.handshake.query.identity === IDENTITIES.session) {
|
if (socket.handshake.query.identity === IDENTITIES.session) {
|
||||||
tabsCount++;
|
tabsCount++;
|
||||||
tabIDs.push(sock.tabId);
|
tabIDs.push(socket.handshake.query.tabId);
|
||||||
} else {
|
} else {
|
||||||
agentsCount++;
|
agentsCount++;
|
||||||
agentIDs.push(sock.id);
|
agentIDs.push(socket.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -50,10 +50,10 @@ async function postData(payload) {
|
||||||
|
|
||||||
function startAssist(socket, agentID) {
|
function startAssist(socket, agentID) {
|
||||||
const tsNow = +new Date();
|
const tsNow = +new Date();
|
||||||
const eventID = `${socket.sessId}_${agentID}_assist_${tsNow}`;
|
const eventID = `${socket.handshake.query.sessId}_${agentID}_assist_${tsNow}`;
|
||||||
void postData({
|
void postData({
|
||||||
"project_id": socket.projectId,
|
"project_id": socket.handshake.query.projectId,
|
||||||
"session_id": socket.sessId,
|
"session_id": socket.handshake.query.sessId,
|
||||||
"agent_id": agentID,
|
"agent_id": agentID,
|
||||||
"event_id": eventID,
|
"event_id": eventID,
|
||||||
"event_type": "assist",
|
"event_type": "assist",
|
||||||
|
|
@ -61,20 +61,20 @@ function startAssist(socket, agentID) {
|
||||||
"timestamp": tsNow,
|
"timestamp": tsNow,
|
||||||
});
|
});
|
||||||
// Save uniq eventID to cache
|
// Save uniq eventID to cache
|
||||||
cache.set(`${socket.sessId}_${agentID}_assist`, eventID);
|
cache.set(`${socket.handshake.query.sessId}_${agentID}_assist`, eventID);
|
||||||
// Debug log
|
// Debug log
|
||||||
debug && console.log(`assist_started, agentID: ${agentID}, sessID: ${socket.sessId}, projID: ${socket.projectId}, time: ${tsNow}`);
|
debug && console.log(`assist_started, agentID: ${agentID}, sessID: ${socket.handshake.query.sessId}, projID: ${socket.handshake.query.projectId}, time: ${tsNow}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function endAssist(socket, agentID) {
|
function endAssist(socket, agentID) {
|
||||||
const eventID = cache.get(`${socket.sessId}_${agentID}_assist`);
|
const eventID = cache.get(`${socket.handshake.query.sessId}_${agentID}_assist`);
|
||||||
if (eventID === undefined) {
|
if (eventID === undefined) {
|
||||||
debug && console.log(`have to skip assist_ended, no eventID in the cache, agentID: ${socket.agentID}, sessID: ${socket.sessId}, projID: ${socket.projectId}`);
|
debug && console.log(`have to skip assist_ended, no eventID in the cache, agentID: ${socket.handshake.query.agentID}, sessID: ${socket.handshake.query.sessId}, projID: ${socket.handshake.query.projectId}`);
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
void postData({
|
void postData({
|
||||||
"project_id": socket.projectId,
|
"project_id": socket.handshake.query.projectId,
|
||||||
"session_id": socket.sessId,
|
"session_id": socket.handshake.query.sessId,
|
||||||
"agent_id": agentID,
|
"agent_id": agentID,
|
||||||
"event_id": eventID,
|
"event_id": eventID,
|
||||||
"event_type": "assist",
|
"event_type": "assist",
|
||||||
|
|
@ -82,17 +82,17 @@ function endAssist(socket, agentID) {
|
||||||
"timestamp": +new Date(),
|
"timestamp": +new Date(),
|
||||||
})
|
})
|
||||||
// Remove eventID from cache
|
// Remove eventID from cache
|
||||||
cache.delete(`${socket.sessId}_${agentID}_assist`);
|
cache.delete(`${socket.handshake.query.sessId}_${agentID}_assist`);
|
||||||
// Debug logs
|
// Debug logs
|
||||||
debug && console.log(`assist_ended, agentID: ${socket.agentID}, sessID: ${socket.sessId}, projID: ${socket.projectId}`);
|
debug && console.log(`assist_ended, agentID: ${socket.handshake.query.agentID}, sessID: ${socket.handshake.query.sessId}, projID: ${socket.handshake.query.projectId}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function startCall(socket, agentID) {
|
function startCall(socket, agentID) {
|
||||||
const tsNow = +new Date();
|
const tsNow = +new Date();
|
||||||
const eventID = `${socket.sessId}_${agentID}_call_${tsNow}`;
|
const eventID = `${socket.handshake.query.sessId}_${agentID}_call_${tsNow}`;
|
||||||
void postData({
|
void postData({
|
||||||
"project_id": socket.projectId,
|
"project_id": socket.handshake.query.projectId,
|
||||||
"session_id": socket.sessId,
|
"session_id": socket.handshake.query.sessId,
|
||||||
"agent_id": agentID,
|
"agent_id": agentID,
|
||||||
"event_id": eventID,
|
"event_id": eventID,
|
||||||
"event_type": "call",
|
"event_type": "call",
|
||||||
|
|
@ -100,102 +100,102 @@ function startCall(socket, agentID) {
|
||||||
"timestamp": tsNow,
|
"timestamp": tsNow,
|
||||||
});
|
});
|
||||||
// Save uniq eventID to cache
|
// Save uniq eventID to cache
|
||||||
cache.set(`${socket.sessId}_call`, eventID);
|
cache.set(`${socket.handshake.query.sessId}_call`, eventID);
|
||||||
// Debug logs
|
// Debug logs
|
||||||
debug && console.log(`s_call_started, agentID: ${agentID}, sessID: ${socket.sessId}, projID: ${socket.projectId}, time: ${tsNow}`);
|
debug && console.log(`s_call_started, agentID: ${agentID}, sessID: ${socket.handshake.query.sessId}, projID: ${socket.handshake.query.projectId}, time: ${tsNow}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function endCall(socket, agentID) {
|
function endCall(socket, agentID) {
|
||||||
const tsNow = +new Date();
|
const tsNow = +new Date();
|
||||||
const eventID = cache.get(`${socket.sessId}_call`);
|
const eventID = cache.get(`${socket.handshake.query.sessId}_call`);
|
||||||
if (eventID === undefined) {
|
if (eventID === undefined) {
|
||||||
debug && console.log(`have to skip s_call_ended, no eventID in the cache, agentID: ${agentID}, sessID: ${socket.sessId}, projID: ${socket.projectId}, time: ${tsNow}`);
|
debug && console.log(`have to skip s_call_ended, no eventID in the cache, agentID: ${agentID}, sessID: ${socket.handshake.query.sessId}, projID: ${socket.handshake.query.projectId}, time: ${tsNow}`);
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
void postData({
|
void postData({
|
||||||
"project_id": socket.projectId,
|
"project_id": socket.handshake.query.projectId,
|
||||||
"session_id": socket.sessId,
|
"session_id": socket.handshake.query.sessId,
|
||||||
"agent_id": agentID,
|
"agent_id": agentID,
|
||||||
"event_id": eventID,
|
"event_id": eventID,
|
||||||
"event_type": "call",
|
"event_type": "call",
|
||||||
"event_state": "end",
|
"event_state": "end",
|
||||||
"timestamp": tsNow,
|
"timestamp": tsNow,
|
||||||
});
|
});
|
||||||
cache.delete(`${socket.sessId}_call`)
|
cache.delete(`${socket.handshake.query.sessId}_call`)
|
||||||
// Debug logs
|
// Debug logs
|
||||||
debug && console.log(`s_call_ended, agentID: ${agentID}, sessID: ${socket.sessId}, projID: ${socket.projectId}, time: ${tsNow}`);
|
debug && console.log(`s_call_ended, agentID: ${agentID}, sessID: ${socket.handshake.query.sessId}, projID: ${socket.handshake.query.projectId}, time: ${tsNow}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function startControl(socket, agentID) {
|
function startControl(socket, agentID) {
|
||||||
const tsNow = +new Date();
|
const tsNow = +new Date();
|
||||||
const eventID = `${socket.sessId}_${agentID}_control_${tsNow}`;
|
const eventID = `${socket.handshake.query.sessId}_${agentID}_control_${tsNow}`;
|
||||||
void postData({
|
void postData({
|
||||||
"project_id": socket.projectId,
|
"project_id": socket.handshake.query.projectId,
|
||||||
"session_id": socket.sessId,
|
"session_id": socket.handshake.query.sessId,
|
||||||
"agent_id": agentID,
|
"agent_id": agentID,
|
||||||
"event_id": eventID,
|
"event_id": eventID,
|
||||||
"event_type": "control",
|
"event_type": "control",
|
||||||
"event_state": "start",
|
"event_state": "start",
|
||||||
"timestamp": tsNow,
|
"timestamp": tsNow,
|
||||||
});
|
});
|
||||||
cache.set(`${socket.sessId}_control`, eventID)
|
cache.set(`${socket.handshake.query.sessId}_control`, eventID)
|
||||||
// Debug logs
|
// Debug logs
|
||||||
debug && console.log(`s_control_started, agentID: ${agentID}, sessID: ${socket.sessId}, projID: ${socket.projectId}, time: ${+new Date()}`);
|
debug && console.log(`s_control_started, agentID: ${agentID}, sessID: ${socket.handshake.query.sessId}, projID: ${socket.handshake.query.projectId}, time: ${+new Date()}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function endControl(socket, agentID) {
|
function endControl(socket, agentID) {
|
||||||
const tsNow = +new Date();
|
const tsNow = +new Date();
|
||||||
const eventID = cache.get(`${socket.sessId}_control`);
|
const eventID = cache.get(`${socket.handshake.query.sessId}_control`);
|
||||||
if (eventID === undefined) {
|
if (eventID === undefined) {
|
||||||
debug && console.log(`have to skip s_control_ended, no eventID in the cache, agentID: ${agentID}, sessID: ${socket.sessId}, projID: ${socket.projectId}, time: ${tsNow}`);
|
debug && console.log(`have to skip s_control_ended, no eventID in the cache, agentID: ${agentID}, sessID: ${socket.handshake.query.sessId}, projID: ${socket.handshake.query.projectId}, time: ${tsNow}`);
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
void postData({
|
void postData({
|
||||||
"project_id": socket.projectId,
|
"project_id": socket.handshake.query.projectId,
|
||||||
"session_id": socket.sessId,
|
"session_id": socket.handshake.query.sessId,
|
||||||
"agent_id": agentID,
|
"agent_id": agentID,
|
||||||
"event_id": eventID,
|
"event_id": eventID,
|
||||||
"event_type": "control",
|
"event_type": "control",
|
||||||
"event_state": "end",
|
"event_state": "end",
|
||||||
"timestamp": tsNow,
|
"timestamp": tsNow,
|
||||||
});
|
});
|
||||||
cache.delete(`${socket.sessId}_control`)
|
cache.delete(`${socket.handshake.query.sessId}_control`)
|
||||||
// Debug logs
|
// Debug logs
|
||||||
debug && console.log(`s_control_ended, agentID: ${agentID}, sessID: ${socket.sessId}, projID: ${socket.projectId}, time: ${+new Date()}`);
|
debug && console.log(`s_control_ended, agentID: ${agentID}, sessID: ${socket.handshake.query.sessId}, projID: ${socket.handshake.query.projectId}, time: ${+new Date()}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function startRecord(socket, agentID) {
|
function startRecord(socket, agentID) {
|
||||||
const tsNow = +new Date();
|
const tsNow = +new Date();
|
||||||
const eventID = `${socket.sessId}_${agentID}_record_${tsNow}`;
|
const eventID = `${socket.handshake.query.sessId}_${agentID}_record_${tsNow}`;
|
||||||
void postData({
|
void postData({
|
||||||
"project_id": socket.projectId,
|
"project_id": socket.handshake.query.projectId,
|
||||||
"session_id": socket.sessId,
|
"session_id": socket.handshake.query.sessId,
|
||||||
"agent_id": agentID,
|
"agent_id": agentID,
|
||||||
"event_id": eventID,
|
"event_id": eventID,
|
||||||
"event_type": "record",
|
"event_type": "record",
|
||||||
"event_state": "start",
|
"event_state": "start",
|
||||||
"timestamp": tsNow,
|
"timestamp": tsNow,
|
||||||
});
|
});
|
||||||
cache.set(`${socket.sessId}_record`, eventID)
|
cache.set(`${socket.handshake.query.sessId}_record`, eventID)
|
||||||
// Debug logs
|
// Debug logs
|
||||||
debug && console.log(`s_recording_started, agentID: ${agentID}, sessID: ${socket.sessId}, projID: ${socket.projectId}, time: ${+new Date()}`);
|
debug && console.log(`s_recording_started, agentID: ${agentID}, sessID: ${socket.handshake.query.sessId}, projID: ${socket.handshake.query.projectId}, time: ${+new Date()}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function endRecord(socket, agentID) {
|
function endRecord(socket, agentID) {
|
||||||
const tsNow = +new Date();
|
const tsNow = +new Date();
|
||||||
const eventID = cache.get(`${socket.sessId}_record`);
|
const eventID = cache.get(`${socket.sessId}_record`);
|
||||||
void postData({
|
void postData({
|
||||||
"project_id": socket.projectId,
|
"project_id": socket.handshake.query.projectId,
|
||||||
"session_id": socket.sessId,
|
"session_id": socket.handshake.query.sessId,
|
||||||
"agent_id": agentID,
|
"agent_id": agentID,
|
||||||
"event_id": eventID,
|
"event_id": eventID,
|
||||||
"event_type": "record",
|
"event_type": "record",
|
||||||
"event_state": "end",
|
"event_state": "end",
|
||||||
"timestamp": tsNow,
|
"timestamp": tsNow,
|
||||||
});
|
});
|
||||||
cache.delete(`${socket.sessId}_record`)
|
cache.delete(`${socket.handshake.query.sessId}_record`)
|
||||||
// Debug logs
|
// Debug logs
|
||||||
debug && console.log(`s_recording_ended, agentID: ${agentID}, sessID: ${socket.sessId}, projID: ${socket.projectId}, time: ${+new Date()}`);
|
debug && console.log(`s_recording_ended, agentID: ${agentID}, sessID: ${socket.handshake.query.sessId}, projID: ${socket.handshake.query.projectId}, time: ${+new Date()}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleEvent(eventName, socket, agentID) {
|
function handleEvent(eventName, socket, agentID) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue