Skip to content

Commit cdc72ad

Browse files
authored
Merge pull request #971 from MyPureCloud/STREAM-1034
STREAM-1034: jwt support for live-monitoring
2 parents 1ec3b20 + 4e35de6 commit cdc72ad

4 files changed

Lines changed: 41 additions & 13 deletions

File tree

changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
44
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
55

66
# [Unreleased](https://github.com/MyPureCloud/genesys-cloud-webrtc-sdk/compare/v11.5.0...HEAD)
7+
### Added
8+
* [STREAM-1034](https://inindca.atlassian.net/browse/STREAM-1034) - Added JWT support for live monitoring sessions
79

810
### Changed
911
* [STREAM-1122](https://inindca.atlassian.net/browse/STREAM-1122) - Bump streaming-client to v19.5.0.

src/client.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,10 @@ export class GenesysCloudWebrtcSdk extends (EventEmitter as { new(): StrictEvent
145145

146146
let allowedSessionTypes = options.allowedSessionTypes || [SessionTypes.softphone, SessionTypes.collaborateVideo, SessionTypes.acdScreenShare, SessionTypes.liveScreenMonitoring];
147147

148-
// If using JWT auth, we only support screen recording and video conferencing.
148+
// If using JWT auth, we only support screen recording, video conferencing and live screen monitoring.
149149
if (options.jwt) {
150-
console.debug(`Forcing allowed session types to be ${SessionTypes.screenRecording} and ${SessionTypes.collaborateVideo} due to jwt auth`);
151-
allowedSessionTypes = [ SessionTypes.screenRecording, SessionTypes.collaborateVideo ];
150+
console.debug(`Forcing allowed session types to be ${SessionTypes.screenRecording}, ${SessionTypes.collaborateVideo} and ${SessionTypes.liveScreenMonitoring} due to jwt auth`);
151+
allowedSessionTypes = [ SessionTypes.screenRecording, SessionTypes.collaborateVideo, SessionTypes.liveScreenMonitoring ];
152152
}
153153

154154
this._config = {

src/sessions/live-monitoring-session-handler.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,19 @@ export class LiveMonitoringSessionHandler extends BaseSessionHandler {
2929
return this.proceedWithSession(pendingSession);
3030
}
3131

32+
// Auto-accept if current user is the target (fromUserId matches current user)
33+
if (pendingSession.fromUserId === this.sdk._personDetails?.id) {
34+
this._liveMonitoringObserver = false;
35+
return this.proceedWithSession(pendingSession);
36+
}
37+
3238
// if not auto accepting sessions, emit this event for the consumer to accept
3339
await super.handlePropose(pendingSession);
3440
}
3541

3642
async acceptSession(session: LiveScreenMonitoringSession, params: IAcceptSessionRequest): Promise<void> {
37-
// Store the liveMonitoringObserver flag
38-
this._liveMonitoringObserver = params.liveMonitoringObserver || false;
43+
// Store the liveMonitoringObserver flag (use existing flag if already set in handlePropose)
44+
this._liveMonitoringObserver = this._liveMonitoringObserver || params.liveMonitoringObserver || false;
3945

4046
if (this._liveMonitoringObserver) {
4147
await this.acceptSessionForObserver(session, params)

test/unit/sessions/live-monitoring-session-handler.test.ts

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import LiveMonitoringSessionHandler from '../../../src/sessions/live-monitoring-
55
import * as utils from '../../../src/utils';
66
import BaseSessionHandler from "../../../src/sessions/base-session-handler";
77
import * as mediaUtils from "../../../src/media/media-utils";
8-
import {IExtendedMediaSession, LiveScreenMonitoringSession, VideoMediaSession} from "../../../src";
8+
import {
9+
LiveScreenMonitoringSession,
10+
} from "../../../src";
911

1012
let handler: LiveMonitoringSessionHandler;
1113
let mockSdk: GenesysCloudWebrtcSdk;
@@ -54,15 +56,32 @@ describe('handlePropose', () => {
5456
expect(superSpy).not.toHaveBeenCalled();
5557
});
5658

57-
it('should not accept session if not autoAcceptPendingLiveScreenMonitoringRequests', async () => {
59+
it('should auto-accept as target when current user is the fromUserId', async () => {
5860
const proceedSpy = jest.spyOn(handler, 'proceedWithSession').mockResolvedValue(null);
5961
const superSpy = jest.spyOn(BaseSessionHandler.prototype, 'handlePropose').mockResolvedValue(null);
6062

6163
mockSdk._config.autoAcceptPendingLiveScreenMonitoringRequests = false;
62-
await handler.handlePropose({} as any);
64+
const pendingSession = { fromUserId: 'user123' } as any;
65+
66+
await handler.handlePropose(pendingSession);
67+
68+
expect(handler._liveMonitoringObserver).toBe(false);
69+
expect(proceedSpy).toHaveBeenCalledWith(pendingSession);
70+
expect(superSpy).not.toHaveBeenCalled();
71+
});
6372

73+
it('should not accept session if not autoAcceptPendingLiveScreenMonitoringRequests and user is not observer', async () => {
74+
const proceedSpy = jest.spyOn(handler, 'proceedWithSession').mockResolvedValue(null);
75+
const superSpy = jest.spyOn(BaseSessionHandler.prototype, 'handlePropose').mockResolvedValue(null);
76+
77+
mockSdk._config.autoAcceptPendingLiveScreenMonitoringRequests = false;
78+
const pendingSession = { fromUserId: 'different-user' } as any;
79+
80+
await handler.handlePropose(pendingSession);
81+
82+
expect(handler._liveMonitoringObserver).toBe(false);
6483
expect(proceedSpy).not.toHaveBeenCalled();
65-
expect(superSpy).toHaveBeenCalled();
84+
expect(superSpy).toHaveBeenCalledWith(pendingSession);
6685
});
6786
});
6887

@@ -103,14 +122,15 @@ describe('acceptSession', () => {
103122
expect(superAcceptSessionSpy).toHaveBeenCalledWith(session, params);
104123
});
105124

106-
it('should default liveMonitoringObserver to false when not provided', async () => {
125+
it('should preserve liveMonitoringObserver flag set in handlePropose', async () => {
107126
const params = { conversationId: session.conversationId };
127+
handler._liveMonitoringObserver = true; // Simulate flag set in handlePropose
108128

109129
await handler.acceptSession(session as any, params);
110130

111-
expect(handler._liveMonitoringObserver).toBe(false);
112-
expect(acceptSessionForTargetSpy).toHaveBeenCalledWith(session, params);
113-
expect(acceptSessionForObserverSpy).not.toHaveBeenCalled();
131+
expect(handler._liveMonitoringObserver).toBe(true);
132+
expect(acceptSessionForObserverSpy).toHaveBeenCalledWith(session, params);
133+
expect(acceptSessionForTargetSpy).not.toHaveBeenCalled();
114134
expect(superAcceptSessionSpy).toHaveBeenCalledWith(session, params);
115135
});
116136
});

0 commit comments

Comments
 (0)