diff --git a/packages/hms-video-store/src/sdk/index.ts b/packages/hms-video-store/src/sdk/index.ts index fb184ade5f..eaa7c2f82f 100644 --- a/packages/hms-video-store/src/sdk/index.ts +++ b/packages/hms-video-store/src/sdk/index.ts @@ -92,6 +92,7 @@ import { DEFAULT_PLAYLIST_AUDIO_BITRATE, DEFAULT_PLAYLIST_VIDEO_BITRATE, HAND_RAISE_GROUP_NAME, + LEAVE_REASON, } from '../utils/constants'; import { fetchWithRetry } from '../utils/fetch'; import decodeJWT from '../utils/jwt'; @@ -724,6 +725,7 @@ export class HMSSdk implements HMSInterface { return this.internalLeave(notifyServer); } + // eslint-disable-next-line complexity private async internalLeave(notifyServer = true, error?: HMSException) { const room = this.store?.getRoom(); if (room) { @@ -744,7 +746,7 @@ export class HMSSdk implements HMSInterface { // tab refresh or close. Therefore prioritise the leave action over anything else, if tab is closed/refreshed // we would want leave to succeed to stop stucked peer for others. The followup cleanup however is important // for cases where uses stays on the page post leave. - await this.transport?.leave(notifyServer); + await this.transport?.leave(notifyServer, error ? LEAVE_REASON.SDK_REQUEST : LEAVE_REASON.USER_REQUEST); this.cleanup(); HMSLogger.d(this.TAG, `✅ Left room ${roomId}, peerId=${peerId}`); } diff --git a/packages/hms-video-store/src/signal/jsonrpc/index.ts b/packages/hms-video-store/src/signal/jsonrpc/index.ts index 51e357ce56..a5a5438b91 100644 --- a/packages/hms-video-store/src/signal/jsonrpc/index.ts +++ b/packages/hms-video-store/src/signal/jsonrpc/index.ts @@ -9,6 +9,7 @@ import { PeerNotificationInfo, SendMessage } from '../../notification-manager'; import { DEFAULT_SIGNAL_PING_INTERVAL, DEFAULT_SIGNAL_PING_TIMEOUT, + LEAVE_REASON, PONG_RESPONSE_TIMES_SIZE, } from '../../utils/constants'; import HMSLogger from '../../utils/logger'; @@ -307,8 +308,8 @@ export default class JsonRpcSignal { return await this.call(HMSSignalMethod.BROADCAST, message); } - leave() { - this.notify(HMSSignalMethod.LEAVE, {}); + leave(reason: LEAVE_REASON) { + this.notify(HMSSignalMethod.LEAVE, { client_reason: reason }); } async endRoom(lock: boolean, reason: string) { diff --git a/packages/hms-video-store/src/transport/index.ts b/packages/hms-video-store/src/transport/index.ts index 11b418a416..6615b030cc 100644 --- a/packages/hms-video-store/src/transport/index.ts +++ b/packages/hms-video-store/src/transport/index.ts @@ -36,6 +36,7 @@ import { ISignalEventsObserver } from '../signal/ISignalEventsObserver'; import JsonRpcSignal from '../signal/jsonrpc'; import { ICE_DISCONNECTION_TIMEOUT, + LEAVE_REASON, PROTOCOL_SPEC, PROTOCOL_VERSION, PUBLISH_STATS_PUSH_INTERVAL, @@ -359,7 +360,7 @@ export default class HMSTransport { } } - async leave(notifyServer: boolean): Promise { + async leave(notifyServer: boolean, reason = LEAVE_REASON.USER_REQUEST): Promise { this.retryScheduler.reset(); this.joinParameters = undefined; HMSLogger.d(TAG, 'leaving in transport'); @@ -375,7 +376,7 @@ export default class HMSTransport { this.clearPeerConnections(); if (notifyServer) { try { - this.signal.leave(); + this.signal.leave(reason); HMSLogger.d(TAG, 'signal leave done'); } catch (err) { HMSLogger.w(TAG, 'failed to send leave on websocket to server', err); diff --git a/packages/hms-video-store/src/utils/constants.ts b/packages/hms-video-store/src/utils/constants.ts index 0888adb791..021dc07030 100644 --- a/packages/hms-video-store/src/utils/constants.ts +++ b/packages/hms-video-store/src/utils/constants.ts @@ -71,3 +71,8 @@ export const DEFAULT_PLAYLIST_AUDIO_BITRATE = 64; export const WHITEBOARD_ORIGIN = 'https://whiteboard.100ms.live'; export const WHITEBOARD_QA_ORIGIN = 'https://whiteboard-qa.100ms.live'; + +export enum LEAVE_REASON { + USER_REQUEST = 'user request', + SDK_REQUEST = 'sdk request', +}