Skip to content

Commit 633de51

Browse files
author
Aidan Zimmermann
committed
STREAM-1034: add check for fromUserId for observer
1 parent 7c8408d commit 633de51

2 files changed

Lines changed: 33 additions & 9 deletions

File tree

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 observer (fromUserId matches current user)
33+
if (pendingSession.fromUserId === this.sdk._personDetails?.id) {
34+
this._liveMonitoringObserver = true;
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: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,32 @@ describe('handlePropose', () => {
5656
expect(superSpy).not.toHaveBeenCalled();
5757
});
5858

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

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

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);
6683
expect(proceedSpy).not.toHaveBeenCalled();
67-
expect(superSpy).toHaveBeenCalled();
84+
expect(superSpy).toHaveBeenCalledWith(pendingSession);
6885
});
6986
});
7087

@@ -105,14 +122,15 @@ describe('acceptSession', () => {
105122
expect(superAcceptSessionSpy).toHaveBeenCalledWith(session, params);
106123
});
107124

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

111129
await handler.acceptSession(session as any, params);
112130

113-
expect(handler._liveMonitoringObserver).toBe(false);
114-
expect(acceptSessionForTargetSpy).toHaveBeenCalledWith(session, params);
115-
expect(acceptSessionForObserverSpy).not.toHaveBeenCalled();
131+
expect(handler._liveMonitoringObserver).toBe(true);
132+
expect(acceptSessionForObserverSpy).toHaveBeenCalledWith(session, params);
133+
expect(acceptSessionForTargetSpy).not.toHaveBeenCalled();
116134
expect(superAcceptSessionSpy).toHaveBeenCalledWith(session, params);
117135
});
118136
});

0 commit comments

Comments
 (0)