-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: [react-native-sdk] Adds screen share support on iOS #14929
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,24 +14,34 @@ | |
* limitations under the License. | ||
*/ | ||
|
||
#import "ScheenshareEventEmiter.h" | ||
#import "JitsiMeet+Private.h" | ||
#import "ExternalAPI.h" | ||
#import "ScreenShareEventEmitter.h" | ||
#import <React/RCTLog.h> | ||
#import <React/RCTBridge.h> | ||
|
||
NSNotificationName const kBroadcastStartedNotification = @"iOS_BroadcastStarted"; | ||
NSNotificationName const kBroadcastStoppedNotification = @"iOS_BroadcastStopped"; | ||
|
||
@implementation ScheenshareEventEmiter { | ||
static NSString * const toggleScreenShareAction = @"org.jitsi.meet.TOGGLE_SCREEN_SHARE"; | ||
|
||
@implementation ScreenShareEventEmitter { | ||
CFNotificationCenterRef _notificationCenter; | ||
bool hasListeners; | ||
} | ||
|
||
RCT_EXPORT_MODULE(); | ||
|
||
- (NSDictionary *)constantsToExport { | ||
return @{ | ||
@"TOGGLE_SCREEN_SHARE": toggleScreenShareAction, | ||
}; | ||
}; | ||
|
||
- (instancetype)init { | ||
self = [super init]; | ||
if (self) { | ||
_notificationCenter = CFNotificationCenterGetDarwinNotifyCenter(); | ||
[self setupObserver]; | ||
} | ||
|
||
return self; | ||
} | ||
|
||
|
@@ -44,29 +54,46 @@ - (void)dealloc { | |
- (void)setupObserver { | ||
CFNotificationCenterAddObserver(_notificationCenter, (__bridge const void *)(self), broadcastStartedNotificationCallback, (__bridge CFStringRef)kBroadcastStartedNotification, NULL, CFNotificationSuspensionBehaviorDeliverImmediately); | ||
CFNotificationCenterAddObserver(_notificationCenter, (__bridge const void *)(self), broadcastStoppedNotificationCallback, (__bridge CFStringRef)kBroadcastStoppedNotification, NULL, CFNotificationSuspensionBehaviorDeliverImmediately); | ||
hasListeners = YES; | ||
} | ||
|
||
- (void)clearObserver { | ||
CFNotificationCenterRemoveObserver(_notificationCenter, (__bridge const void *)(self), (__bridge CFStringRef)kBroadcastStartedNotification, NULL); | ||
CFNotificationCenterRemoveObserver(_notificationCenter, (__bridge const void *)(self), (__bridge CFStringRef)kBroadcastStoppedNotification, NULL); | ||
hasListeners = NO; | ||
} | ||
|
||
void broadcastStartedNotificationCallback(CFNotificationCenterRef center, | ||
void *observer, | ||
CFStringRef name, | ||
const void *object, | ||
CFDictionaryRef userInfo) { | ||
ExternalAPI *externalAPI = [[JitsiMeet sharedInstance] getExternalAPI]; | ||
[externalAPI toggleScreenShare:true]; | ||
ScreenShareEventEmitter *self = (__bridge ScreenShareEventEmitter *)observer; | ||
[self handleBroadcastStarted]; | ||
} | ||
|
||
void broadcastStoppedNotificationCallback(CFNotificationCenterRef center, | ||
void *observer, | ||
CFStringRef name, | ||
const void *object, | ||
CFDictionaryRef userInfo) { | ||
ExternalAPI *externalAPI = [[JitsiMeet sharedInstance] getExternalAPI]; | ||
[externalAPI toggleScreenShare:false]; | ||
ScreenShareEventEmitter *self = (__bridge ScreenShareEventEmitter *)observer; | ||
[self handleBroadcastStopped]; | ||
} | ||
|
||
- (void)handleBroadcastStarted { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thread 1: "Error when sending event: org.jitsi.meet.TOGGLE_SCREEN_SHARE with body: {\n enabled = 1;\n}. RCTCallableJSModules is not set. This is probably because you've explicitly synthesized the RCTCallableJSModules in ScreenShareEventEmitter, even though it's inherited from RCTEventEmitter." |
||
RCTLogInfo(@"Broadcast started"); | ||
[self sendEventWithName:toggleScreenShareAction body:@{@"enabled": @TRUE}]; | ||
} | ||
|
||
- (void)handleBroadcastStopped { | ||
RCTLogInfo(@"Broadcast stopped"); | ||
[self sendEventWithName:toggleScreenShareAction body:@{@"enabled": @FALSE}]; | ||
} | ||
|
||
// Override the supportedEvents method | ||
- (NSArray<NSString *> *)supportedEvents { | ||
return @[toggleScreenShareAction]; | ||
} | ||
|
||
@end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { NativeModules } from 'react-native'; | ||
|
||
/** | ||
* Determines if the ScreenShareEventEmitter native module is available. | ||
* | ||
* @returns {boolean} If yes {@code true} otherwise {@code false}. | ||
*/ | ||
export function isScreenShareAPIAvailable() { | ||
const { ScreenShareEventEmitter } = NativeModules; | ||
|
||
return ScreenShareEventEmitter !== null; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check this warning
Module ScreenShareEventEmitter requires main queue setup since it overrides
constantsToExport
but doesn't implementrequiresMainQueueSetup
. In a future release React Native will default to initializing all native modules on a background thread unless explicitly opted-out of.