Skip to content

Commit

Permalink
feat(subtitles): created separate helpers for sending transcription c…
Browse files Browse the repository at this point in the history
…hunks events
  • Loading branch information
Calinteodor committed Mar 27, 2024
1 parent ffa704e commit 655e643
Show file tree
Hide file tree
Showing 12 changed files with 108 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ public enum Type {
CHAT_MESSAGE_RECEIVED("org.jitsi.meet.CHAT_MESSAGE_RECEIVED"),
CHAT_TOGGLED("org.jitsi.meet.CHAT_TOGGLED"),
VIDEO_MUTED_CHANGED("org.jitsi.meet.VIDEO_MUTED_CHANGED"),
READY_TO_CLOSE("org.jitsi.meet.READY_TO_CLOSE");
READY_TO_CLOSE("org.jitsi.meet.READY_TO_CLOSE"),
TRANSCRIPTION_CHUNK_RECEIVED("org.jitsi.meet.TRANSCRIPTION_CHUNK_RECEIVED");

private static final String CONFERENCE_BLURRED_NAME = "CONFERENCE_BLURRED";
private static final String CONFERENCE_FOCUSED_NAME = "CONFERENCE_FOCUSED";
Expand All @@ -106,6 +107,7 @@ public enum Type {
private static final String CHAT_TOGGLED_NAME = "CHAT_TOGGLED";
private static final String VIDEO_MUTED_CHANGED_NAME = "VIDEO_MUTED_CHANGED";
private static final String READY_TO_CLOSE_NAME = "READY_TO_CLOSE";
private static final String TRANSCRIPTION_CHUNK_RECEIVED_NAME = "TRANSCRIPTION_CHUNK_RECEIVED";

private final String action;

Expand Down Expand Up @@ -158,6 +160,8 @@ private static Type buildTypeFromName(String name) {
return VIDEO_MUTED_CHANGED;
case READY_TO_CLOSE_NAME:
return READY_TO_CLOSE;
case TRANSCRIPTION_CHUNK_RECEIVED_NAME:
return TRANSCRIPTION_CHUNK_RECEIVED;
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@ protected void onReadyToClose() {
finish();
}

protected void onTranscriptionChunkReceived(HashMap<String, Object> extraData) {
JitsiMeetLogger.i("Transcription chunk received: " + extraData);
}

// Activity lifecycle methods
//

Expand Down Expand Up @@ -338,6 +342,9 @@ private void onBroadcastReceived(Intent intent) {
case READY_TO_CLOSE:
onReadyToClose();
break;
case TRANSCRIPTION_CHUNK_RECEIVED:
onTranscriptionChunkReceived(event.getData());
break;
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions ios/app/src/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ - (void)readyToClose:(NSDictionary *)data {
[self _onJitsiMeetViewDelegateEvent:@"READY_TO_CLOSE" withData:data];
}

- (void)transcriptionChunkReceived:(NSDictionary *)data {
[self _onJitsiMeetViewDelegateEvent:@"TRANSCRIPTION_CHUNK_RECEIVED" withData:data];
}

- (void)participantJoined:(NSDictionary *)data {
NSLog(@"%@%@", @"Participant joined: ", data[@"participantId"]);
}
Expand Down Expand Up @@ -130,6 +134,7 @@ - (void)videoMutedChanged:(NSDictionary *)data {
NSLog(@"%@%@", @"Video muted changed: ", data[@"muted"]);
}


#pragma mark - Helpers

- (void)terminate {
Expand Down
2 changes: 1 addition & 1 deletion ios/sdk/src/JitsiMeetView.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
@property (nonatomic, nullable, weak) id<JitsiMeetViewDelegate> delegate;

/**
* Joins the conference specified by the given options. The gievn options will
* Joins the conference specified by the given options. The given options will
* be merged with the defaultConferenceOptions (if set) in JitsiMeet. If there
* is an already active conference it will be automatically left prior to
* joining the new one.
Expand Down
7 changes: 7 additions & 0 deletions ios/sdk/src/JitsiMeetViewDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,11 @@
*/
- (void)readyToClose:(NSDictionary *)data;

/**
* Called when the transcription chunk was received.
*
* The `data` dictionary contains a `messageID`, `language`, `participant` key.
*/
- (void)transcriptionChunkReceived:(NSDictionary *)data;

@end
21 changes: 17 additions & 4 deletions react/features/mobile/external-api/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import { ITrack } from '../../base/tracks/types';
import { CLOSE_CHAT, OPEN_CHAT } from '../../chat/actionTypes';
import { closeChat, openChat, sendMessage, setPrivateMessageRecipient } from '../../chat/actions.native';
import { setRequestingSubtitles } from '../../subtitles/actions.any';
import { notifyTranscriptionChunkReceived } from '../../subtitles/functions.native';
import { muteLocal } from '../../video-menu/actions.native';
import { ENTER_PICTURE_IN_PICTURE } from '../picture-in-picture/actionTypes';
// @ts-ignore
Expand All @@ -62,6 +63,7 @@ import { setParticipantsWithScreenShare } from './actions';
import { participantToParticipantInfo, sendEvent } from './functions';
import logger from './logger';


/**
* Event which will be emitted on the native side when a chat message is received
* through the channel.
Expand All @@ -86,7 +88,7 @@ const CONFERENCE_TERMINATED = 'CONFERENCE_TERMINATED';
const ENDPOINT_TEXT_MESSAGE_RECEIVED = 'ENDPOINT_TEXT_MESSAGE_RECEIVED';

/**
* Event which will be emitted on the native side to indicate a participant togggles
* Event which will be emitted on the native side to indicate a participant toggles
* the screen share.
*/
const SCREEN_SHARE_TOGGLED = 'SCREEN_SHARE_TOGGLED';
Expand All @@ -96,6 +98,7 @@ const SCREEN_SHARE_TOGGLED = 'SCREEN_SHARE_TOGGLED';
*/
const PARTICIPANTS_INFO_RETRIEVED = 'PARTICIPANTS_INFO_RETRIEVED';


const externalAPIEnabled = isExternalAPIAvailable();

let eventEmitter: any;
Expand Down Expand Up @@ -186,18 +189,28 @@ externalAPIEnabled && MiddlewareRegistry.register(store => next => action => {
}

case ENDPOINT_MESSAGE_RECEIVED: {
const { participant, data } = action;
const { participant, data: json } = action;
const transcriptMessageID = json.message_id;
const { language: dataLanguage } = json;

if (data?.name === ENDPOINT_TEXT_MESSAGE_NAME) {
if (json?.name === ENDPOINT_TEXT_MESSAGE_NAME) {
sendEvent(
store,
ENDPOINT_TEXT_MESSAGE_RECEIVED,
/* data */ {
message: data.text,
message: json.text,
senderId: participant.getId()
});
}

notifyTranscriptionChunkReceived(
transcriptMessageID,
dataLanguage,
participant,
json.text,
store
);

break;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { IReduxState } from '../../app/types';
import { MEET_FEATURES } from '../../base/jwt/constants';
import AbstractButton, { IProps as AbstractButtonProps } from '../../base/toolbox/components/AbstractButton';
import { maybeShowPremiumFeatureDialog } from '../../jaas/actions';
import { canStartSubtitles } from '../functions';
import { canStartSubtitles } from '../functions.any';

export interface IAbstractProps extends AbstractButtonProps {

Expand Down
File renamed without changes.
31 changes: 31 additions & 0 deletions react/features/subtitles/functions.native.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* eslint-disable max-params, max-len */

import { IStore } from '../app/types';
import { sendEvent } from '../mobile/external-api/functions';


/**
* Event which will be emitted on the native side to indicate that the transcription chunk was received.
*/
const TRANSCRIPTION_CHUNK_RECEIVED = 'TRANSCRIPTION_CHUNK_RECEIVED';

/**
* Logs when about the received transcription chunk.
*
* @param {string} transcriptMessageID - Transcription message id.
* @param {string} language - The language of the transcribed message.
* @param {Object} participant - The participant who send the message.
* @param {any} text - The message text.
* @param {IStore} _store - The store.
* @returns {Event}
*/
export const notifyTranscriptionChunkReceived = (transcriptMessageID: string, language: string, participant: Object, text: any, _store?: IStore) =>
sendEvent(
_store,

Check failure on line 24 in react/features/subtitles/functions.native.ts

View workflow job for this annotation

GitHub Actions / Lint

Argument of type 'IStore | undefined' is not assignable to parameter of type 'Object'.
TRANSCRIPTION_CHUNK_RECEIVED,
{
messageID: transcriptMessageID,
language,
participant,
text
});
22 changes: 22 additions & 0 deletions react/features/subtitles/functions.web.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* eslint-disable max-params, max-len */

import { IStore } from '../app/types';


/**
* Logs when about the received transcription chunk.
*
* @param {string} transcriptMessageID - Transcription message id.
* @param {string} language - The language of the transcribed message.
* @param {Object} participant - The participant who send the message.
* @param {any} text - The message text.
* @param {IStore} _store - The store.
* @returns {Event}
*/
export const notifyTranscriptionChunkReceived = (transcriptMessageID: string, language: string, participant: Object, text: any, _store?: IStore) =>
APP.API.notifyTranscriptionChunkReceived({
messageID: transcriptMessageID,
language,
participant,
text
});
15 changes: 9 additions & 6 deletions react/features/subtitles/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
removeTranscriptMessage,
updateTranscriptMessage
} from './actions.any';
import { notifyTranscriptionChunkReceived } from './functions';


/**
* The type of json-message which indicates that json carries a
Expand Down Expand Up @@ -43,7 +45,7 @@ const P_NAME_TRANSLATION_LANGUAGE = 'translation_language';
const REMOVE_AFTER_MS = 3000;

/**
* Stability factor for a trancription. We'll treat a transcript as stable
* Stability factor for a transcription. We'll treat a transcript as stable
* beyond this value.
*/
const STABLE_TRANSCRIPTION_FACTOR = 0.85;
Expand Down Expand Up @@ -91,6 +93,7 @@ MiddlewareRegistry.register(store => next => action => {
*/
function _endpointMessageReceived({ dispatch, getState }: IStore, next: Function, action: AnyAction) {
const { data: json } = action;
const { language: dataLanguage } = json;

if (![ JSON_TYPE_TRANSCRIPTION_RESULT, JSON_TYPE_TRANSLATION_RESULT ].includes(json?.type)) {
return next(action);
Expand Down Expand Up @@ -140,12 +143,12 @@ function _endpointMessageReceived({ dispatch, getState }: IStore, next: Function
txt.unstable = text;
}

APP.API.notifyTranscriptionChunkReceived({
messageID: transcriptMessageID,
language: json.language,
notifyTranscriptionChunkReceived(
transcriptMessageID,
dataLanguage,
participant,
...txt
});
txt
);

// Dump transcript in a <transcript> element for debugging purposes.
if (!json.is_interim && dumpTranscript) {
Expand Down
4 changes: 3 additions & 1 deletion react/features/subtitles/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import ReducerRegistry from '../base/redux/ReducerRegistry';

import {
REMOVE_TRANSCRIPT_MESSAGE,
SET_REQUESTING_SUBTITLES, TOGGLE_REQUESTING_SUBTITLES, UPDATE_TRANSCRIPT_MESSAGE
SET_REQUESTING_SUBTITLES,
TOGGLE_REQUESTING_SUBTITLES,
UPDATE_TRANSCRIPT_MESSAGE
} from './actionTypes';

/**
Expand Down

0 comments on commit 655e643

Please sign in to comment.