Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

feat(android/ios): Native API events for show/hide notification (#15577)

Calinteodorf670f39dd252
diff --git a/android/sdk/src/main/java/org/jitsi/meet/sdk/BroadcastAction.java b/android/sdk/src/main/java/org/jitsi/meet/sdk/BroadcastAction.java
index e793a99b0d..c8b7729071 100644
--- a/android/sdk/src/main/java/org/jitsi/meet/sdk/BroadcastAction.java
+++ b/android/sdk/src/main/java/org/jitsi/meet/sdk/BroadcastAction.java
@@ -78,7 +78,9 @@ public class BroadcastAction {
SEND_CHAT_MESSAGE("org.jitsi.meet.SEND_CHAT_MESSAGE"),
SET_VIDEO_MUTED("org.jitsi.meet.SET_VIDEO_MUTED"),
SET_CLOSED_CAPTIONS_ENABLED("org.jitsi.meet.SET_CLOSED_CAPTIONS_ENABLED"),
- TOGGLE_CAMERA("org.jitsi.meet.TOGGLE_CAMERA");
+ TOGGLE_CAMERA("org.jitsi.meet.TOGGLE_CAMERA"),
+ SHOW_NOTIFICATION("org.jitsi.meet.SHOW_NOTIFICATION"),
+ HIDE_NOTIFICATION("org.jitsi.meet.HIDE_NOTIFICATION");
private final String action;
diff --git a/android/sdk/src/main/java/org/jitsi/meet/sdk/BroadcastIntentHelper.java b/android/sdk/src/main/java/org/jitsi/meet/sdk/BroadcastIntentHelper.java
index 541fb74631..9a2dabdce3 100644
--- a/android/sdk/src/main/java/org/jitsi/meet/sdk/BroadcastIntentHelper.java
+++ b/android/sdk/src/main/java/org/jitsi/meet/sdk/BroadcastIntentHelper.java
@@ -2,6 +2,11 @@ package org.jitsi.meet.sdk;
import android.content.Intent;
+import org.jitsi.meet.sdk.log.JitsiMeetLogger;
+
+import java.util.Arrays;
+import java.util.List;
+
public class BroadcastIntentHelper {
public static Intent buildSetAudioMutedIntent(boolean muted) {
Intent intent = new Intent(BroadcastAction.Type.SET_AUDIO_MUTED.getAction());
@@ -54,7 +59,7 @@ public class BroadcastIntentHelper {
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);
@@ -64,4 +69,21 @@ public class BroadcastIntentHelper {
public static Intent buildToggleCameraIntent() {
return new Intent(BroadcastAction.Type.TOGGLE_CAMERA.getAction());
}
+
+ public static Intent buildShowNotificationIntent(
+ String appearance, String description, String timeout, String title, String uid) {
+ Intent intent = new Intent(BroadcastAction.Type.SHOW_NOTIFICATION.getAction());
+ intent.putExtra("appearance", appearance);
+ intent.putExtra("description", description);
+ 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;
+ }
}
diff --git a/android/sdk/src/main/java/org/jitsi/meet/sdk/ExternalAPIModule.java b/android/sdk/src/main/java/org/jitsi/meet/sdk/ExternalAPIModule.java
index 02202c9c84..2812d2ae5e 100644
--- a/android/sdk/src/main/java/org/jitsi/meet/sdk/ExternalAPIModule.java
+++ b/android/sdk/src/main/java/org/jitsi/meet/sdk/ExternalAPIModule.java
@@ -97,6 +97,8 @@ class ExternalAPIModule extends ReactContextBaseJavaModule {
constants.put("SET_VIDEO_MUTED", BroadcastAction.Type.SET_VIDEO_MUTED.getAction());
constants.put("SET_CLOSED_CAPTIONS_ENABLED", BroadcastAction.Type.SET_CLOSED_CAPTIONS_ENABLED.getAction());
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());
return constants;
}
diff --git a/ios/sdk/src/ExternalAPI.h b/ios/sdk/src/ExternalAPI.h
index e3c43a22ec..0ee72022d4 100644
--- a/ios/sdk/src/ExternalAPI.h
+++ b/ios/sdk/src/ExternalAPI.h
@@ -27,9 +27,11 @@ static NSString * const sendEventNotificationName = @"org.jitsi.meet.SendEvent";
- (void)retrieveParticipantsInfo:(void (^)(NSArray*))completion;
- (void)openChat:(NSString*)to;
- (void)closeChat;
-- (void)sendChatMessage:(NSString*)message :(NSString*)to ;
+- (void)sendChatMessage:(NSString*)message :(NSString*)to;
- (void)sendSetVideoMuted:(BOOL)muted;
- (void)sendSetClosedCaptionsEnabled:(BOOL)enabled;
- (void)toggleCamera;
+- (void)showNotification:(NSString*)appearance :(NSString*)description :(NSString*)timeout :(NSString*)title :(NSString*)uid;
+- (void)hideNotification:(NSString*)uid;
@end
diff --git a/ios/sdk/src/ExternalAPI.m b/ios/sdk/src/ExternalAPI.m
index 7437d43f83..efaab06b76 100644
--- a/ios/sdk/src/ExternalAPI.m
+++ b/ios/sdk/src/ExternalAPI.m
@@ -28,6 +28,8 @@ static NSString * const sendChatMessageAction = @"org.jitsi.meet.SEND_CHAT_MESSA
static NSString * const setVideoMutedAction = @"org.jitsi.meet.SET_VIDEO_MUTED";
static NSString * const setClosedCaptionsEnabledAction = @"org.jitsi.meet.SET_CLOSED_CAPTIONS_ENABLED";
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";
@implementation ExternalAPI
@@ -52,7 +54,9 @@ RCT_EXPORT_MODULE();
@"SEND_CHAT_MESSAGE": sendChatMessageAction,
@"SET_VIDEO_MUTED" : setVideoMutedAction,
@"SET_CLOSED_CAPTIONS_ENABLED": setClosedCaptionsEnabledAction,
- @"TOGGLE_CAMERA": toggleCameraAction
+ @"TOGGLE_CAMERA": toggleCameraAction,
+ @"SHOW_NOTIFICATION": showNotificationAction,
+ @"HIDE_NOTIFICATION": hideNotificationAction
};
};
@@ -78,7 +82,9 @@ RCT_EXPORT_MODULE();
sendChatMessageAction,
setVideoMutedAction,
setClosedCaptionsEnabledAction,
- toggleCameraAction
+ toggleCameraAction,
+ showNotificationAction,
+ hideNotificationAction
];
}
@@ -180,4 +186,22 @@ RCT_EXPORT_METHOD(sendEvent:(NSString *)name
[self sendEventWithName:toggleCameraAction body:nil];
}
+- (void)showNotification:(NSString *)appearance :(NSString *)description :(NSString *)timeout :(NSString *)title :(NSString *)uid {
+ NSMutableDictionary *data = [[NSMutableDictionary alloc] init];
+ data[@"appearance"] = appearance;
+ data[@"description"] = description;
+ data[@"timeout"] = timeout;
+ data[@"title"] = title;
+ data[@"uid"] = uid;
+
+ [self sendEventWithName:showNotificationAction body:data];
+}
+
+- (void)hideNotification:(NSString *)uid {
+ NSMutableDictionary *data = [[NSMutableDictionary alloc] init];
+ data[@"uid"] = uid;
+
+ [self sendEventWithName:hideNotificationAction body:data];
+}
+
@end
diff --git a/ios/sdk/src/JitsiMeetView.h b/ios/sdk/src/JitsiMeetView.h
index 323f67ccf5..e7b5f1ffa0 100644
--- a/ios/sdk/src/JitsiMeetView.h
+++ b/ios/sdk/src/JitsiMeetView.h
@@ -47,5 +47,7 @@
- (void)setVideoMuted:(BOOL)muted;
- (void)setClosedCaptionsEnabled:(BOOL)enabled;
- (void)toggleCamera;
+- (void)showNotification:(NSString * _Nonnull)appearance :(NSString * _Nullable)description :(NSString * _Nullable)timeout :(NSString * _Nullable)title :(NSString * _Nullable)uid;
+- (void)hideNotification:(NSString * _Nullable)uid;
@end
diff --git a/ios/sdk/src/JitsiMeetView.m b/ios/sdk/src/JitsiMeetView.m
index 5691de1b0c..0427d73a8a 100644
--- a/ios/sdk/src/JitsiMeetView.m
+++ b/ios/sdk/src/JitsiMeetView.m
@@ -142,6 +142,14 @@ static NSString *const PiPEnabledFeatureFlag = @"pip.enabled";
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];
+}
#pragma mark Private methods
diff --git a/react/features/mobile/external-api/middleware.ts b/react/features/mobile/external-api/middleware.ts
index a5203bc774..32a681b156 100644
--- a/react/features/mobile/external-api/middleware.ts
+++ b/react/features/mobile/external-api/middleware.ts
@@ -51,6 +51,8 @@ import { getLocalTracks, isLocalTrackMuted } from '../../base/tracks/functions.n
import { ITrack } from '../../base/tracks/types';
import { CLOSE_CHAT, OPEN_CHAT } from '../../chat/actionTypes';
import { closeChat, openChat, sendMessage, setPrivateMessageRecipient } from '../../chat/actions.native';
+import { hideNotification, showNotification } from '../../notifications/actions';
+import { NOTIFICATION_TIMEOUT_TYPE, NOTIFICATION_TYPE } from '../../notifications/constants';
import { setRequestingSubtitles } from '../../subtitles/actions.any';
import { CUSTOM_BUTTON_PRESSED } from '../../toolbox/actionTypes';
import { muteLocal } from '../../video-menu/actions.native';
@@ -419,6 +421,35 @@ function _registerForNativeEvents(store: IStore) {
eventEmitter.addListener(ExternalAPI.TOGGLE_CAMERA, () => {
dispatch(toggleCameraFacingMode());
});
+
+ eventEmitter.addListener(ExternalAPI.SHOW_NOTIFICATION,
+ ({ appearance, description, timeout, title, uid }: any) => {
+ const validTypes = Object.values(NOTIFICATION_TYPE);
+ const validTimeouts = Object.values(NOTIFICATION_TIMEOUT_TYPE);
+
+ if (!validTypes.includes(appearance)) {
+ logger.error(`Invalid notification type "${appearance}". Expecting one of ${validTypes}`);
+
+ return;
+ }
+
+ if (!validTimeouts.includes(timeout)) {
+ logger.error(`Invalid notification timeout "${timeout}". Expecting one of ${validTimeouts}`);
+
+ return;
+ }
+
+ dispatch(showNotification({
+ appearance,
+ description,
+ title,
+ uid
+ }, timeout));
+ });
+
+ eventEmitter.addListener(ExternalAPI.HIDE_NOTIFICATION, ({ uid }: any) => {
+ dispatch(hideNotification(uid));
+ });
}
/**
@@ -439,6 +470,8 @@ function _unregisterForNativeEvents() {
eventEmitter.removeAllListeners(ExternalAPI.SEND_CHAT_MESSAGE);
eventEmitter.removeAllListeners(ExternalAPI.SET_CLOSED_CAPTIONS_ENABLED);
eventEmitter.removeAllListeners(ExternalAPI.TOGGLE_CAMERA);
+ eventEmitter.removeAllListeners(ExternalAPI.SHOW_NOTIFICATION);
+ eventEmitter.removeAllListeners(ExternalAPI.HIDE_NOTIFICATION);
}
/**
diff --git a/react/features/notifications/constants.ts b/react/features/notifications/constants.ts
index 7bf47d81f9..cc442fcbcd 100644
--- a/react/features/notifications/constants.ts
+++ b/react/features/notifications/constants.ts
@@ -126,10 +126,3 @@ export const SILENT_JOIN_THRESHOLD = 30;
* Amount of participants beyond which no left notification will be emitted.
*/
export const SILENT_LEFT_THRESHOLD = 30;
-
-/**
- * The identifier for the transcriber notifications.
- *
- * @type {string}
- */
-export const TRANSCRIBING_NOTIFICATION_ID = 'TRANSCRIBING_NOTIFICATION';