Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.
TypeScript debiandeep-videojitsijitsi-meetscalable-video-conferencessfuvideovideo-communicationvideo-conferencingwebrtc
feat(react-native-sdk): add iOS screen sharing support
Calin-Teodor9f9f8bf98b6e
diff --git a/.gitignore b/.gitignoreindex c580515e44..9a71b51f2a 100644--- a/.gitignore+++ b/.gitignore@@ -110,7 +110,9 @@ react-native-sdk/android/src/**!react-native-sdk/android/src/main/java/org/jitsi/meet/sdk/JMOngoingConferenceModule.java!react-native-sdk/android/src/main/java/org/jitsi/meet/sdk/RNOngoingNotification.javareact-native-sdk/images-react-native-sdk/ios+react-native-sdk/ios/**+!react-native-sdk/ios/**/+!react-native-sdk/ios/RNScreenShareEventEmitter.mreact-native-sdk/langreact-native-sdk/modulesreact-native-sdk/node_modulesdiff --git a/react-native-sdk/README.md b/react-native-sdk/README.mdindex cdeabb3b0f..6a4f658c93 100644--- a/react-native-sdk/README.md+++ b/react-native-sdk/README.md@@ -67,6 +67,86 @@ Run;cd ios && pod install && cd ..```+#### Screen share++Screen share on iOS needs a Broadcast Upload Extension in your app. The SDK does not include one.+Screen share works on a physical device with iOS 14 or newer. It does not work in the simulator.++The steps below are complete. For background, see the handbook section+[Creating the Broadcast Upload Extension](https://jitsi.github.io/handbook/docs/dev-guide/dev-guide-ios-sdk/#creating-the-broadcast-upload-extension)+and the [swift-screensharing sample](https://github.com/jitsi/jitsi-meet-sdk-samples/tree/master/ios/swift-screensharing).++**1. Create the extension target**++1. In Xcode, choose File > New > Target.+2. Select the Broadcast Upload Extension template.+3. Set the language to Swift.+4. Clear the "Include UI Extension" checkbox.+5. Click Finish. Xcode creates a folder that contains `SampleHandler.swift`.+6. In the new target, set the iOS Deployment Target to 14.0 or newer.++**2. Add the extension code**++1. Copy these five files from the sample into the extension folder:+ `SampleHandler.swift`, `SampleUploader.swift`, `SocketConnection.swift`,+ `DarwinNotificationCenter.swift`, `Atomic.swift`. Replace the generated `SampleHandler.swift`.+2. Make sure that all five files belong to the extension target. Check File Inspector > Target+ Membership.++**3. Create the app group**++1. Choose an app group id, for example `group.com.example.myapp`.+2. In the Apple Developer portal, register the app group.+3. Assign the app group to the App ID of the app and to the App ID of the extension.+4. In Xcode, add the App Groups capability to the app target. Select the group.+5. Add the App Groups capability to the extension target. Select the same group.+6. In `SampleHandler.swift`, set `Constants.appGroupIdentifier` to the same app group id.++**4. Configure the app**++1. Add two keys to the app `Info.plist`:+ - `RTCAppGroupIdentifier`: the app group id.+ - `RTCScreenSharingExtension`: the bundle id of the extension, for example+ `com.example.myapp.broadcast`.+2. Make sure that Background Modes has Audio and Voice over IP. See "General" above.+3. Pass the feature flag to `JitsiMeeting`. The toolbar then shows the screen share button.+ ```jsx+ <JitsiMeeting flags = {{ 'ios.screensharing.enabled': true }} ... />+ ```++> **Important**+> - The app group id must be the same in three places: `Constants.appGroupIdentifier` in+> `SampleHandler.swift`, the App Groups capability of both targets, and `RTCAppGroupIdentifier`.+> If they are different, the picker opens and the red status bar appears, but no video reaches+> the meeting. The SDK cannot detect this.+> - Do not change the notification names `iOS_BroadcastStarted` and `iOS_BroadcastStopped` in+> `DarwinNotificationCenter.swift`. The SDK listens for these exact names.++**5. Test**++1. Run the app on a physical device.+2. Join a meeting.+3. Tap the screen share button. The system picker opens.+4. Tap Start Broadcast. After the countdown, the red status bar appears and the other+ participants see your screen.+5. Tap the red status bar and stop the broadcast. The screen share ends.++##### Know when screen share starts or stops++Use `eventListeners.onScreenShareToggled({ sharing })`. It fires when the user starts or stops+screen share, from the toolbar button or from the red status bar. It does not fire when the user+dismisses the iOS picker or the Android consent dialog without a start. In that case nothing+changes.++```jsx+ <JitsiMeeting+ eventListeners = {{+ onScreenShareToggled: ({ sharing }) => console.log('screen share', sharing)+ }}+ room = { 'ThisIsNotATestRoomName' }+ serverURL = { 'https://meet.jit.si/' } />+```+## Android- In your build.gradle have at least `minSdkVersion = 26`diff --git a/react-native-sdk/index.tsx b/react-native-sdk/index.tsxindex 19128f4a1e..3a20cc433d 100644--- a/react-native-sdk/index.tsx+++ b/react-native-sdk/index.tsx@@ -35,6 +35,7 @@ interface IEventListeners {onParticipantJoined?: Function;onParticipantLeft?: ({ id }: { id: string }) => void;onReadyToClose?: Function;+ onScreenShareToggled?: ({ sharing }: { sharing: boolean }) => void;}interface IUserInfo {@@ -144,7 +145,8 @@ export const JitsiMeeting = forwardRef<JitsiRefProps, IAppProps>((props, ref) =>onEndpointMessageReceived: eventListeners?.onEndpointMessageReceived,onParticipantJoined: eventListeners?.onParticipantJoined,onParticipantLeft: eventListeners?.onParticipantLeft,- onReadyToClose: eventListeners?.onReadyToClose+ onReadyToClose: eventListeners?.onReadyToClose,+ onScreenShareToggled: eventListeners?.onScreenShareToggled},'url': urlProps,'userInfo': userInfodiff --git a/react-native-sdk/ios/RNScreenShareEventEmitter.m b/react-native-sdk/ios/RNScreenShareEventEmitter.mnew file mode 100644index 0000000000..6bc8d36496--- /dev/null+++ b/react-native-sdk/ios/RNScreenShareEventEmitter.m@@ -0,0 +1,155 @@+/*+ * Copyright @ 2025-present 8x8, Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++/*+ * Observes the Darwin notifications which the Broadcast Upload Extension posts+ * when the user starts or stops a screen share, and forwards them to JS as a+ * single event. The JS side turns the event into toggleScreensharing().+ *+ * Compiled only by the RN SDK pod (jitsi-meet-rnsdk.podspec). The native iOS+ * SDK uses ScheenshareEventEmiter instead, which delivers through ExternalAPI.+ */++#import <React/RCTEventEmitter.h>++static NSString * const kScreenShareToggled = @"org.jitsi.meet:features/screen-share#toggled";++// The Broadcast Upload Extension posts these names. They must stay in sync with+// DarwinNotificationCenter.swift in the consumer's extension.+static NSString * const kBroadcastStartedNotification = @"iOS_BroadcastStarted";+static NSString * const kBroadcastStoppedNotification = @"iOS_BroadcastStopped";++// Info.plist keys which react-native-webrtc reads to find the App Group+// container and the Broadcast Upload Extension.+static NSString * const kRTCAppGroupIdentifier = @"RTCAppGroupIdentifier";+static NSString * const kRTCScreenSharingExtension = @"RTCScreenSharingExtension";++@interface RNScreenShareEventEmitter : RCTEventEmitter++- (void)emitScreenShareToggled:(BOOL)enabled;++@end++static void broadcastStartedNotificationCallback(CFNotificationCenterRef center,+ void *observer,+ CFStringRef name,+ const void *object,+ CFDictionaryRef userInfo);+static void broadcastStoppedNotificationCallback(CFNotificationCenterRef center,+ void *observer,+ CFStringRef name,+ const void *object,+ CFDictionaryRef userInfo);++@implementation RNScreenShareEventEmitter {+ CFNotificationCenterRef _notificationCenter;+ BOOL _observing;+}++RCT_EXPORT_MODULE();+++ (BOOL)requiresMainQueueSetup {+ return NO;+}++- (instancetype)init {+ self = [super init];+ if (self) {+ _notificationCenter = CFNotificationCenterGetDarwinNotifyCenter();+ }++ return self;+}++- (void)dealloc {+ [self stopObserving];+}++- (void)invalidate {+ [self stopObserving];+ [super invalidate];+}++- (NSArray<NSString *> *)supportedEvents {+ return @[ kScreenShareToggled ];+}++- (NSDictionary *)constantsToExport {+ NSDictionary *info = [[NSBundle mainBundle] infoDictionary];++ return @{+ @"SCREEN_SHARE_TOGGLED": kScreenShareToggled,+ @"appGroupIdentifier": info[kRTCAppGroupIdentifier] ?: [NSNull null],+ @"screenSharingExtension": info[kRTCScreenSharingExtension] ?: [NSNull null]+ };+}++// MARK: RCTEventEmitter++- (void)startObserving {+ if (_observing) {+ return;+ }++ _observing = YES;++ CFNotificationCenterAddObserver(_notificationCenter,+ (__bridge const void *)(self),+ broadcastStartedNotificationCallback,+ (__bridge CFStringRef)kBroadcastStartedNotification,+ NULL,+ CFNotificationSuspensionBehaviorDeliverImmediately);+ CFNotificationCenterAddObserver(_notificationCenter,+ (__bridge const void *)(self),+ broadcastStoppedNotificationCallback,+ (__bridge CFStringRef)kBroadcastStoppedNotification,+ NULL,+ CFNotificationSuspensionBehaviorDeliverImmediately);+}++- (void)stopObserving {+ if (!_observing) {+ return;+ }++ _observing = NO;++ CFNotificationCenterRemoveEveryObserver(_notificationCenter, (__bridge const void *)(self));+}++// MARK: Private Methods++- (void)emitScreenShareToggled:(BOOL)enabled {+ [self sendEventWithName:kScreenShareToggled body:@{ @"enabled": @(enabled) }];+}++@end++static void broadcastStartedNotificationCallback(CFNotificationCenterRef center,+ void *observer,+ CFStringRef name,+ const void *object,+ CFDictionaryRef userInfo) {+ [(__bridge RNScreenShareEventEmitter *)observer emitScreenShareToggled:YES];+}++static void broadcastStoppedNotificationCallback(CFNotificationCenterRef center,+ void *observer,+ CFStringRef name,+ const void *object,+ CFDictionaryRef userInfo) {+ [(__bridge RNScreenShareEventEmitter *)observer emitScreenShareToggled:NO];+}diff --git a/react/features/mobile/react-native-sdk/logger.ts b/react/features/mobile/react-native-sdk/logger.tsnew file mode 100644index 0000000000..6eb5d5e905--- /dev/null+++ b/react/features/mobile/react-native-sdk/logger.ts@@ -0,0 +1,3 @@+import { getLogger } from '../../base/logging/functions';++export default getLogger('mobile-app:react-native-sdk');diff --git a/react/features/mobile/react-native-sdk/middleware.js b/react/features/mobile/react-native-sdk/middleware.jsindex 13bf6b3df6..e213b29d87 100644--- a/react/features/mobile/react-native-sdk/middleware.js+++ b/react/features/mobile/react-native-sdk/middleware.js@@ -1,5 +1,6 @@-import { NativeModules } from 'react-native';+import { NativeEventEmitter, NativeModules, Platform } from 'react-native';+import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../../base/app/actionTypes';import { getAppProp } from '../../base/app/functions';import {CONFERENCE_BLURRED,@@ -13,14 +14,63 @@ import { SET_AUDIO_MUTED, SET_VIDEO_MUTED } from '../../base/media/actionTypes';import { PARTICIPANT_JOINED, PARTICIPANT_LEFT } from '../../base/participants/actionTypes';import MiddlewareRegistry from '../../base/redux/MiddlewareRegistry';import StateListenerRegistry from '../../base/redux/StateListenerRegistry';+import { toggleScreensharing } from '../../base/tracks/actions.native';+import { isLocalVideoTrackDesktop } from '../../base/tracks/functions.native';import { READY_TO_CLOSE } from '../external-api/actionTypes';import { participantToParticipantInfo } from '../external-api/functions';import { ENTER_PICTURE_IN_PICTURE } from '../picture-in-picture/actionTypes';import { isExternalAPIAvailable } from './functions';+import logger from './logger';const externalAPIEnabled = isExternalAPIAvailable();-const { JMOngoingConference } = NativeModules;+const { JMOngoingConference, RNScreenShareEventEmitter } = NativeModules;++let screenShareSubscription;++/**+ * Starts listening for the Darwin notifications which the iOS Broadcast Upload+ * Extension posts when the user starts or stops a screen share.+ *+ * @param {Store} store - The redux store.+ * @returns {void}+ */+function _registerForScreenShareEvents(store) {+ // iOS only, and only when the RN SDK pod compiled RNScreenShareEventEmitter.+ // NativeModules.<Name> is null for absent modules, so this also skips Android.+ if (Platform.OS !== 'ios' || !RNScreenShareEventEmitter || screenShareSubscription) {+ return;+ }++ const { appGroupIdentifier, screenSharingExtension } = RNScreenShareEventEmitter;++ if (!appGroupIdentifier || !screenSharingExtension) {+ logger.warn('iOS screen sharing is not configured. Your app must provide a Broadcast Upload '+ + 'Extension and set RTCAppGroupIdentifier and RTCScreenSharingExtension in Info.plist. '+ + 'See the react-native-sdk README, "Screen share".');+ } else {+ logger.info(`iOS screen sharing is set up with extension "${screenSharingExtension}" `+ + `and app group "${appGroupIdentifier}". Please make sure your Broadcast Upload `+ + 'Extension uses the same app group; the SDK cannot check this for you.');+ }++ // Do not gate this on an active conference. When the event arrives the extension is already+ // running and polls the socket with no timeout; a skipped dispatch would leave the red status+ // bar stuck with no way to stop it from the app.+ screenShareSubscription = new NativeEventEmitter(RNScreenShareEventEmitter).addListener(+ RNScreenShareEventEmitter.SCREEN_SHARE_TOGGLED,+ ({ enabled }) => store.dispatch(toggleScreensharing(enabled)));+}++/**+ * Stops listening for the iOS screen share notifications.+ *+ * @returns {void}+ */+function _unregisterForScreenShareEvents() {+ screenShareSubscription?.remove();+ screenShareSubscription = undefined;+}/**@@ -33,6 +83,12 @@ const { JMOngoingConference } = NativeModules;const rnSdkHandlers = getAppProp(store, 'rnSdkHandlers');switch (type) {+ case APP_WILL_MOUNT:+ _registerForScreenShareEvents(store);+ break;+ case APP_WILL_UNMOUNT:+ _unregisterForScreenShareEvents();+ break;case SET_AUDIO_MUTED:rnSdkHandlers?.onAudioMutedChanged?.(action.muted);break;@@ -106,3 +162,18 @@ JMOngoingConference && !externalAPIEnabled && StateListenerRegistry.register(}});++/**+ * Notifies the SDK consumer when a screen share starts or stops, whichever way it was triggered.+ */+!externalAPIEnabled && StateListenerRegistry.register(+ state => isLocalVideoTrackDesktop(state),+ (sharing, store, previousSharing) => {+ if (typeof previousSharing === 'undefined') {+ // Initial invocation, nothing was toggled yet.+ return;+ }++ getAppProp(store, 'rnSdkHandlers')?.onScreenShareToggled?.({ sharing });+ }+);