Skip to content

Commit

Permalink
feat: disable auto unsubscribe video based on init flag
Browse files Browse the repository at this point in the history
  • Loading branch information
raviteja83 committed Jun 20, 2023
1 parent b27c92d commit 65bcfad
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import EventEmitter from 'eventemitter2';
import { v4 as uuid } from 'uuid';
import ISubscribeConnectionObserver from './ISubscribeConnectionObserver';
import { HMSRemoteStream } from '../../internal';
import { HMSRemoteStream, HMSSimulcastLayer } from '../../internal';
import { HMSRemoteAudioTrack } from '../../media/tracks/HMSRemoteAudioTrack';
import { HMSRemoteVideoTrack } from '../../media/tracks/HMSRemoteVideoTrack';
import { InitFlags } from '../../signal/init/models';
import { ISignal } from '../../signal/ISignal';
import { API_DATA_CHANNEL } from '../../utils/constants';
import HMSLogger from '../../utils/logger';
Expand Down Expand Up @@ -106,7 +107,12 @@ export default class HMSSubscribeConnection extends HMSConnection {
};
}

constructor(signal: ISignal, config: RTCConfiguration, observer: ISubscribeConnectionObserver) {
constructor(
signal: ISignal,
config: RTCConfiguration,
private isFlagEnabled: (flag: InitFlags) => boolean,
observer: ISubscribeConnectionObserver,
) {
super(HMSConnectionRole.Subscribe, signal);
this.observer = observer;

Expand All @@ -128,6 +134,13 @@ export default class HMSSubscribeConnection extends HMSConnection {
requestId?: string,
): Promise<PreferLayerResponse> {
const id = uuid();
if (message.method === 'prefer-video-track-state') {
const disableAutoUnsubscribe = this.isFlagEnabled(InitFlags.FLAG_DISABLE_VIDEO_TRACK_AUTO_UNSUBSCRIBE);
if (disableAutoUnsubscribe && message.params.max_spatial_layer === HMSSimulcastLayer.NONE) {
HMSLogger.d(this.TAG, 'video auto unsubscribe is disabled, request is ignored');
return { id } as PreferLayerResponse;
}
}
const request = JSON.stringify({
id: requestId || id,
jsonrpc: '2.0',
Expand Down
3 changes: 3 additions & 0 deletions packages/hms-video-web/src/signal/init/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,7 @@ export enum InitFlags {
FLAG_SERVER_SIMULCAST = 'simulcast',
FLAG_NON_WEBRTC_DISABLE_OFFER = 'nonWebRTCDisableOffer',
FLAG_PUBLISH_STATS = 'publishStats',
FLAG_ON_DEMAND_TRACKS = 'onDemandTracks',
// Don't unsubscribe for beam to prevent a/v sync in case of active speaker
FLAG_DISABLE_VIDEO_TRACK_AUTO_UNSUBSCRIBE = 'disableVideoTrackAutoUnsubscribe',
}
1 change: 1 addition & 0 deletions packages/hms-video-web/src/transport/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,7 @@ export default class HMSTransport implements ITransport {
this.subscribeConnection = new HMSSubscribeConnection(
this.signal,
this.initConfig.rtcConfiguration,
this.isFlagEnabled.bind(this),
this.subscribeConnectionObserver,
);
}
Expand Down

0 comments on commit 65bcfad

Please sign in to comment.