Skip to content

Commit

Permalink
Merge branch 'dev' into WEB-2828
Browse files Browse the repository at this point in the history
  • Loading branch information
KaustubhKumar05 authored May 21, 2024
2 parents af33450 + af3c5ce commit f2a395d
Show file tree
Hide file tree
Showing 15 changed files with 114 additions and 6 deletions.
13 changes: 13 additions & 0 deletions packages/hms-video-store/src/IHMSActions.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { TranscriptionConfig } from './interfaces/transcription-config';
import {
HLSConfig,
HLSTimedMetadata,
Expand Down Expand Up @@ -371,6 +372,18 @@ export interface IHMSActions<T extends HMSGenericTypes = { sessionStore: Record<
*/
stopHLSStreaming(params?: HLSConfig): Promise<void>;

/**
* If you want to start transcriptions(Closed Caption).
* @param params.mode This is the mode which represent the type of transcription. Currently we have Caption mode only
*/
startTranscription(params: TranscriptionConfig): Promise<void>;

/**
* If you want to stop transcriptions(Closed Caption).
* @param params.mode This is the mode which represent the type of transcription you want to stop. Currently we have Caption mode only
*/
stopTranscription(params: TranscriptionConfig): Promise<void>;

/**
* @alpha
* Used to define date range metadata in a media playlist.
Expand Down
3 changes: 3 additions & 0 deletions packages/hms-video-store/src/interfaces/hms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { HMSHLS, HMSRecording, HMSRTMP, HMSTranscriptionInfo } from './room';
import { RTMPRecordingConfig } from './rtmp-recording-config';
import { HMSInteractivityCenter, HMSSessionStore } from './session-store';
import { HMSScreenShareConfig } from './track-settings';
import { TranscriptionConfig } from './transcription-config';
import { HMSAudioListener, HMSConnectionQualityListener, HMSUpdateListener } from './update-listener';
import { HMSAnalyticsLevel } from '../analytics/AnalyticsEventLevel';
import { IAudioOutputManager } from '../device-manager/AudioOutputManager';
Expand Down Expand Up @@ -61,6 +62,8 @@ export interface HMSInterface {
*/
startHLSStreaming(params?: HLSConfig): Promise<void>;
stopHLSStreaming(params?: HLSConfig): Promise<void>;
startTranscription(params: TranscriptionConfig): Promise<void>;
stopTranscription(params: TranscriptionConfig): Promise<void>;
getRecordingState(): HMSRecording | undefined;
getRTMPState(): HMSRTMP | undefined;
getHLSState(): HMSHLS | undefined;
Expand Down
1 change: 1 addition & 0 deletions packages/hms-video-store/src/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ export * from './webrtc-stats';
export * from './framework-info';
export * from './get-token';
export * from './session-store';
export * from './transcription-config';
6 changes: 6 additions & 0 deletions packages/hms-video-store/src/interfaces/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export interface HLSVariant {
Transcription related details
*/
export enum HMSTranscriptionState {
INITIALISED = 'initialised',
STARTED = 'started',
STOPPED = 'stopped',
FAILED = 'failed',
Expand All @@ -133,4 +134,9 @@ export enum HMSTranscriptionMode {
export interface HMSTranscriptionInfo {
state?: HMSTranscriptionState;
mode?: HMSTranscriptionMode;
initialised_at?: Date;
started_at?: Date;
updated_at?: Date;
stopped_at?: Date;
error?: HMSException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { HMSTranscriptionMode } from './room';

export interface TranscriptionConfig {
mode: HMSTranscriptionMode;
}
1 change: 1 addition & 0 deletions packages/hms-video-store/src/interfaces/update-listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export enum HMSRoomUpdate {
SERVER_RECORDING_STATE_UPDATED = 'SERVER_RECORDING_STATE_UPDATED',
RTMP_STREAMING_STATE_UPDATED = 'RTMP_STREAMING_STATE_UPDATED',
HLS_STREAMING_STATE_UPDATED = 'HLS_STREAMING_STATE_UPDATED',
TRANSCRIPTION_STATE_UPDATED = 'TRANSCRIPTION_STATE_UPDATED',
ROOM_PEER_COUNT_UPDATED = 'ROOM_PEER_COUNT_UPDATED',
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export enum HMSNotificationMethod {
RTMP_UPDATE = 'on-rtmp-update',
RECORDING_UPDATE = 'on-record-update',
HLS_UPDATE = 'on-hls-update',
TRANSCRIPTION_UPDATE = 'on-transcription-update',
METADATA_CHANGE = 'on-metadata-change',
POLL_START = 'on-poll-start',
POLL_STOP = 'on-poll-stop',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export enum HMSStreamingState {
}

export enum HMSTranscriptionState {
INITIALISED = 'initialised',
STARTED = 'started',
STOPPED = 'stopped',
FAILED = 'failed',
Expand Down Expand Up @@ -133,6 +134,12 @@ export interface PeerNotification {
export interface TranscriptionNotification {
state?: HMSTranscriptionState;
mode?: HMSTranscriptionMode;
initialised_at?: number;
started_at?: number;
updated_at?: number;
stopped_at?: number;
peer?: PeerNotificationInfo;
error?: ServerError;
}

export interface RoomState {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ export class RoomUpdateManager {
case HMSNotificationMethod.HLS_UPDATE:
this.updateHLSStatus(notification as HLSNotification);
break;
case HMSNotificationMethod.TRANSCRIPTION_UPDATE:
this.handleTranscriptionStatus([notification as TranscriptionNotification]);
break;
default:
break;
}
Expand Down Expand Up @@ -129,6 +132,11 @@ export class RoomUpdateManager {
return {
state: transcription.state,
mode: transcription.mode,
initialised_at: convertDateNumToDate(transcription.initialised_at),
started_at: convertDateNumToDate(transcription.started_at),
stopped_at: convertDateNumToDate(transcription.stopped_at),
updated_at: convertDateNumToDate(transcription.updated_at),
error: this.toSdkError(transcription?.error),
};
});
}
Expand Down Expand Up @@ -200,6 +208,15 @@ export class RoomUpdateManager {
this.listener?.onRoomUpdate(HMSRoomUpdate.HLS_STREAMING_STATE_UPDATED, room);
}

private handleTranscriptionStatus(notification: TranscriptionNotification[]) {
const room = this.store.getRoom();
if (!room) {
HMSLogger.w(this.TAG, 'on transcription - room not present');
return;
}
room.transcriptions = this.addTranscriptionDetail(notification) || [];
this.listener?.onRoomUpdate(HMSRoomUpdate.TRANSCRIPTION_STATE_UPDATED, room);
}
private convertHls(hlsNotification?: HLSNotification) {
const isInitialised =
hlsNotification?.variants && hlsNotification.variants.length > 0
Expand Down
8 changes: 8 additions & 0 deletions packages/hms-video-store/src/reactive-store/HMSSDKActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,14 @@ export class HMSSDKActions<T extends HMSGenericTypes = { sessionStore: Record<st
await this.sdk.stopHLSStreaming(params);
}

async startTranscription(params: sdkTypes.TranscriptionConfig) {
await this.sdk.startTranscription(params);
}

async stopTranscription(params: sdkTypes.TranscriptionConfig): Promise<void> {
await this.sdk.stopTranscription(params);
}

async sendHLSTimedMetadata(metadataList: sdkTypes.HLSTimedMetadata[]): Promise<void> {
await this.sdk.sendHLSTimedMetadata(metadataList);
}
Expand Down
10 changes: 6 additions & 4 deletions packages/hms-video-store/src/reactive-store/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,11 @@ export class SDKToHMS {
}

static convertRoom(sdkRoom: sdkTypes.HMSRoom, sdkLocalPeerId?: string): Partial<HMSRoom> {
const { recording, rtmp, hls } = SDKToHMS.convertRecordingStreamingState(
sdkRoom?.recording,
sdkRoom?.rtmp,
sdkRoom?.hls,
const { recording, rtmp, hls, transcriptions } = SDKToHMS.convertRecordingStreamingState(
sdkRoom.recording,
sdkRoom.rtmp,
sdkRoom.hls,
sdkRoom.transcriptions,
);
return {
id: sdkRoom.id,
Expand All @@ -151,6 +152,7 @@ export class SDKToHMS {
recording,
rtmp,
hls,
transcriptions,
sessionId: sdkRoom.sessionId,
startedAt: sdkRoom.startedAt,
joinedAt: sdkRoom.joinedAt,
Expand Down
32 changes: 31 additions & 1 deletion packages/hms-video-store/src/sdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import { HMSPreviewListener } from '../interfaces/preview-listener';
import { RTMPRecordingConfig } from '../interfaces/rtmp-recording-config';
import InitialSettings from '../interfaces/settings';
import { HMSAudioListener, HMSPeerUpdate, HMSTrackUpdate, HMSUpdateListener } from '../interfaces/update-listener';
import { PlaylistManager } from '../internal';
import { PlaylistManager, TranscriptionConfig } from '../internal';
import { HMSLocalStream } from '../media/streams/HMSLocalStream';
import {
HMSLocalAudioTrack,
Expand All @@ -70,6 +70,7 @@ import {
HLSTimedMetadataParams,
HLSVariant,
StartRTMPOrRecordingRequestParams,
StartTranscriptionRequestParams,
} from '../signal/interfaces';
import HMSTransport from '../transport';
import ITransportObserver from '../transport/ITransportObserver';
Expand Down Expand Up @@ -1012,6 +1013,35 @@ export class HMSSdk implements HMSInterface {
await this.transport?.signal.stopHLSStreaming();
}

async startTranscription(params: TranscriptionConfig) {
if (!this.localPeer) {
throw ErrorFactory.GenericErrors.NotConnected(
HMSAction.VALIDATION,
'No local peer present, cannot start transcriptions',
);
}
const transcriptionParams: StartTranscriptionRequestParams = {
mode: params.mode,
};
await this.transport?.signal.startTranscription(transcriptionParams);
}

async stopTranscription(params: TranscriptionConfig) {
if (!this.localPeer) {
throw ErrorFactory.GenericErrors.NotConnected(
HMSAction.VALIDATION,
'No local peer present, cannot stop transcriptions',
);
}
if (!params) {
throw ErrorFactory.GenericErrors.Signalling(HMSAction.VALIDATION, 'No mode is passed to stop the transcription');
}
const transcriptionParams: StartTranscriptionRequestParams = {
mode: params.mode,
};
await this.transport?.signal.stopTranscription(transcriptionParams);
}

async sendHLSTimedMetadata(metadataList: HLSTimedMetadata[]) {
this.validateJoined('sendHLSTimedMetadata');
if (metadataList.length > 0) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HMSTrackSource } from '../..';
import { HMSTrackSource, HMSTranscriptionMode } from '../..';
import { HLSTimedMetadata, RTMPRecordingResolution } from '../../interfaces';

/**
Expand Down Expand Up @@ -57,6 +57,9 @@ export interface UpdatePeerRequestParams {
data?: string;
}

export interface StartTranscriptionRequestParams {
mode: HMSTranscriptionMode;
}
export interface SetSessionMetadataParams {
key?: string;
data: any;
Expand Down
9 changes: 9 additions & 0 deletions packages/hms-video-store/src/signal/jsonrpc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import {
SetSessionMetadataParams,
SetSessionMetadataResponse,
StartRTMPOrRecordingRequestParams,
StartTranscriptionRequestParams,
Track,
TrackUpdateRequestParams,
UpdatePeerRequestParams,
Expand Down Expand Up @@ -364,6 +365,14 @@ export default class JsonRpcSignal {
await this.call(HMSSignalMethod.STOP_HLS_STREAMING, { ...params });
}

async startTranscription(params: StartTranscriptionRequestParams) {
await this.call(HMSSignalMethod.START_TRANSCRIPTION, { ...params });
}

async stopTranscription(params: StartTranscriptionRequestParams) {
await this.call(HMSSignalMethod.STOP_TRANSCRIPTION, { ...params });
}

async sendHLSTimedMetadata(params?: HLSTimedMetadataParams): Promise<void> {
await this.call(HMSSignalMethod.HLS_TIMED_METADATA, { ...params });
}
Expand Down
2 changes: 2 additions & 0 deletions packages/hms-video-store/src/signal/jsonrpc/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export enum HMSSignalMethod {
UPDATE_PEER_METADATA = 'peer-update',
START_HLS_STREAMING = 'hls-start',
STOP_HLS_STREAMING = 'hls-stop',
START_TRANSCRIPTION = 'transcription-start',
STOP_TRANSCRIPTION = 'transcription-stop',
HLS_TIMED_METADATA = 'hls-timed-metadata',
SET_METADATA = 'set-metadata',
GET_METADATA = 'get-metadata',
Expand Down

0 comments on commit f2a395d

Please sign in to comment.