diff --git a/CHANGELOG.md b/CHANGELOG.md index 1464a44..bd268c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed * [STREAM-162](https://inindca.atlassian.net/browse/STREAM-162) - Streaming-client should trigger re-auth for some SASL errors (and 401s) - this will be indicated by a StreamingClientError of type `.invalid-token`. +### Fixed +* [STREAM-262](https://inindca.atlassian.net/browse/STREAM-262) - Set the state of a GenesysCloudMediaSession to `ended` when a `terminate` is received (or we determine a hard closure of the PeerConnection is needed) + # [v17.2.7](https://github.com/purecloudlabs/genesys-cloud-streaming-client/compare/v17.2.6..v17.2.7) ### Fixed * [STREAM-218](https://inindca.atlassian.net/browse/STREAM-218) - update the conversationId on sessions with reinvites diff --git a/src/types/genesys-cloud-media-session.ts b/src/types/genesys-cloud-media-session.ts index e585188..0dc33b9 100644 --- a/src/types/genesys-cloud-media-session.ts +++ b/src/types/genesys-cloud-media-session.ts @@ -96,7 +96,6 @@ export class GenesysCloudMediaSession { // if we have a state mismatch if (this.state !== 'ended' && ['failed', 'closed'].includes(this.peerConnection.connectionState)) { this.log('warn', 'state mismatch between session.state and peerConnection.connectionState, manually terminating the session', { sessionId: this.id, conversationId: this.conversationId, sessionType: this.sessionType }); - this.state = 'ended'; this.onSessionTerminate(); } } @@ -224,7 +223,6 @@ export class GenesysCloudMediaSession { this.interruptionStart = undefined; } else if (connectionState === 'failed') { this.log('info', 'Connection was interrupted and failed to recover, cleaning up', { sessionId, conversationId, sessionType }); - this.state = 'ended'; this.onSessionTerminate(); } } @@ -305,6 +303,8 @@ export class GenesysCloudMediaSession { } onSessionTerminate (reason?: JingleReasonCondition) { + this.state = 'ended'; + if (this.peerConnection) { this.peerConnection.close(); } diff --git a/test/unit/genesys-cloud-media-session.test.ts b/test/unit/genesys-cloud-media-session.test.ts index 3b21c7c..3b79ba2 100644 --- a/test/unit/genesys-cloud-media-session.test.ts +++ b/test/unit/genesys-cloud-media-session.test.ts @@ -458,6 +458,13 @@ describe('unmute()', () => { }); describe('onSessionTerminate()', () => { + it('should set the state to `ended`', () => { + const session = new GenesysCloudMediaSession(mockWebrtcExtension, config); + + session.onSessionTerminate(); + expect(session.state).toEqual('ended'); + }); + it('should emit a terminated event with default condition', () => { const session = new GenesysCloudMediaSession(mockWebrtcExtension, config); @@ -603,6 +610,12 @@ describe('end()', () => { session = new GenesysCloudMediaSession(mockWebrtcExtension, config); }); + it('should set state to `ended`', () => { + session.end(); + + expect(session.state).toEqual('ended'); + }); + it('should not send message if silent', () => { const spy = session['sendGenesysWebrtc'] = jest.fn();