Skip to content

Commit

Permalink
feat(android/ios): start/stop recording events for native (#15598)
Browse files Browse the repository at this point in the history
Added native android and ios events for start and stop recording.
  • Loading branch information
Calinteodor authored Feb 13, 2025
1 parent 13bfdae commit ef138fb
Show file tree
Hide file tree
Showing 8 changed files with 263 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ enum Type {
SET_CLOSED_CAPTIONS_ENABLED("org.jitsi.meet.SET_CLOSED_CAPTIONS_ENABLED"),
TOGGLE_CAMERA("org.jitsi.meet.TOGGLE_CAMERA"),
SHOW_NOTIFICATION("org.jitsi.meet.SHOW_NOTIFICATION"),
HIDE_NOTIFICATION("org.jitsi.meet.HIDE_NOTIFICATION");
HIDE_NOTIFICATION("org.jitsi.meet.HIDE_NOTIFICATION"),
START_RECORDING("org.jitsi.meet.START_RECORDING"),
STOP_RECORDING("org.jitsi.meet.STOP_RECORDING");

private final String action;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package org.jitsi.meet.sdk;

import android.content.Intent;

import org.jitsi.meet.sdk.log.JitsiMeetLogger;

import java.util.Arrays;
import java.util.List;
import android.os.Bundle;

public class BroadcastIntentHelper {
public static Intent buildSetAudioMutedIntent(boolean muted) {
Intent intent = new Intent(BroadcastAction.Type.SET_AUDIO_MUTED.getAction());
intent.putExtra("muted", muted);

return intent;
}

Expand All @@ -22,18 +19,21 @@ public static Intent buildSendEndpointTextMessageIntent(String to, String messag
Intent intent = new Intent(BroadcastAction.Type.SEND_ENDPOINT_TEXT_MESSAGE.getAction());
intent.putExtra("to", to);
intent.putExtra("message", message);

return intent;
}

public static Intent buildToggleScreenShareIntent(boolean enabled) {
Intent intent = new Intent(BroadcastAction.Type.TOGGLE_SCREEN_SHARE.getAction());
intent.putExtra("enabled", enabled);

return intent;
}

public static Intent buildOpenChatIntent(String participantId) {
Intent intent = new Intent(BroadcastAction.Type.OPEN_CHAT.getAction());
intent.putExtra("to", participantId);

return intent;
}

Expand All @@ -45,24 +45,28 @@ public static Intent buildSendChatMessageIntent(String participantId, String mes
Intent intent = new Intent(BroadcastAction.Type.SEND_CHAT_MESSAGE.getAction());
intent.putExtra("to", participantId);
intent.putExtra("message", message);

return intent;
}

public static Intent buildSetVideoMutedIntent(boolean muted) {
Intent intent = new Intent(BroadcastAction.Type.SET_VIDEO_MUTED.getAction());
intent.putExtra("muted", muted);

return intent;
}

public static Intent buildSetClosedCaptionsEnabledIntent(boolean enabled) {
Intent intent = new Intent(BroadcastAction.Type.SET_CLOSED_CAPTIONS_ENABLED.getAction());
intent.putExtra("enabled", enabled);

return intent;
}

public static Intent buildRetrieveParticipantsInfo(String requestId) {
Intent intent = new Intent(BroadcastAction.Type.RETRIEVE_PARTICIPANTS_INFO.getAction());
intent.putExtra("requestId", requestId);

return intent;
}

Expand All @@ -78,12 +82,61 @@ public static Intent buildShowNotificationIntent(
intent.putExtra("timeout", timeout);
intent.putExtra("title", title);
intent.putExtra("uid", uid);

return intent;
}

public static Intent buildHideNotificationIntent(String uid) {
Intent intent = new Intent(BroadcastAction.Type.HIDE_NOTIFICATION.getAction());
intent.putExtra("uid", uid);

return intent;
}

public enum RecordingMode {
FILE("file"),
STREAM("stream");

private final String mode;

RecordingMode(String mode) {
this.mode = mode;
}

public String getMode() {
return mode;
}
}

public static Intent buildStartRecordingIntent(
RecordingMode mode,
String dropboxToken,
boolean shouldShare,
String rtmpStreamKey,
String rtmpBroadcastID,
String youtubeStreamKey,
String youtubeBroadcastID,
Bundle extraMetadata,
boolean transcription) {
Intent intent = new Intent(BroadcastAction.Type.START_RECORDING.getAction());
intent.putExtra("mode", mode.getMode());
intent.putExtra("dropboxToken", dropboxToken);
intent.putExtra("shouldShare", shouldShare);
intent.putExtra("rtmpStreamKey", rtmpStreamKey);
intent.putExtra("rtmpBroadcastID", rtmpBroadcastID);
intent.putExtra("youtubeStreamKey", youtubeStreamKey);
intent.putExtra("youtubeBroadcastID", youtubeBroadcastID);
intent.putExtra("extraMetadata", extraMetadata);
intent.putExtra("transcription", transcription);

return intent;
}

public static Intent buildStopRecordingIntent(RecordingMode mode, boolean transcription) {
Intent intent = new Intent(BroadcastAction.Type.STOP_RECORDING.getAction());
intent.putExtra("mode", mode.getMode());
intent.putExtra("transcription", transcription);

return intent;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ public Map<String, Object> getConstants() {
constants.put("TOGGLE_CAMERA", BroadcastAction.Type.TOGGLE_CAMERA.getAction());
constants.put("SHOW_NOTIFICATION", BroadcastAction.Type.SHOW_NOTIFICATION.getAction());
constants.put("HIDE_NOTIFICATION", BroadcastAction.Type.HIDE_NOTIFICATION.getAction());
constants.put("START_RECORDING", BroadcastAction.Type.START_RECORDING.getAction());
constants.put("STOP_RECORDING", BroadcastAction.Type.STOP_RECORDING.getAction());

return constants;
}
Expand Down
7 changes: 7 additions & 0 deletions ios/sdk/src/ExternalAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@

static NSString * const sendEventNotificationName = @"org.jitsi.meet.SendEvent";

typedef NS_ENUM(NSInteger, RecordingMode) {
RecordingModeFile,
RecordingModeStream
};

@interface ExternalAPI : RCTEventEmitter<RCTBridgeModule>

- (void)sendHangUp;
Expand All @@ -33,5 +38,7 @@ static NSString * const sendEventNotificationName = @"org.jitsi.meet.SendEvent";
- (void)toggleCamera;
- (void)showNotification:(NSString*)appearance :(NSString*)description :(NSString*)timeout :(NSString*)title :(NSString*)uid;
- (void)hideNotification:(NSString*)uid;
- (void)startRecording:(RecordingMode)mode :(NSString*)dropboxToken :(BOOL)shouldShare :(NSString*)rtmpStreamKey :(NSString*)rtmpBroadcastID :(NSString*)youtubeStreamKey :(NSString*)youtubeBroadcastID :(NSDictionary*)extraMetadata :(BOOL)transcription;
- (void)stopRecording:(RecordingMode)mode :(BOOL)transcription;

@end
51 changes: 47 additions & 4 deletions ios/sdk/src/ExternalAPI.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
static NSString * const toggleCameraAction = @"org.jitsi.meet.TOGGLE_CAMERA";
static NSString * const showNotificationAction = @"org.jitsi.meet.SHOW_NOTIFICATION";
static NSString * const hideNotificationAction = @"org.jitsi.meet.HIDE_NOTIFICATION";
static NSString * const startRecordingAction = @"org.jitsi.meet.START_RECORDING";
static NSString * const stopRecordingAction = @"org.jitsi.meet.STOP_RECORDING";

@implementation ExternalAPI

Expand All @@ -56,7 +58,9 @@ - (NSDictionary *)constantsToExport {
@"SET_CLOSED_CAPTIONS_ENABLED": setClosedCaptionsEnabledAction,
@"TOGGLE_CAMERA": toggleCameraAction,
@"SHOW_NOTIFICATION": showNotificationAction,
@"HIDE_NOTIFICATION": hideNotificationAction
@"HIDE_NOTIFICATION": hideNotificationAction,
@"START_RECORDING": startRecordingAction,
@"STOP_RECORDING": stopRecordingAction
};
};

Expand Down Expand Up @@ -84,7 +88,9 @@ + (BOOL)requiresMainQueueSetup {
setClosedCaptionsEnabledAction,
toggleCameraAction,
showNotificationAction,
hideNotificationAction
hideNotificationAction,
startRecordingAction,
stopRecordingAction
];
}

Expand Down Expand Up @@ -186,7 +192,7 @@ - (void)toggleCamera {
[self sendEventWithName:toggleCameraAction body:nil];
}

- (void)showNotification:(NSString *)appearance :(NSString *)description :(NSString *)timeout :(NSString *)title :(NSString *)uid {
- (void)showNotification:(NSString*)appearance :(NSString*)description :(NSString*)timeout :(NSString*)title :(NSString*)uid {
NSMutableDictionary *data = [[NSMutableDictionary alloc] init];
data[@"appearance"] = appearance;
data[@"description"] = description;
Expand All @@ -197,11 +203,48 @@ - (void)showNotification:(NSString *)appearance :(NSString *)description :(NSStr
[self sendEventWithName:showNotificationAction body:data];
}

- (void)hideNotification:(NSString *)uid {
- (void)hideNotification:(NSString*)uid {
NSMutableDictionary *data = [[NSMutableDictionary alloc] init];
data[@"uid"] = uid;

[self sendEventWithName:hideNotificationAction body:data];
}

static inline NSString *RecordingModeToString(RecordingMode mode) {
switch (mode) {
case RecordingModeFile:
return @"file";
case RecordingModeStream:
return @"stream";
default:
return nil;
}
}

- (void)startRecording:(RecordingMode)mode :(NSString*)dropboxToken :(BOOL)shouldShare :(NSString*)rtmpStreamKey :(NSString*)rtmpBroadcastID :(NSString*)youtubeStreamKey :(NSString*)youtubeBroadcastID :(NSDictionary*)extraMetadata :(BOOL)transcription {
NSString *modeString = RecordingModeToString(mode);
NSDictionary *data = @{
@"mode": modeString,
@"dropboxToken": dropboxToken,
@"shouldShare": @(shouldShare),
@"rtmpStreamKey": rtmpStreamKey,
@"rtmpBroadcastID": rtmpBroadcastID,
@"youtubeStreamKey": youtubeStreamKey,
@"youtubeBroadcastID": youtubeBroadcastID,
@"extraMetadata": extraMetadata,
@"transcription": @(transcription)
};

[self sendEventWithName:startRecordingAction body:data];
}

- (void)stopRecording:(RecordingMode)mode :(BOOL)transcription {
NSString *modeString = RecordingModeToString(mode);
NSDictionary *data = @{
@"mode": modeString,
@"transcription": @(transcription)
};

[self sendEventWithName:stopRecordingAction body:data];
}
@end
4 changes: 4 additions & 0 deletions ios/sdk/src/JitsiMeetView.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#import "JitsiMeetConferenceOptions.h"
#import "JitsiMeetViewDelegate.h"

typedef NS_ENUM(NSInteger, RecordingMode);

@interface JitsiMeetView : UIView

@property (nonatomic, nullable, weak) id<JitsiMeetViewDelegate> delegate;
Expand Down Expand Up @@ -49,5 +51,7 @@
- (void)toggleCamera;
- (void)showNotification:(NSString * _Nonnull)appearance :(NSString * _Nullable)description :(NSString * _Nullable)timeout :(NSString * _Nullable)title :(NSString * _Nullable)uid;
- (void)hideNotification:(NSString * _Nullable)uid;
- (void)startRecording:(RecordingMode)mode :(NSString * _Nullable)dropboxToken :(BOOL)shouldShare :(NSString * _Nullable)rtmpStreamKey :(NSString * _Nullable)rtmpBroadcastID :(NSString * _Nullable)youtubeStreamKey :(NSString * _Nullable)youtubeBroadcastID :(NSString * _Nullable)extraMetadata :(BOOL)transcription;
- (void)stopRecording:(RecordingMode)mode :(BOOL)transcription;

@end
12 changes: 12 additions & 0 deletions ios/sdk/src/JitsiMeetView.m
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,27 @@ - (void)toggleCamera {
ExternalAPI *externalAPI = [[JitsiMeet sharedInstance] getExternalAPI];
[externalAPI toggleCamera];
}

- (void)showNotification:(NSString *)appearance :(NSString *)description :(NSString *)timeout :(NSString *)title :(NSString *)uid {
ExternalAPI *externalAPI = [[JitsiMeet sharedInstance] getExternalAPI];
[externalAPI showNotification:appearance :description :timeout :title :uid];
}

-(void)hideNotification:(NSString *)uid {
ExternalAPI *externalAPI = [[JitsiMeet sharedInstance] getExternalAPI];
[externalAPI hideNotification:uid];
}

- (void)startRecording:(RecordingMode)mode :(NSString *)dropboxToken :(BOOL)shouldShare :(NSString *)rtmpStreamKey :(NSString *)rtmpBroadcastID :(NSString *)youtubeStreamKey :(NSString *)youtubeBroadcastID :(NSString *)extraMetadata :(BOOL)transcription {
ExternalAPI *externalAPI = [[JitsiMeet sharedInstance] getExternalAPI];
[externalAPI startRecording:mode :dropboxToken :shouldShare :rtmpStreamKey :rtmpBroadcastID :youtubeStreamKey :youtubeBroadcastID :extraMetadata :transcription];
}

- (void)stopRecording:(RecordingMode)mode :(BOOL)transcription {
ExternalAPI *externalAPI = [[JitsiMeet sharedInstance] getExternalAPI];
[externalAPI stopRecording:mode :transcription];
}

#pragma mark Private methods

- (void)registerObservers {
Expand Down
Loading

0 comments on commit ef138fb

Please sign in to comment.