From 184dea26b47e22d9271b274f7f1d9f76a5c976d2 Mon Sep 17 00:00:00 2001 From: nick-delirium Date: Mon, 2 Oct 2023 11:51:05 +0200 Subject: [PATCH] feat(player): add agent id to assist con query --- .../AssistActions/AssistActions.tsx | 27 +++++++++++++++++++ .../ScreenRecorder/ScreenRecorder.tsx | 10 +++++++ .../app/player/web/assist/AssistManager.ts | 10 +++++++ 3 files changed, 47 insertions(+) diff --git a/frontend/app/components/Assist/components/AssistActions/AssistActions.tsx b/frontend/app/components/Assist/components/AssistActions/AssistActions.tsx index 29d2c42a4..666239e09 100644 --- a/frontend/app/components/Assist/components/AssistActions/AssistActions.tsx +++ b/frontend/app/components/Assist/components/AssistActions/AssistActions.tsx @@ -33,8 +33,20 @@ interface Props { isCallActive: boolean; agentIds: string[]; userDisplayName: string; + agentId: number, } +const AssistActionsPing = { + control: { + start: 's_control_started', + end: 's_control_ended' + }, + call: { + start: 's_call_started', + end: 's_call_ended' + }, +} as const + function AssistActions({ userId, hasPermission, @@ -42,6 +54,7 @@ function AssistActions({ isCallActive, agentIds, userDisplayName, + agentId, }: Props) { // @ts-ignore ??? const { player, store } = React.useContext(PlayerContext); @@ -136,6 +149,7 @@ function AssistActions({ lStream, addIncomeStream, () => { + player.assistManager.ping(AssistActionsPing.call.end, agentId) lStream.stop.bind(lStream); }, onReject, @@ -164,11 +178,23 @@ function AssistActions({ }; const requestControl = () => { + if (remoteActive) player.assistManager.ping(AssistActionsPing.control.end, agentId) setRemoteControlCallbacks({ onReject: onControlReject }); if (callRequesting || remoteRequesting) return; requestReleaseRemoteControl(); }; + React.useEffect(() => { + if (remoteActive) { + player.assistManager.ping(AssistActionsPing.control.start, agentId) + } + }, [remoteActive]) + React.useEffect(() => { + if (onCall) { + player.assistManager.ping(AssistActionsPing.call.start, agentId) + } + }, [onCall]) + return (
{(onCall || remoteActive) && ( @@ -262,6 +288,7 @@ const con = connect((state: any) => { hasPermission: permissions.includes('ASSIST_CALL'), isEnterprise: state.getIn(['user', 'account', 'edition']) === 'ee', userDisplayName: state.getIn(['sessions', 'current']).userDisplayName, + agentId: state.getIn(['user', 'account', 'id']) }; }); diff --git a/frontend/app/components/Session_/ScreenRecorder/ScreenRecorder.tsx b/frontend/app/components/Session_/ScreenRecorder/ScreenRecorder.tsx index c52377400..707d1d1ed 100644 --- a/frontend/app/components/Session_/ScreenRecorder/ScreenRecorder.tsx +++ b/frontend/app/components/Session_/ScreenRecorder/ScreenRecorder.tsx @@ -34,11 +34,13 @@ const supportedMessage = `Supported Browsers: ${supportedBrowsers.join(', ')}`; function ScreenRecorder({ siteId, sessionId, + agentId, isEnterprise, }: { siteId: string; sessionId: string; isEnterprise: boolean; + agentId: number, }) { const { player, store } = React.useContext(PlayerContext) as ILivePlayerContext; const recordingState = store.get().recordingState; @@ -96,6 +98,7 @@ function ScreenRecorder({ }; const stopRecordingHandler = () => { + player.assistManager.ping('s_recording_ended', agentId) stopRecorderCb?.(); onStop(); }; @@ -105,6 +108,12 @@ function ScreenRecorder({ player.assistManager.requestRecording({ onDeny }); }; + React.useEffect(() => { + if (isRecording) { + player.assistManager.ping('s_recording_started', agentId) + } + }, [isRecording]) + if (!isSupported() || !isEnterprise) { return (
@@ -136,4 +145,5 @@ export default connect((state: any) => ({ isEnterprise: state.getIn(['user', 'account', 'edition']) === 'ee', siteId: state.getIn(['site', 'siteId']), sessionId: state.getIn(['sessions', 'current']).sessionId, + agentId: state.getIn(['user', 'account', 'id']), }))(observer(ScreenRecorder)); diff --git a/frontend/app/player/web/assist/AssistManager.ts b/frontend/app/player/web/assist/AssistManager.ts index a55c481e4..a844cfd73 100644 --- a/frontend/app/player/web/assist/AssistManager.ts +++ b/frontend/app/player/web/assist/AssistManager.ts @@ -25,6 +25,12 @@ export enum ConnectionStatus { Closed, } +type StatsEvent = 's_call_started' + | 's_call_ended' + | 's_control_started' + | 's_control_ended' + | 's_recording_started' + | 's_recording_ended' export function getStatusText(status: ConnectionStatus): string { switch(status) { @@ -272,6 +278,10 @@ export default class AssistManager { }) } + public ping(event: StatsEvent, id: number) { + this.socket?.emit(event, id) + } + /* ==== ScreenRecording ==== */ private screenRecording: ScreenRecording | null = null