Skip to content

Commit

Permalink
fix: send user or sdk request in reason for leave
Browse files Browse the repository at this point in the history
  • Loading branch information
raviteja83 authored Dec 27, 2024
1 parent acd0a1f commit 198cc2a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
4 changes: 3 additions & 1 deletion packages/hms-video-store/src/sdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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) {
Expand All @@ -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}`);
}
Expand Down
5 changes: 3 additions & 2 deletions packages/hms-video-store/src/signal/jsonrpc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -307,8 +308,8 @@ export default class JsonRpcSignal {
return await this.call<BroadcastResponse>(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) {
Expand Down
5 changes: 3 additions & 2 deletions packages/hms-video-store/src/transport/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -359,7 +360,7 @@ export default class HMSTransport {
}
}

async leave(notifyServer: boolean): Promise<void> {
async leave(notifyServer: boolean, reason = LEAVE_REASON.USER_REQUEST): Promise<void> {
this.retryScheduler.reset();
this.joinParameters = undefined;
HMSLogger.d(TAG, 'leaving in transport');
Expand All @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions packages/hms-video-store/src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}

0 comments on commit 198cc2a

Please sign in to comment.