Skip to content

Commit 68e0efe

Browse files
committed
[STREAM-575] Don't emit a pendingSession when we have an activeSession if the conversation update is for the same conversation as the activeSession
1 parent be39d19 commit 68e0efe

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

src/sessions/softphone-session-handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ export class SoftphoneSessionHandler extends BaseSessionHandler {
277277
}
278278

279279
/* only emit `pendingSession` if we already have an active session */
280-
if (session && session === this.activeSession) {
280+
if (session && session === this.activeSession && conversationId !== session.conversationId) {
281281
const pendingSession: IPendingSession = {
282282
id: session.id,
283283
sessionId: session.id,

test/unit/sessions/softphone-session-handler.test.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1197,12 +1197,13 @@ describe('handleSoftphoneConversationUpdate()', () => {
11971197
);
11981198
});
11991199

1200-
it('should emit a pending session if we already have an active session', async () => {
1200+
it('should emit a pending session if we already have an active session with a different conversationId', async () => {
12011201
const { update, participant, callState, session } = generateUpdate({
12021202
callState: CommunicationStates.alerting
12031203
});
12041204

12051205
handler.activeSession = session;
1206+
update.id = session.conversationId + '1';
12061207

12071208
handler.handleSoftphoneConversationUpdate(update, participant, callState, session);
12081209

@@ -1228,6 +1229,21 @@ describe('handleSoftphoneConversationUpdate()', () => {
12281229
expect(mockSessionManager.pendingSessions[0]).toEqual(expectedPendingSession);
12291230
});
12301231

1232+
it('should not emit a pending session if the active session is for the same conversation', async () => {
1233+
const { update, participant, callState, session } = generateUpdate({
1234+
callState: CommunicationStates.alerting
1235+
});
1236+
handler.activeSession = session;
1237+
1238+
handler.handleSoftphoneConversationUpdate(update, participant, callState, session);
1239+
1240+
await flushPromises();
1241+
1242+
expect(emitConversationEventSpy).not.toHaveBeenCalled();
1243+
expect(sdkEmitSpy).not.toHaveBeenCalled();
1244+
expect(mockSessionManager.pendingSessions.length).toBe(0);
1245+
});
1246+
12311247
it('should not emit a pending session if we do not have an active session', () => {
12321248
const { update, participant, callState, session } = generateUpdate({
12331249
callState: CommunicationStates.alerting

0 commit comments

Comments
 (0)