init
Some checks failed
Close stale issues and PRs / stale (push) Has been cancelled

This commit is contained in:
2025-09-02 14:49:16 +08:00
commit 38ba663466
2885 changed files with 391107 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1020"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "0BD906E41EC0C00300C8C18E"
BuildableName = "JitsiMeetSDK.framework"
BlueprintName = "JitsiMeetSDK"
ReferencedContainer = "container:sdk.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "0BD906E41EC0C00300C8C18E"
BuildableName = "JitsiMeetSDK.framework"
BlueprintName = "JitsiMeetSDK"
ReferencedContainer = "container:sdk.xcodeproj">
</BuildableReference>
</MacroExpansion>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "0BD906E41EC0C00300C8C18E"
BuildableName = "JitsiMeetSDK.framework"
BlueprintName = "JitsiMeetSDK"
ReferencedContainer = "container:sdk.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

View File

@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1340"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "DE9A012D289A9A9A00E41CBB"
BuildableName = "JitsiMeetSDK.framework"
BlueprintName = "JitsiMeetSDKLite"
ReferencedContainer = "container:sdk.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "DE9A012D289A9A9A00E41CBB"
BuildableName = "JitsiMeetSDK.framework"
BlueprintName = "JitsiMeetSDKLite"
ReferencedContainer = "container:sdk.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

102
ios/sdk/src/AppInfo.m Normal file
View File

@@ -0,0 +1,102 @@
/*
* Copyright @ 2017-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.
*/
#import <AVFoundation/AVFoundation.h>
#import <React/RCTBridgeModule.h>
#import <React/RCTLog.h>
#import "InfoPlistUtil.h"
@interface AppInfo : NSObject<RCTBridgeModule>
@end
@implementation AppInfo
RCT_EXPORT_MODULE();
+ (BOOL)requiresMainQueueSetup {
return NO;
}
- (NSDictionary *)constantsToExport {
NSDictionary<NSString *, id> *infoDictionary
= [[NSBundle mainBundle] infoDictionary];
// calendarEnabled
BOOL calendarEnabled = NO;
#if !defined(JITSI_MEET_SDK_LITE)
calendarEnabled = infoDictionary[@"NSCalendarsUsageDescription"] != nil;
#endif
// name
NSString *name = infoDictionary[@"CFBundleDisplayName"];
if (name == nil) {
name = infoDictionary[@"CFBundleName"];
if (name == nil) {
name = @"";
}
}
// sdkBundlePath
NSString *sdkBundlePath = [[NSBundle bundleForClass:self.class] bundlePath];
// version
NSString *version = infoDictionary[@"CFBundleShortVersionString"];
if (version == nil) {
version = infoDictionary[@"CFBundleVersion"];
if (version == nil) {
version = @"";
}
}
// SDK version
NSDictionary<NSString *, id> *sdkInfoDictionary
= [[NSBundle bundleForClass:self.class] infoDictionary];
NSString *sdkVersion = sdkInfoDictionary[@"CFBundleShortVersionString"];
if (sdkVersion == nil) {
sdkVersion = @"";
}
// build number
NSString *buildNumber = infoDictionary[@"CFBundleVersion"];
if (buildNumber == nil) {
buildNumber = @"";
}
// google services (sign in)
BOOL isGoogleServiceEnabled = [InfoPlistUtil containsRealServiceInfoPlistInBundle:[NSBundle mainBundle]];
// lite SDK
BOOL isLiteSDK = NO;
#if defined(JITSI_MEET_SDK_LITE)
isLiteSDK = YES;
#endif
return @{
@"calendarEnabled": [NSNumber numberWithBool:calendarEnabled],
@"buildNumber": buildNumber,
@"isLiteSDK": [NSNumber numberWithBool:isLiteSDK],
@"name": name,
@"sdkBundlePath": sdkBundlePath,
@"sdkVersion": sdkVersion,
@"version": version,
@"GOOGLE_SERVICES_ENABLED": [NSNumber numberWithBool:isGoogleServiceEnabled]
};
};
@end

430
ios/sdk/src/AudioMode.m Normal file
View File

@@ -0,0 +1,430 @@
/*
* Copyright @ 2017-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.
*/
#import <AVFoundation/AVFoundation.h>
#import <React/RCTEventEmitter.h>
#import <React/RCTLog.h>
#import <WebRTC/WebRTC.h>
#import "JitsiAudioSession+Private.h"
#import "callkit/JMCallKitProxy.h"
// Audio mode
typedef enum {
kAudioModeDefault,
kAudioModeAudioCall,
kAudioModeVideoCall
} JitsiMeetAudioMode;
// Events
static NSString * const kDevicesChanged = @"org.jitsi.meet:features/audio-mode#devices-update";
// Device types (must match JS and Java)
static NSString * const kDeviceTypeBluetooth = @"BLUETOOTH";
static NSString * const kDeviceTypeCar = @"CAR";
static NSString * const kDeviceTypeEarpiece = @"EARPIECE";
static NSString * const kDeviceTypeHeadphones = @"HEADPHONES";
static NSString * const kDeviceTypeSpeaker = @"SPEAKER";
static NSString * const kDeviceTypeUnknown = @"UNKNOWN";
@interface AudioMode : RCTEventEmitter<RTCAudioSessionDelegate>
@property(nonatomic, strong) dispatch_queue_t workerQueue;
@end
@implementation AudioMode {
JitsiMeetAudioMode activeMode;
RTCAudioSessionConfiguration *defaultConfig;
RTCAudioSessionConfiguration *audioCallConfig;
RTCAudioSessionConfiguration *videoCallConfig;
RTCAudioSessionConfiguration *earpieceConfig;
BOOL audioDisabled;
BOOL forceSpeaker;
BOOL forceEarpiece;
BOOL isSpeakerOn;
BOOL isEarpieceOn;
}
RCT_EXPORT_MODULE();
+ (BOOL)requiresMainQueueSetup {
return NO;
}
- (NSArray<NSString *> *)supportedEvents {
return @[ kDevicesChanged ];
}
- (NSDictionary *)constantsToExport {
return @{
@"DEVICE_CHANGE_EVENT": kDevicesChanged,
@"AUDIO_CALL" : [NSNumber numberWithInt: kAudioModeAudioCall],
@"DEFAULT" : [NSNumber numberWithInt: kAudioModeDefault],
@"VIDEO_CALL" : [NSNumber numberWithInt: kAudioModeVideoCall]
};
};
- (instancetype)init {
self = [super init];
if (self) {
dispatch_queue_attr_t attributes =
dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_USER_INITIATED, -1);
_workerQueue = dispatch_queue_create("AudioMode.queue", attributes);
activeMode = kAudioModeDefault;
defaultConfig = [[RTCAudioSessionConfiguration alloc] init];
defaultConfig.category = AVAudioSessionCategoryAmbient;
defaultConfig.categoryOptions = 0;
defaultConfig.mode = AVAudioSessionModeDefault;
audioCallConfig = [[RTCAudioSessionConfiguration alloc] init];
audioCallConfig.category = AVAudioSessionCategoryPlayAndRecord;
audioCallConfig.categoryOptions = AVAudioSessionCategoryOptionAllowBluetooth | AVAudioSessionCategoryOptionDefaultToSpeaker;
audioCallConfig.mode = AVAudioSessionModeVoiceChat;
videoCallConfig = [[RTCAudioSessionConfiguration alloc] init];
videoCallConfig.category = AVAudioSessionCategoryPlayAndRecord;
videoCallConfig.categoryOptions = AVAudioSessionCategoryOptionAllowBluetooth;
videoCallConfig.mode = AVAudioSessionModeVideoChat;
// Manually routing audio to the earpiece doesn't quite work unless one disables BT (weird, I know).
earpieceConfig = [[RTCAudioSessionConfiguration alloc] init];
earpieceConfig.category = AVAudioSessionCategoryPlayAndRecord;
earpieceConfig.categoryOptions = 0;
earpieceConfig.mode = AVAudioSessionModeVoiceChat;
forceSpeaker = NO;
forceEarpiece = NO;
isSpeakerOn = NO;
isEarpieceOn = NO;
RTCAudioSession *session = JitsiAudioSession.rtcAudioSession;
[session addDelegate:self];
}
return self;
}
- (dispatch_queue_t)methodQueue {
// Use a dedicated queue for audio mode operations.
return _workerQueue;
}
- (BOOL)setConfigWithoutLock:(RTCAudioSessionConfiguration *)config
error:(NSError * _Nullable *)outError {
RTCAudioSession *session = JitsiAudioSession.rtcAudioSession;
return [session setConfiguration:config error:outError];
}
- (BOOL)setConfig:(RTCAudioSessionConfiguration *)config
error:(NSError * _Nullable *)outError {
RTCAudioSession *session = JitsiAudioSession.rtcAudioSession;
[session lockForConfiguration];
BOOL success = [self setConfigWithoutLock:config error:outError];
[session unlockForConfiguration];
return success;
}
#pragma mark - Exported methods
RCT_EXPORT_METHOD(setDisabled:(BOOL)disabled
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject) {
if (audioDisabled == disabled) {
resolve(nil);
return;
}
RCTLogInfo(@"[AudioMode] audio disabled: %d", disabled);
audioDisabled = disabled;
JMCallKitProxy.enabled = !disabled;
RTCAudioSession *session = JitsiAudioSession.rtcAudioSession;
if (disabled) {
[session removeDelegate:self];
} else {
[session addDelegate:self];
}
session.useManualAudio = disabled;
}
RCT_EXPORT_METHOD(setMode:(int)mode
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject) {
if (audioDisabled) {
resolve(nil);
return;
}
RTCAudioSessionConfiguration *config = [self configForMode:mode];
NSError *error;
if (config == nil) {
reject(@"setMode", @"Invalid mode", nil);
return;
}
// Reset.
if (mode == kAudioModeDefault) {
forceSpeaker = NO;
forceEarpiece = NO;
}
activeMode = mode;
if ([self setConfig:config error:&error]) {
resolve(nil);
} else {
reject(@"setMode", error.localizedDescription, error);
}
[self notifyDevicesChanged];
}
RCT_EXPORT_METHOD(setAudioDevice:(NSString *)device
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject) {
if (audioDisabled) {
resolve(nil);
return;
}
RCTLogInfo(@"[AudioMode] Selected device: %@", device);
RTCAudioSession *session = JitsiAudioSession.rtcAudioSession;
[session lockForConfiguration];
BOOL success;
NSError *error = nil;
// Reset these, as we are about to compute them.
forceSpeaker = NO;
forceEarpiece = NO;
// The speaker is special, so test for it first.
if ([device isEqualToString:kDeviceTypeSpeaker]) {
forceSpeaker = YES;
success = [session overrideOutputAudioPort:AVAudioSessionPortOverrideSpeaker error:&error];
} else {
// Here we use AVAudioSession because RTCAudioSession doesn't expose availableInputs.
AVAudioSession *_session = [AVAudioSession sharedInstance];
AVAudioSessionPortDescription *port = nil;
// Find the matching input device.
for (AVAudioSessionPortDescription *portDesc in _session.availableInputs) {
if ([portDesc.UID isEqualToString:device]) {
port = portDesc;
break;
}
}
if (port != nil) {
// First remove the override if we are going to select a different device.
if (isSpeakerOn) {
[session overrideOutputAudioPort:AVAudioSessionPortOverrideNone error:nil];
}
// Special case for the earpiece.
if ([port.portType isEqualToString:AVAudioSessionPortBuiltInMic]) {
forceEarpiece = YES;
[self setConfigWithoutLock:earpieceConfig error:nil];
} else if (isEarpieceOn) {
// Reset the config.
RTCAudioSessionConfiguration *config = [self configForMode:activeMode];
[self setConfigWithoutLock:config error:nil];
}
// Select our preferred input.
success = [session setPreferredInput:port error:&error];
} else {
success = NO;
error = RCTErrorWithMessage(@"Could not find audio device");
}
}
[session unlockForConfiguration];
if (success) {
resolve(nil);
} else {
reject(@"setAudioDevice", error != nil ? error.localizedDescription : @"", error);
}
}
RCT_EXPORT_METHOD(updateDeviceList) {
if (audioDisabled) {
return;
}
[self notifyDevicesChanged];
}
#pragma mark - RTCAudioSessionDelegate
- (void)audioSessionDidChangeRoute:(RTCAudioSession *)session
reason:(AVAudioSessionRouteChangeReason)reason
previousRoute:(AVAudioSessionRouteDescription *)previousRoute {
RCTLogInfo(@"[AudioMode] Route changed, reason: %lu", (unsigned long)reason);
// Update JS about the changes.
[self notifyDevicesChanged];
dispatch_async(_workerQueue, ^{
switch (reason) {
case AVAudioSessionRouteChangeReasonNewDeviceAvailable:
case AVAudioSessionRouteChangeReasonOldDeviceUnavailable:
// If the device list changed, reset our overrides.
self->forceSpeaker = NO;
self->forceEarpiece = NO;
break;
case AVAudioSessionRouteChangeReasonCategoryChange:
// The category has changed, re-apply our config.
// NB: It's tempting to doa category check here and skip the processing,
// but that won't work. If the config changes but the category remains
// the same we'll still find ourselves here.
break;
default:
return;
}
// We don't want to touch the category when in default mode.
// This is to play well with other components which could be integrated
// into the final application.
if (self->activeMode != kAudioModeDefault) {
RCTLogInfo(@"[AudioMode] Route changed, reapplying RTCAudioSession config");
RTCAudioSessionConfiguration *config = [self configForMode:self->activeMode];
[self setConfig:config error:nil];
if (self->forceSpeaker && !self->isSpeakerOn) {
[session lockForConfiguration];
[session overrideOutputAudioPort:AVAudioSessionPortOverrideSpeaker error:nil];
[session unlockForConfiguration];
}
}
});
}
- (void)audioSession:(RTCAudioSession *)audioSession didSetActive:(BOOL)active {
RCTLogInfo(@"[AudioMode] Audio session didSetActive:%d", active);
}
#pragma mark - Helper methods
- (RTCAudioSessionConfiguration *)configForMode:(int) mode {
if (mode != kAudioModeDefault && forceEarpiece) {
return earpieceConfig;
}
switch (mode) {
case kAudioModeAudioCall:
return audioCallConfig;
case kAudioModeDefault:
return defaultConfig;
case kAudioModeVideoCall:
return videoCallConfig;
default:
return nil;
}
}
// Here we convert input and output port types into a single type.
- (NSString *)portTypeToString:(AVAudioSessionPort) portType {
if ([portType isEqualToString:AVAudioSessionPortHeadphones]
|| [portType isEqualToString:AVAudioSessionPortHeadsetMic]) {
return kDeviceTypeHeadphones;
} else if ([portType isEqualToString:AVAudioSessionPortBuiltInMic]
|| [portType isEqualToString:AVAudioSessionPortBuiltInReceiver]) {
return kDeviceTypeEarpiece;
} else if ([portType isEqualToString:AVAudioSessionPortBuiltInSpeaker]) {
return kDeviceTypeSpeaker;
} else if ([portType isEqualToString:AVAudioSessionPortBluetoothHFP]
|| [portType isEqualToString:AVAudioSessionPortBluetoothLE]
|| [portType isEqualToString:AVAudioSessionPortBluetoothA2DP]) {
return kDeviceTypeBluetooth;
} else if ([portType isEqualToString:AVAudioSessionPortCarAudio]) {
return kDeviceTypeCar;
} else {
return kDeviceTypeUnknown;
}
}
- (void)notifyDevicesChanged {
dispatch_async(_workerQueue, ^{
NSMutableArray *data = [[NSMutableArray alloc] init];
// Here we use AVAudioSession because RTCAudioSession doesn't expose availableInputs.
AVAudioSession *session = [AVAudioSession sharedInstance];
NSString *currentPort = @"";
AVAudioSessionRouteDescription *currentRoute = session.currentRoute;
// Check what the current device is. Because the speaker is somewhat special, we need to
// check for it first.
if (currentRoute != nil) {
AVAudioSessionPortDescription *output = currentRoute.outputs.firstObject;
AVAudioSessionPortDescription *input = currentRoute.inputs.firstObject;
if (output != nil && [output.portType isEqualToString:AVAudioSessionPortBuiltInSpeaker]) {
currentPort = kDeviceTypeSpeaker;
self->isSpeakerOn = YES;
} else if (input != nil) {
currentPort = input.UID;
self->isSpeakerOn = NO;
self->isEarpieceOn = [input.portType isEqualToString:AVAudioSessionPortBuiltInMic];
}
}
BOOL headphonesAvailable = NO;
for (AVAudioSessionPortDescription *portDesc in session.availableInputs) {
if ([portDesc.portType isEqualToString:AVAudioSessionPortHeadsetMic] || [portDesc.portType isEqualToString:AVAudioSessionPortHeadphones]) {
headphonesAvailable = YES;
break;
}
}
for (AVAudioSessionPortDescription *portDesc in session.availableInputs) {
// Skip "Phone" if headphones are present.
if (headphonesAvailable && [portDesc.portType isEqualToString:AVAudioSessionPortBuiltInMic]) {
continue;
}
id deviceData
= @{
@"type": [self portTypeToString:portDesc.portType],
@"name": portDesc.portName,
@"uid": portDesc.UID,
@"selected": [NSNumber numberWithBool:[portDesc.UID isEqualToString:currentPort]]
};
[data addObject:deviceData];
}
// We need to manually add the speaker because it will never show up in the
// previous list, as it's not an input.
[data addObject:
@{ @"type": kDeviceTypeSpeaker,
@"name": @"Speaker",
@"uid": kDeviceTypeSpeaker,
@"selected": [NSNumber numberWithBool:[kDeviceTypeSpeaker isEqualToString:currentPort]]
}];
[self sendEventWithName:kDevicesChanged body:data];
});
}
@end

41
ios/sdk/src/ExternalAPI.h Normal file
View File

@@ -0,0 +1,41 @@
/* Copyright @ 2021-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.
*/
#import <React/RCTBridgeModule.h>
#import <React/RCTEventEmitter.h>
static NSString * const sendEventNotificationName = @"org.jitsi.meet.SendEvent";
@interface ExternalAPI : RCTEventEmitter<RCTBridgeModule>
- (void)sendHangUp;
- (void)sendSetAudioMuted:(BOOL)muted;
- (void)sendEndpointTextMessage:(NSString*)message :(NSString*)to;
- (void)toggleScreenShare:(BOOL)enabled;
- (void)retrieveParticipantsInfo:(void (^)(NSArray*))completion;
- (void)openChat:(NSString*)to;
- (void)closeChat;
- (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;
- (void)startRecording:(NSString*)mode :(NSString*)dropboxToken :(BOOL)shouldShare :(NSString*)rtmpStreamKey :(NSString*)rtmpBroadcastID :(NSString*)youtubeStreamKey :(NSString*)youtubeBroadcastID :(NSDictionary*)extraMetadata :(BOOL)transcription;
- (void)stopRecording:(NSString*)mode :(BOOL)transcription;
- (void)overwriteConfig:(NSDictionary*)config;
- (void)sendCameraFacingModeMessage:(NSString*)to :(NSString*)facingMode;
@end

260
ios/sdk/src/ExternalAPI.m Normal file
View File

@@ -0,0 +1,260 @@
/*
* Copyright @ 2017-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.
*/
#import "ExternalAPI.h"
// Events
static NSString * const hangUpAction = @"org.jitsi.meet.HANG_UP";
static NSString * const setAudioMutedAction = @"org.jitsi.meet.SET_AUDIO_MUTED";
static NSString * const sendEndpointTextMessageAction = @"org.jitsi.meet.SEND_ENDPOINT_TEXT_MESSAGE";
static NSString * const toggleScreenShareAction = @"org.jitsi.meet.TOGGLE_SCREEN_SHARE";
static NSString * const retrieveParticipantsInfoAction = @"org.jitsi.meet.RETRIEVE_PARTICIPANTS_INFO";
static NSString * const openChatAction = @"org.jitsi.meet.OPEN_CHAT";
static NSString * const closeChatAction = @"org.jitsi.meet.CLOSE_CHAT";
static NSString * const sendChatMessageAction = @"org.jitsi.meet.SEND_CHAT_MESSAGE";
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";
static NSString * const startRecordingAction = @"org.jitsi.meet.START_RECORDING";
static NSString * const stopRecordingAction = @"org.jitsi.meet.STOP_RECORDING";
static NSString * const overwriteConfigAction = @"org.jitsi.meet.OVERWRITE_CONFIG";
static NSString * const sendCameraFacingModeMessageAction = @"org.jitsi.meet.SEND_CAMERA_FACING_MODE_MESSAGE";
@implementation ExternalAPI
static NSMapTable<NSString*, void (^)(NSArray* participantsInfo)> *participantInfoCompletionHandlers;
__attribute__((constructor))
static void initializeViewsMap(void) {
participantInfoCompletionHandlers = [NSMapTable strongToStrongObjectsMapTable];
}
RCT_EXPORT_MODULE();
- (NSDictionary *)constantsToExport {
return @{
@"HANG_UP": hangUpAction,
@"SET_AUDIO_MUTED" : setAudioMutedAction,
@"SEND_ENDPOINT_TEXT_MESSAGE": sendEndpointTextMessageAction,
@"TOGGLE_SCREEN_SHARE": toggleScreenShareAction,
@"RETRIEVE_PARTICIPANTS_INFO": retrieveParticipantsInfoAction,
@"OPEN_CHAT": openChatAction,
@"CLOSE_CHAT": closeChatAction,
@"SEND_CHAT_MESSAGE": sendChatMessageAction,
@"SET_VIDEO_MUTED" : setVideoMutedAction,
@"SET_CLOSED_CAPTIONS_ENABLED": setClosedCaptionsEnabledAction,
@"TOGGLE_CAMERA": toggleCameraAction,
@"SHOW_NOTIFICATION": showNotificationAction,
@"HIDE_NOTIFICATION": hideNotificationAction,
@"START_RECORDING": startRecordingAction,
@"STOP_RECORDING": stopRecordingAction,
@"OVERWRITE_CONFIG": overwriteConfigAction,
@"SEND_CAMERA_FACING_MODE_MESSAGE": sendCameraFacingModeMessageAction
};
};
/**
* Make sure all methods in this module are invoked on the main/UI thread.
*/
- (dispatch_queue_t)methodQueue {
return dispatch_get_main_queue();
}
+ (BOOL)requiresMainQueueSetup {
return NO;
}
- (NSArray<NSString *> *)supportedEvents {
return @[ hangUpAction,
setAudioMutedAction,
sendEndpointTextMessageAction,
toggleScreenShareAction,
retrieveParticipantsInfoAction,
openChatAction,
closeChatAction,
sendChatMessageAction,
setVideoMutedAction,
setClosedCaptionsEnabledAction,
toggleCameraAction,
showNotificationAction,
hideNotificationAction,
startRecordingAction,
stopRecordingAction,
overwriteConfigAction,
sendCameraFacingModeMessageAction
];
}
/**
* Dispatches an event that occurred on JavaScript to the view's delegate.
*
* @param name The name of the event.
* @param data The details/specifics of the event to send determined
* by/associated with the specified `name`.
* @param scope
*/
RCT_EXPORT_METHOD(sendEvent:(NSString *)name
data:(NSDictionary *)data) {
if ([name isEqual: @"PARTICIPANTS_INFO_RETRIEVED"]) {
[self onParticipantsInfoRetrieved: data];
return;
}
[[NSNotificationCenter defaultCenter] postNotificationName:sendEventNotificationName
object:nil
userInfo:@{@"name": name, @"data": data}];
}
- (void) onParticipantsInfoRetrieved:(NSDictionary *)data {
NSArray *participantsInfoArray = [data objectForKey:@"participantsInfo"];
NSString *completionHandlerId = [data objectForKey:@"requestId"];
void (^completionHandler)(NSArray*) = [participantInfoCompletionHandlers objectForKey:completionHandlerId];
completionHandler(participantsInfoArray);
[participantInfoCompletionHandlers removeObjectForKey:completionHandlerId];
}
- (void)sendHangUp {
[self sendEventWithName:hangUpAction body:nil];
}
- (void)sendSetAudioMuted:(BOOL)muted {
NSDictionary *data = @{ @"muted": [NSNumber numberWithBool:muted]};
[self sendEventWithName:setAudioMutedAction body:data];
}
- (void)sendEndpointTextMessage:(NSString*)message :(NSString*)to {
NSMutableDictionary *data = [[NSMutableDictionary alloc] init];
data[@"to"] = to;
data[@"message"] = message;
[self sendEventWithName:sendEndpointTextMessageAction body:data];
}
- (void)toggleScreenShare:(BOOL)enabled {
NSMutableDictionary *data = [[NSMutableDictionary alloc] init];
data[@"enabled"] = [NSNumber numberWithBool:enabled];
[self sendEventWithName:toggleScreenShareAction body:data];
}
- (void)retrieveParticipantsInfo:(void (^)(NSArray*))completionHandler {
NSString *completionHandlerId = [[NSUUID UUID] UUIDString];
NSDictionary *data = @{ @"requestId": completionHandlerId};
[participantInfoCompletionHandlers setObject:[completionHandler copy] forKey:completionHandlerId];
[self sendEventWithName:retrieveParticipantsInfoAction body:data];
}
- (void)openChat:(NSString*)to {
NSMutableDictionary *data = [[NSMutableDictionary alloc] init];
data[@"to"] = to;
[self sendEventWithName:openChatAction body:data];
}
- (void)closeChat {
[self sendEventWithName:closeChatAction body:nil];
}
- (void)sendChatMessage:(NSString*)message :(NSString*)to {
NSMutableDictionary *data = [[NSMutableDictionary alloc] init];
data[@"to"] = to;
data[@"message"] = message;
[self sendEventWithName:sendChatMessageAction body:data];
}
- (void)sendSetVideoMuted:(BOOL)muted {
NSDictionary *data = @{ @"muted": [NSNumber numberWithBool:muted]};
[self sendEventWithName:setVideoMutedAction body:data];
}
- (void)sendSetClosedCaptionsEnabled:(BOOL)enabled {
NSDictionary *data = @{ @"enabled": [NSNumber numberWithBool:enabled]};
[self sendEventWithName:setClosedCaptionsEnabledAction body:data];
}
- (void)toggleCamera {
[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];
}
- (void)startRecording:(NSString*)mode :(NSString*)dropboxToken :(BOOL)shouldShare :(NSString*)rtmpStreamKey :(NSString*)rtmpBroadcastID :(NSString*)youtubeStreamKey :(NSString*)youtubeBroadcastID :(NSDictionary*)extraMetadata :(BOOL)transcription {
NSDictionary *data = @{
@"mode": mode,
@"dropboxToken": dropboxToken,
@"shouldShare": @(shouldShare),
@"rtmpStreamKey": rtmpStreamKey,
@"rtmpBroadcastID": rtmpBroadcastID,
@"youtubeStreamKey": youtubeStreamKey,
@"youtubeBroadcastID": youtubeBroadcastID,
@"extraMetadata": extraMetadata,
@"transcription": @(transcription)
};
[self sendEventWithName:startRecordingAction body:data];
}
- (void)stopRecording:(NSString*)mode :(BOOL)transcription {
NSDictionary *data = @{
@"mode": mode,
@"transcription": @(transcription)
};
[self sendEventWithName:stopRecordingAction body:data];
}
- (void)overwriteConfig:(NSDictionary*)config {
NSDictionary *data = @{
@"config": config
};
[self sendEventWithName:overwriteConfigAction body:data];
}
- (void)sendCameraFacingModeMessage:(NSString*)to :(NSString*)facingMode {
NSDictionary *data = @{
@"to": to,
@"facingMode": facingMode
};
[self sendEventWithName:sendCameraFacingModeMessageAction body:data];
}
@end

24
ios/sdk/src/Info.plist Normal file
View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>99.0.0</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
</plist>

View File

@@ -0,0 +1,23 @@
/*
* Copyright @ 2019-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.
*/
#import <Foundation/Foundation.h>
@interface InfoPlistUtil : NSObject
+ (BOOL)containsRealServiceInfoPlistInBundle:(NSBundle *)bundle;
@end

View File

@@ -0,0 +1,52 @@
/*
* Copyright @ 2019-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.
*/
#import "InfoPlistUtil.h"
// Plist file name.
NSString *const kGoogleServiceInfoFileName = @"GoogleService-Info";
// Plist file type.
NSString *const kGoogleServiceInfoFileType = @"plist";
NSString *const kGoogleAppIDPlistKey = @"GOOGLE_APP_ID";
@implementation InfoPlistUtil
+ (BOOL)containsRealServiceInfoPlistInBundle:(NSBundle *)bundle {
NSString *bundlePath = bundle.bundlePath;
if (!bundlePath.length) {
return NO;
}
NSString *plistFilePath = [bundle pathForResource:kGoogleServiceInfoFileName
ofType:kGoogleServiceInfoFileType];
if (!plistFilePath.length) {
return NO;
}
NSDictionary *plist = [NSDictionary dictionaryWithContentsOfFile:plistFilePath];
if (!plist) {
return NO;
}
// Perform a very naive validation by checking to see if the plist has the dummy google app id
NSString *googleAppID = plist[kGoogleAppIDPlistKey];
if (!googleAppID.length) {
return NO;
}
return YES;
}
@end

View File

@@ -0,0 +1,55 @@
/*
* Copyright @ 2019-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.
*/
@import JavaScriptCore;
#import <React/RCTBridgeModule.h>
@interface JavaScriptSandbox : NSObject<RCTBridgeModule>
@end
@implementation JavaScriptSandbox
RCT_EXPORT_MODULE();
+ (BOOL)requiresMainQueueSetup {
return NO;
}
#pragma mark - Exported methods
RCT_EXPORT_METHOD(evaluate:(NSString *)code
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject) {
__block BOOL hasError = NO;
JSContext *ctx = [[JSContext alloc] init];
ctx.exceptionHandler = ^(JSContext *context, JSValue *exception) {
hasError = YES;
reject(@"evaluate", [exception toString], nil);
};
JSValue *ret = [ctx evaluateScript:code];
if (!hasError) {
NSString *result = [ret toString];
if (result == nil) {
reject(@"evaluate", @"Error in string coercion", nil);
} else {
resolve(result);
}
}
}
@end

View File

@@ -0,0 +1,24 @@
/*
* Copyright @ 2017-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.
*/
#import "JitsiAudioSession.h"
#import <WebRTC/WebRTC.h>
@interface JitsiAudioSession (Private)
+ (RTCAudioSession *)rtcAudioSession;
@end

View File

@@ -0,0 +1,26 @@
/*
* Copyright @ 2017-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.
*/
#import <Foundation/Foundation.h>
@class AVAudioSession;
@interface JitsiAudioSession : NSObject
+ (void)activateWithAudioSession:(AVAudioSession *)session;
+ (void)deactivateWithAudioSession:(AVAudioSession *)session;
@end

View File

@@ -0,0 +1,34 @@
/*
* Copyright @ 2017-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.
*/
#import "JitsiAudioSession.h"
#import "JitsiAudioSession+Private.h"
@implementation JitsiAudioSession
+ (RTCAudioSession *)rtcAudioSession {
return [RTCAudioSession sharedInstance];
}
+ (void)activateWithAudioSession:(AVAudioSession *)session {
[self.rtcAudioSession audioSessionDidActivate:session];
}
+ (void)deactivateWithAudioSession:(AVAudioSession *)session {
[self.rtcAudioSession audioSessionDidDeactivate:session];
}
@end

View File

@@ -0,0 +1,28 @@
/*
* Copyright @ 2019-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.
*/
#import <React/RCTBridge.h>
#import "ExternalAPI.h"
#import "JitsiMeet.h"
@interface JitsiMeet ()
- (NSDictionary *)getDefaultProps;
- (RCTBridge *)getReactBridge;
- (ExternalAPI *)getExternalAPI;
@end

108
ios/sdk/src/JitsiMeet.h Normal file
View File

@@ -0,0 +1,108 @@
/*
* Copyright @ 2017-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.
*/
@import UIKit;
@import Foundation;
#import <JitsiMeetSDK/JitsiMeetConferenceOptions.h>
// Matches RTCLoggingSeverity from RTCLogging.h
typedef NS_ENUM(NSInteger, WebRTCLoggingSeverity) {
WebRTCLoggingSeverityVerbose,
WebRTCLoggingSeverityInfo,
WebRTCLoggingSeverityWarning,
WebRTCLoggingSeverityError,
WebRTCLoggingSeverityNone,
};
@interface JitsiMeet : NSObject
/**
* Name for the conference NSUserActivity type. This is used when integrating with
* SiriKit or Handoff, for example.
*/
@property (copy, nonatomic, nullable) NSString *conferenceActivityType;
/**
* Custom URL scheme used for deep-linking.
*/
@property (copy, nonatomic, nullable) NSString *customUrlScheme;
/**
* List of domains used for universal linking.
*/
@property (copy, nonatomic, nullable) NSArray<NSString *> *universalLinkDomains;
/**
* Default conference options used for all conferences. These options will be merged
* with those passed to JitsiMeetView.join when joining a conference.
*/
@property (nonatomic, nullable) JitsiMeetConferenceOptions *defaultConferenceOptions;
/**
* Custom RTCAudioDevice implementation.
* https://github.com/jitsi/webrtc/blob/M124/sdk/objc/components/audio/RTCAudioDevice.h
* https://github.com/mstyura/RTCAudioDevice
*/
@property (nonatomic, strong, nullable) id rtcAudioDevice;
/**
* Specify WebRTC logging severity.
*/
@property (nonatomic, assign) WebRTCLoggingSeverity webRtcLoggingSeverity;
#pragma mark - This class is a singleton
+ (instancetype _Nonnull)sharedInstance;
#pragma mark - Methods that the App delegate must call
- (BOOL)application:(UIApplication *_Nonnull)application
didFinishLaunchingWithOptions:(NSDictionary *_Nonnull)launchOptions;
- (BOOL)application:(UIApplication *_Nonnull)application
continueUserActivity:(NSUserActivity *_Nonnull)userActivity
restorationHandler:(void (^_Nullable)(NSArray<id<UIUserActivityRestoring>> *_Nonnull))restorationHandler;
- (BOOL)application:(UIApplication *_Nonnull)app
openURL:(NSURL *_Nonnull)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *_Nonnull)options;
- (UIInterfaceOrientationMask)application:(UIApplication *_Nonnull)application
supportedInterfaceOrientationsForWindow:(UIWindow *_Nullable)window;
#pragma mark - Utility methods
/**
* Once the react native bridge is destroyed you are responsible for reinstantiating it back. Use this method to do so.
*/
- (void)instantiateReactNativeBridge;
/**
* Helper method to destroy the react native bridge, cleaning up resources in the process. Once the react native bridge is destroyed you are responsible for reinstantiating it back using `instantiateReactNativeBridge` method.
*/
- (void)destroyReactNativeBridge;
- (JitsiMeetConferenceOptions *_Nonnull)getInitialConferenceOptions;
- (BOOL)isCrashReportingDisabled;
/**
* Shows the splash screen.
*/
- (void)showSplashScreen;
@end

270
ios/sdk/src/JitsiMeet.m Normal file
View File

@@ -0,0 +1,270 @@
/*
* Copyright @ 2019-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.
*/
#import <Intents/Intents.h>
#import "Orientation.h"
#import "JitsiMeet+Private.h"
#import "JitsiMeetConferenceOptions+Private.h"
#import "JitsiMeetView+Private.h"
#import "RCTBridgeWrapper.h"
#import "ReactUtils.h"
#import "ScheenshareEventEmiter.h"
#import <react-native-webrtc/WebRTCModuleOptions.h>
#if !defined(JITSI_MEET_SDK_LITE)
#import <RNGoogleSignin/RNGoogleSignin.h>
#import "Dropbox.h"
#endif
@implementation JitsiMeet {
RCTBridgeWrapper *_bridgeWrapper;
NSDictionary *_launchOptions;
ScheenshareEventEmiter *_screenshareEventEmiter;
}
#pragma mak - This class is a singleton
+ (instancetype)sharedInstance {
static JitsiMeet *sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [[self alloc] init];
});
return sharedInstance;
}
- (instancetype)init {
if (self = [super init]) {
// Initialize WebRTC options.
self.rtcAudioDevice = nil;
self.webRtcLoggingSeverity = WebRTCLoggingSeverityNone;
// Initialize the listener for handling start/stop screensharing notifications.
_screenshareEventEmiter = [[ScheenshareEventEmiter alloc] init];
// Register a fatal error handler for React.
registerReactFatalErrorHandler();
// Register a log handler for React.
registerReactLogHandler();
}
return self;
}
#pragma mark - Methods that the App delegate must call
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
_launchOptions = [launchOptions copy];
#if !defined(JITSI_MEET_SDK_LITE)
[Dropbox setAppKey];
#endif
return YES;
}
- (BOOL)application:(UIApplication *)application
continueUserActivity:(NSUserActivity *)userActivity
restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> *))restorationHandler {
JitsiMeetConferenceOptions *options = [self optionsFromUserActivity:userActivity];
if (options) {
[JitsiMeetView updateProps:[options asProps]];
return true;
}
return false;
}
- (BOOL)application:(UIApplication *)app
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
#if !defined(JITSI_MEET_SDK_LITE)
if ([Dropbox application:app openURL:url options:options]) {
return YES;
}
if ([RNGoogleSignin application:app
openURL:url
options:options]) {
return YES;
}
#endif
if (_customUrlScheme == nil || ![_customUrlScheme isEqualToString:url.scheme]) {
return NO;
}
JitsiMeetConferenceOptions *conferenceOptions = [JitsiMeetConferenceOptions fromBuilder:^(JitsiMeetConferenceOptionsBuilder *builder) {
builder.room = [url absoluteString];
}];
[JitsiMeetView updateProps:[conferenceOptions asProps]];
return true;
}
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
return [Orientation getOrientation];
}
#pragma mark - Utility methods
- (void)instantiateReactNativeBridge {
if (_bridgeWrapper != nil) {
return;
};
// Initialize WebRTC options.
WebRTCModuleOptions *options = [WebRTCModuleOptions sharedInstance];
options.audioDevice = _rtcAudioDevice;
options.loggingSeverity = (RTCLoggingSeverity)_webRtcLoggingSeverity;
// Initialize the one and only bridge for interfacing with React Native.
_bridgeWrapper = [[RCTBridgeWrapper alloc] init];
}
- (void)destroyReactNativeBridge {
[_bridgeWrapper invalidate];
_bridgeWrapper = nil;
}
- (JitsiMeetConferenceOptions *)getInitialConferenceOptions {
if (_launchOptions[UIApplicationLaunchOptionsURLKey]) {
NSURL *url = _launchOptions[UIApplicationLaunchOptionsURLKey];
return [JitsiMeetConferenceOptions fromBuilder:^(JitsiMeetConferenceOptionsBuilder *builder) {
builder.room = [url absoluteString];
}];
} else {
NSDictionary *userActivityDictionary
= _launchOptions[UIApplicationLaunchOptionsUserActivityDictionaryKey];
NSUserActivity *userActivity
= [userActivityDictionary objectForKey:@"UIApplicationLaunchOptionsUserActivityKey"];
if (userActivity != nil) {
return [self optionsFromUserActivity:userActivity];
}
}
return nil;
}
- (BOOL)isCrashReportingDisabled {
NSUserDefaults *userDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"jitsi-default-preferences"];
return [userDefaults stringForKey:@"isCrashReportingDisabled"];
}
- (JitsiMeetConferenceOptions *)optionsFromUserActivity:(NSUserActivity *)userActivity {
NSString *activityType = userActivity.activityType;
if ([activityType isEqualToString:NSUserActivityTypeBrowsingWeb]) {
// App was started by opening a URL in the browser
NSURL *url = userActivity.webpageURL;
if ([_universalLinkDomains containsObject:url.host]) {
return [JitsiMeetConferenceOptions fromBuilder:^(JitsiMeetConferenceOptionsBuilder *builder) {
builder.room = [url absoluteString];
}];
}
} else if ([activityType isEqualToString:@"INStartAudioCallIntent"]
|| [activityType isEqualToString:@"INStartVideoCallIntent"]) {
// App was started by a CallKit Intent
INIntent *intent = userActivity.interaction.intent;
NSArray<INPerson *> *contacts;
NSString *url;
BOOL audioOnly = NO;
if ([intent isKindOfClass:[INStartAudioCallIntent class]]) {
contacts = ((INStartAudioCallIntent *) intent).contacts;
audioOnly = YES;
} else if ([intent isKindOfClass:[INStartVideoCallIntent class]]) {
contacts = ((INStartVideoCallIntent *) intent).contacts;
}
if (contacts && (url = contacts.firstObject.personHandle.value)) {
return [JitsiMeetConferenceOptions fromBuilder:^(JitsiMeetConferenceOptionsBuilder *builder) {
builder.audioOnly = audioOnly;
builder.room = url;
}];
}
} else if (self.conferenceActivityType && [activityType isEqualToString:self.conferenceActivityType]) {
// App was started by continuing a registered NSUserActivity (SiriKit, Handoff, ...)
NSString *url;
if ((url = userActivity.userInfo[@"url"])) {
return [JitsiMeetConferenceOptions fromBuilder:^(JitsiMeetConferenceOptionsBuilder *builder) {
builder.room = url;
}];
}
}
return nil;
}
- (void)showSplashScreen {
Class splashClass = NSClassFromString(@"SplashView");
if (splashClass && [splashClass respondsToSelector:@selector(sharedInstance)]) {
id splashInstance = [splashClass performSelector:@selector(sharedInstance)];
if (splashInstance && [splashInstance respondsToSelector:@selector(showSplash)]) {
[splashInstance performSelector:@selector(showSplash)];
NSLog(@"✅ Splash Screen Shown Successfully");
}
} else {
NSLog(@"⚠️ SplashView module not found");
}
}
#pragma mark - Property getter / setters
- (NSArray<NSString *> *)universalLinkDomains {
return _universalLinkDomains ? _universalLinkDomains : @[];
}
- (void)setDefaultConferenceOptions:(JitsiMeetConferenceOptions *)defaultConferenceOptions {
// For testing configOverrides a room needs to be set,
// thus the following check needs to be commented out
if (defaultConferenceOptions != nil && defaultConferenceOptions.room != nil) {
@throw [NSException exceptionWithName:@"RuntimeError"
reason:@"'room' must be null in the default conference options"
userInfo:nil];
}
_defaultConferenceOptions = defaultConferenceOptions;
}
#pragma mark - Private API methods
- (NSDictionary *)getDefaultProps {
return _defaultConferenceOptions == nil ? @{} : [_defaultConferenceOptions asProps];
}
- (RCTBridge *)getReactBridge {
// Initialize bridge lazily.
[self instantiateReactNativeBridge];
return _bridgeWrapper.bridge;
}
- (ExternalAPI *)getExternalAPI {
return [_bridgeWrapper.bridge moduleForClass:ExternalAPI.class];
}
@end

View File

@@ -0,0 +1,24 @@
/*
* Copyright @ 2019-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.
*/
#import "LogUtils.h"
#import "JitsiMeetBaseLogHandler.h"
@interface JitsiMeetBaseLogHandler ()
@property (nonatomic, retain) id<DDLogger> logger;
@end

View File

@@ -0,0 +1,28 @@
/*
* Copyright @ 2019-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.
*/
#import <Foundation/Foundation.h>
@interface JitsiMeetBaseLogHandler : NSObject
// These are "abstract".
- (void)logVerbose:(NSString *)msg;
- (void)logDebug:(NSString *)msg;
- (void)logInfo:(NSString *)msg;
- (void)logWarn:(NSString *)msg;
- (void)logError:(NSString *)msg;
@end

View File

@@ -0,0 +1,105 @@
/*
* Copyright @ 2019-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.
*/
#import "JitsiMeetBaseLogHandler+Private.h"
@interface PrivateLogger : DDAbstractLogger <DDLogger>
@end
@implementation PrivateLogger {
JitsiMeetBaseLogHandler *_delegate;
}
- (instancetype)initWithDelegate:(JitsiMeetBaseLogHandler *)delegate {
if (self = [super init]) {
_delegate = delegate;
}
return self;
}
#pragma mark - DDAbstractLogger interface
- (void)logMessage:(DDLogMessage *)logMessage {
NSString *logMsg = logMessage.message;
if (_logFormatter)
logMsg = [_logFormatter formatLogMessage:logMessage];
if (logMsg && _delegate) {
switch (logMessage.flag) {
case DDLogFlagError:
[_delegate logError:logMsg];
break;
case DDLogFlagWarning:
[_delegate logWarn:logMsg];
break;
case DDLogFlagInfo:
[_delegate logInfo:logMsg];
break;
case DDLogFlagDebug:
[_delegate logDebug:logMsg];
break;
case DDLogFlagVerbose:
[_delegate logVerbose:logMsg];
break;
}
}
}
@end
@implementation JitsiMeetBaseLogHandler
#pragma mark - Proxy logger not to expose the CocoaLumberjack headers
- (instancetype)init {
if (self = [super init]) {
self.logger = [[PrivateLogger alloc] initWithDelegate:self];
}
return self;
}
#pragma mark - Public API
- (void)logVerbose:(NSString *)msg {
// Override me!
[self doesNotRecognizeSelector:_cmd];
}
- (void)logDebug:(NSString *)msg {
// Override me!
[self doesNotRecognizeSelector:_cmd];
}
- (void)logInfo:(NSString *)msg {
// Override me!
[self doesNotRecognizeSelector:_cmd];
}
- (void)logWarn:(NSString *)msg {
// Override me!
[self doesNotRecognizeSelector:_cmd];
}
- (void)logError:(NSString *)msg {
// Override me!
[self doesNotRecognizeSelector:_cmd];
}
@end

View File

@@ -0,0 +1,23 @@
/*
* Copyright @ 2019-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.
*/
#import "JitsiMeetConferenceOptions.h"
@interface JitsiMeetConferenceOptions ()
- (NSMutableDictionary *)asProps;
@end

View File

@@ -0,0 +1,80 @@
/*
* Copyright @ 2019-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.
*/
#import <Foundation/Foundation.h>
#import "JitsiMeetUserInfo.h"
@interface JitsiMeetConferenceOptionsBuilder : NSObject
/**
* Server where the conference should take place.
*/
@property (nonatomic, copy, nullable) NSURL *serverURL;
/**
* Room name.
*/
@property (nonatomic, copy, nullable) NSString *room;
/**
* JWT token used for authentication.
*/
@property (nonatomic, copy, nullable) NSString *token;
/**
* Feature flags. See: https://github.com/jitsi/jitsi-meet/blob/master/react/features/base/flags/constants.js
*/
@property (nonatomic, readonly, nonnull) NSDictionary *featureFlags;
@property (nonatomic, readonly, nonnull) NSDictionary *config;
/**
* Information about the local user. It will be used in absence of a token.
*/
@property (nonatomic, nullable) JitsiMeetUserInfo *userInfo;
- (void)setFeatureFlag:(NSString *_Nonnull)flag withBoolean:(BOOL)value;
- (void)setFeatureFlag:(NSString *_Nonnull)flag withValue:(id _Nonnull)value;
- (void)setConfigOverride:(NSString *_Nonnull)config withBoolean:(BOOL)value;
- (void)setConfigOverride:(NSString *_Nonnull)config withValue:(id _Nonnull)value;
- (void)setConfigOverride:(NSString *_Nonnull)config withDictionary:(NSDictionary * _Nonnull)dictionary;
- (void)setConfigOverride:(NSString *_Nonnull)config withArray:( NSArray * _Nonnull)array;
- (void)setAudioOnly:(BOOL)audioOnly;
- (void)setAudioMuted:(BOOL)audioMuted;
- (void)setVideoMuted:(BOOL)videoMuted;
- (void)setCallHandle:(NSString *_Nonnull)callHandle;
- (void)setCallUUID:(NSUUID *_Nonnull)callUUID;
- (void)setSubject:(NSString *_Nonnull)subject;
@end
@interface JitsiMeetConferenceOptions : NSObject
@property (nonatomic, copy, nullable, readonly) NSURL *serverURL;
@property (nonatomic, copy, nullable, readonly) NSString *room;
@property (nonatomic, copy, nullable, readonly) NSString *token;
@property (nonatomic, readonly, nonnull) NSDictionary *featureFlags;
@property (nonatomic, nullable) JitsiMeetUserInfo *userInfo;
+ (instancetype _Nonnull)fromBuilder:(void (^_Nonnull)(JitsiMeetConferenceOptionsBuilder *_Nonnull))initBlock;
- (instancetype _Nonnull)init NS_UNAVAILABLE;
@end

View File

@@ -0,0 +1,159 @@
/*
* Copyright @ 2019-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.
*/
#import <React/RCTUtils.h>
#import "JitsiMeetConferenceOptions+Private.h"
#import "JitsiMeetUserInfo+Private.h"
@implementation JitsiMeetConferenceOptionsBuilder {
NSMutableDictionary *_featureFlags;
NSMutableDictionary *_config;
}
- (instancetype)init {
if (self = [super init]) {
_serverURL = nil;
_room = nil;
_token = nil;
_config = [[NSMutableDictionary alloc] init];
_featureFlags = [[NSMutableDictionary alloc] init];
_userInfo = nil;
}
return self;
}
- (void)setFeatureFlag:(NSString *)flag withBoolean:(BOOL)value {
[self setFeatureFlag:flag withValue:[NSNumber numberWithBool:value]];
}
- (void)setFeatureFlag:(NSString *)flag withValue:(id)value {
_featureFlags[flag] = value;
}
- (void)setAudioOnly:(BOOL)audioOnly {
[self setConfigOverride:@"startAudioOnly" withBoolean:audioOnly];
}
- (void)setAudioMuted:(BOOL)audioMuted {
[self setConfigOverride:@"startWithAudioMuted" withBoolean:audioMuted];
}
- (void)setVideoMuted:(BOOL)videoMuted {
[self setConfigOverride:@"startWithVideoMuted" withBoolean:videoMuted];
}
- (void)setCallHandle:(NSString *_Nonnull)callHandle {
[self setConfigOverride:@"callHandle" withValue:callHandle];
}
- (void)setCallUUID:(NSUUID *_Nonnull)callUUID {
[self setConfigOverride:@"callUUID" withValue:[callUUID UUIDString]];
}
- (void)setSubject:(NSString *_Nonnull)subject {
[self setConfigOverride:@"subject" withValue:subject];
}
- (void)setConfigOverride:(NSString *_Nonnull)config withBoolean:(BOOL)value {
[self setConfigOverride:config withValue:[NSNumber numberWithBool:value]];
}
- (void)setConfigOverride:(NSString *_Nonnull)config withDictionary:(NSDictionary*)dictionary {
_config[config] = dictionary;
}
- (void)setConfigOverride:(NSString *_Nonnull)config withArray:( NSArray * _Nonnull)array {
_config[config] = array;
}
- (void)setConfigOverride:(NSString *_Nonnull)config withValue:(id _Nonnull)value {
_config[config] = value;
}
@end
@implementation JitsiMeetConferenceOptions {
NSDictionary *_featureFlags;
NSDictionary *_config;
}
#pragma mark - Internal initializer
- (instancetype)initWithBuilder:(JitsiMeetConferenceOptionsBuilder *)builder {
if (self = [super init]) {
_serverURL = builder.serverURL;
_room = builder.room;
_token = builder.token;
_config = builder.config;
_featureFlags = [NSDictionary dictionaryWithDictionary:builder.featureFlags];
_userInfo = builder.userInfo;
}
return self;
}
#pragma mark - API
+ (instancetype)fromBuilder:(void (^)(JitsiMeetConferenceOptionsBuilder *))initBlock {
JitsiMeetConferenceOptionsBuilder *builder = [[JitsiMeetConferenceOptionsBuilder alloc] init];
initBlock(builder);
return [[JitsiMeetConferenceOptions alloc] initWithBuilder:builder];
}
#pragma mark - Private API
- (NSDictionary *)asProps {
NSMutableDictionary *props = [[NSMutableDictionary alloc] init];
props[@"flags"] = [NSMutableDictionary dictionaryWithDictionary:_featureFlags];
NSMutableDictionary *urlProps = [[NSMutableDictionary alloc] init];
// The room is fully qualified.
if (_room != nil && [_room containsString:@"://"]) {
urlProps[@"url"] = _room;
} else {
if (_serverURL != nil) {
urlProps[@"serverURL"] = [_serverURL absoluteString];
}
if (_room != nil) {
urlProps[@"room"] = _room;
}
}
if (_token != nil) {
urlProps[@"jwt"] = _token;
}
if (_userInfo != nil) {
props[@"userInfo"] = [self.userInfo asDict];
}
urlProps[@"config"] = _config;
props[@"url"] = urlProps;
return props;
}
@end

View File

@@ -0,0 +1,27 @@
/*
* Copyright @ 2019-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.
*/
#import <Foundation/Foundation.h>
#import "JitsiMeetBaseLogHandler.h"
@interface JitsiMeetLogger : NSObject
+ (void)addHandler:(JitsiMeetBaseLogHandler *)handler;
+ (void)removeHandler:(JitsiMeetBaseLogHandler *)handler;
@end

View File

@@ -0,0 +1,42 @@
/*
* Copyright @ 2019-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.
*/
#import "LogUtils.h"
#import "JitsiMeetLogger.h"
#import "JitsiMeetBaseLogHandler+Private.h"
@implementation JitsiMeetLogger
/**
* This gets called automagically when the program starts.
*/
__attribute__((constructor))
static void initializeLogger() {
NSString *mainBundleId = [NSBundle mainBundle].bundleIdentifier;
DDOSLogger *osLogger = [[DDOSLogger alloc] initWithSubsystem:mainBundleId category:@"JitsiMeetSDK"];
[DDLog addLogger:osLogger];
}
+ (void)addHandler:(JitsiMeetBaseLogHandler *)handler {
[DDLog addLogger:handler.logger];
}
+ (void)removeHandler:(JitsiMeetBaseLogHandler *)handler {
[DDLog removeLogger:handler.logger];
}
@end

View File

@@ -0,0 +1,26 @@
/*
* Copyright @ 2020-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.
*/
#import <JitsiMeetSDK/JitsiMeet.h>
#import <JitsiMeetSDK/JitsiMeetView.h>
#import <JitsiMeetSDK/JitsiMeetViewDelegate.h>
#import <JitsiMeetSDK/JitsiMeetConferenceOptions.h>
#import <JitsiMeetSDK/JitsiMeetLogger.h>
#import <JitsiMeetSDK/JitsiMeetBaseLogHandler.h>
#import <JitsiMeetSDK/JitsiAudioSession.h>
#import <JitsiMeetSDK/InfoPlistUtil.h>
#import <JitsiMeetSDK/JMCallKitListener.h>
#import <JitsiMeetSDK/JMCallKitProxy.h>

View File

@@ -0,0 +1,23 @@
/*
* Copyright @ 2019-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.
*/
#import "JitsiMeetUserInfo.h"
@interface JitsiMeetUserInfo ()
- (NSMutableDictionary *)asDict;
@end

View File

@@ -0,0 +1,38 @@
/*
* Copyright @ 2019-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.
*/
#import <Foundation/Foundation.h>
@interface JitsiMeetUserInfo : NSObject
/**
* User display name.
*/
@property (nonatomic, copy, nullable) NSString *displayName;
/**
* User email.
*/
@property (nonatomic, copy, nullable) NSString *email;
/**
* URL for the user avatar.
*/
@property (nonatomic, copy, nullable) NSURL *avatar;
- (instancetype _Nullable)initWithDisplayName:(NSString *_Nullable)displayName
andEmail:(NSString *_Nullable)email
andAvatar:(NSURL *_Nullable) avatar;
@end

View File

@@ -0,0 +1,55 @@
/*
* Copyright @ 2019-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.
*/
#import "JitsiMeetUserInfo+Private.h"
@implementation JitsiMeetUserInfo
- (instancetype)initWithDisplayName:(NSString *)displayName
andEmail:(NSString *)email
andAvatar:(NSURL *_Nullable) avatar {
self = [super init];
if (self) {
self.displayName = displayName;
self.email = email;
self.avatar = avatar;
}
return self;
}
- (NSDictionary *)asDict {
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
if (self.displayName != nil) {
dict[@"displayName"] = self.displayName;
}
if (self.email != nil) {
dict[@"email"] = self.email;
}
if (self.avatar != nil) {
NSString *avatarURL = [self.avatar absoluteString];
if (avatarURL != nil) {
dict[@"avatarURL"] = avatarURL;
}
}
return dict;
}
@end

View File

@@ -0,0 +1,29 @@
/*
* Copyright @ 2022-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.
*/
#import <JitsiMeetSDK/JitsiMeetSDK.h>
NS_ASSUME_NONNULL_BEGIN
static NSString * const updateViewPropsNotificationName = @"org.jitsi.meet.UpdateViewProps";
@interface JitsiMeetView (Private)
+ (void)updateProps:(NSDictionary *_Nonnull)newProps;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,25 @@
/*
* Copyright @ 2022-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.
*/
#import "JitsiMeetView+Private.h"
@implementation JitsiMeetView (Private)
+ (void)updateProps:(NSDictionary *_Nonnull)newProps {
[[NSNotificationCenter defaultCenter] postNotificationName:updateViewPropsNotificationName object:nil userInfo:@{@"props": newProps}];
}
@end

View File

@@ -0,0 +1,61 @@
/*
* Copyright @ 2018-present 8x8, Inc.
* Copyright @ 2017-2018 Atlassian Pty Ltd
*
* 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.
*/
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "JitsiMeetConferenceOptions.h"
#import "JitsiMeetViewDelegate.h"
typedef NS_ENUM(NSInteger, RecordingMode) {
RecordingModeFile,
RecordingModeStream
};
@interface JitsiMeetView : UIView
@property (nonatomic, nullable, weak) id<JitsiMeetViewDelegate> delegate;
/**
* 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.
*/
- (void)join:(JitsiMeetConferenceOptions *_Nullable)options;
/**
* Leaves the currently active conference.
*/
- (void)leave;
- (void)hangUp;
- (void)setAudioMuted:(BOOL)muted;
- (void)sendEndpointTextMessage:(NSString * _Nonnull)message :(NSString * _Nullable)to;
- (void)toggleScreenShare:(BOOL)enabled;
- (void)retrieveParticipantsInfo:(void (^ _Nonnull)(NSArray * _Nullable))completionHandler;
- (void)openChat:(NSString * _Nullable)to;
- (void)closeChat;
- (void)sendChatMessage:(NSString * _Nonnull)message :(NSString * _Nullable)to;
- (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;
- (void)startRecording:(RecordingMode)mode :(NSString * _Nullable)dropboxToken :(BOOL)shouldShare :(NSString * _Nullable)rtmpStreamKey :(NSString * _Nullable)rtmpBroadcastID :(NSString * _Nullable)youtubeStreamKey :(NSString * _Nullable)youtubeBroadcastID :(NSDictionary * _Nullable)extraMetadata :(BOOL)transcription;
- (void)stopRecording:(RecordingMode)mode :(BOOL)transcription;
- (void)overwriteConfig:(NSDictionary * _Nonnull)config;
- (void)sendCameraFacingModeMessage:(NSString * _Nonnull)to :(NSString * _Nullable)facingMode;
@end

311
ios/sdk/src/JitsiMeetView.m Normal file
View File

@@ -0,0 +1,311 @@
/*
* Copyright @ 2018-present 8x8, Inc.
* Copyright @ 2017-2018 Atlassian Pty Ltd
*
* 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.
*/
#include <mach/mach_time.h>
#import <UIKit/UIKit.h>
#import "ExternalAPI.h"
#import "JitsiMeet+Private.h"
#import "JitsiMeetConferenceOptions+Private.h"
#import "JitsiMeetView+Private.h"
#import "ReactUtils.h"
#import "RNRootView.h"
#pragma mark UIColor helpers
@interface UIColor (Hex)
+ (UIColor *)colorWithHex:(uint32_t)hex;
+ (UIColor *)colorWithHex:(uint32_t)hex alpha:(CGFloat)alpha;
@end
@implementation UIColor (Hex)
+ (UIColor *)colorWithHex:(uint32_t)hex {
return [self colorWithHex:hex alpha:1.0];
}
+ (UIColor *)colorWithHex:(uint32_t)hex alpha:(CGFloat)alpha {
CGFloat red = ((hex >> 16) & 0xFF) / 255.0;
CGFloat green = ((hex >> 8) & 0xFF) / 255.0;
CGFloat blue = (hex & 0xFF) / 255.0;
return [UIColor colorWithRed:red green:green blue:blue alpha:alpha];
}
@end
#pragma mark UIColor helpers end
/**
* Backwards compatibility: turn the boolean prop into a feature flag.
*/
static NSString *const PiPEnabledFeatureFlag = @"pip.enabled";
/**
* Forward declarations.
*/
static NSString *recordingModeToString(RecordingMode mode);
@implementation JitsiMeetView {
/**
* React Native view where the entire content will be rendered.
*/
RNRootView *rootView;
}
#pragma mark Initializers
- (instancetype)initWithCoder:(NSCoder *)coder {
self = [super initWithCoder:coder];
if (self) {
[self doInitialize];
}
return self;
}
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self doInitialize];
}
return self;
}
/**
* Internal initialization:
*
* - sets the background color
* - registers necessary observers
*/
- (void)doInitialize {
// Set a background color which matches the one used in JS.
self.backgroundColor = [UIColor colorWithHex:0x040404 alpha:1];
[self registerObservers];
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
#pragma mark API
- (void)join:(JitsiMeetConferenceOptions *)options {
[self setProps:options == nil ? @{} : [options asProps]];
}
- (void)leave {
[self setProps:@{}];
}
- (void)hangUp {
ExternalAPI *externalAPI = [[JitsiMeet sharedInstance] getExternalAPI];
[externalAPI sendHangUp];
}
- (void)setAudioMuted:(BOOL)muted {
ExternalAPI *externalAPI = [[JitsiMeet sharedInstance] getExternalAPI];
[externalAPI sendSetAudioMuted:muted];
}
- (void)sendEndpointTextMessage:(NSString * _Nonnull)message :(NSString * _Nullable)to {
ExternalAPI *externalAPI = [[JitsiMeet sharedInstance] getExternalAPI];
[externalAPI sendEndpointTextMessage:message :to];
}
- (void)toggleScreenShare:(BOOL)enabled {
ExternalAPI *externalAPI = [[JitsiMeet sharedInstance] getExternalAPI];
[externalAPI toggleScreenShare:enabled];
}
- (void)retrieveParticipantsInfo:(void (^ _Nonnull)(NSArray * _Nullable))completionHandler {
ExternalAPI *externalAPI = [[JitsiMeet sharedInstance] getExternalAPI];
[externalAPI retrieveParticipantsInfo:completionHandler];
}
- (void)openChat:(NSString*)to {
ExternalAPI *externalAPI = [[JitsiMeet sharedInstance] getExternalAPI];
[externalAPI openChat:to];
}
- (void)closeChat {
ExternalAPI *externalAPI = [[JitsiMeet sharedInstance] getExternalAPI];
[externalAPI closeChat];
}
- (void)sendChatMessage:(NSString * _Nonnull)message :(NSString * _Nullable)to {
ExternalAPI *externalAPI = [[JitsiMeet sharedInstance] getExternalAPI];
[externalAPI sendChatMessage:message :to];
}
- (void)setVideoMuted:(BOOL)muted {
ExternalAPI *externalAPI = [[JitsiMeet sharedInstance] getExternalAPI];
[externalAPI sendSetVideoMuted:muted];
}
- (void)setClosedCaptionsEnabled:(BOOL)enabled {
ExternalAPI *externalAPI = [[JitsiMeet sharedInstance] getExternalAPI];
[externalAPI sendSetClosedCaptionsEnabled:enabled];
}
- (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 * _Nullable)dropboxToken :(BOOL)shouldShare :(NSString * _Nullable)rtmpStreamKey :(NSString * _Nullable)rtmpBroadcastID :(NSString * _Nullable)youtubeStreamKey :(NSString * _Nullable)youtubeBroadcastID :(NSDictionary * _Nullable)extraMetadata :(BOOL)transcription {
ExternalAPI *externalAPI = [[JitsiMeet sharedInstance] getExternalAPI];
[externalAPI startRecording:recordingModeToString(mode) :dropboxToken :shouldShare :rtmpStreamKey :rtmpBroadcastID :youtubeStreamKey :youtubeBroadcastID :extraMetadata :transcription];
}
- (void)stopRecording:(RecordingMode)mode :(BOOL)transcription {
ExternalAPI *externalAPI = [[JitsiMeet sharedInstance] getExternalAPI];
[externalAPI stopRecording:recordingModeToString(mode) :transcription];
}
- (void)overwriteConfig:(NSDictionary * _Nonnull)config {
ExternalAPI *externalAPI = [[JitsiMeet sharedInstance] getExternalAPI];
[externalAPI overwriteConfig:config];
}
- (void)sendCameraFacingModeMessage:(NSString * _Nonnull)to :(NSString * _Nullable)facingMode {
ExternalAPI *externalAPI = [[JitsiMeet sharedInstance] getExternalAPI];
[externalAPI sendCameraFacingModeMessage:to :facingMode];
}
#pragma mark Private methods
- (void)registerObservers {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleUpdateViewPropsNotification:) name:updateViewPropsNotificationName object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleSendEventNotification:) name:sendEventNotificationName object:nil];
}
- (void)handleUpdateViewPropsNotification:(NSNotification *)notification {
NSDictionary *props = [notification.userInfo objectForKey:@"props"];
[self setProps:props];
}
- (void)handleSendEventNotification:(NSNotification *)notification {
NSString *eventName = notification.userInfo[@"name"];
NSString *eventData = notification.userInfo[@"data"];
SEL sel = NSSelectorFromString([self methodNameFromEventName:eventName]);
if (sel && [self.delegate respondsToSelector:sel]) {
[self.delegate performSelector:sel withObject:eventData];
}
}
/**
* Converts a specific event name i.e. redux action type description to a
* method name.
*
* @param eventName The event name to convert to a method name.
* @return A method name constructed from the specified `eventName`.
*/
- (NSString *)methodNameFromEventName:(NSString *)eventName {
NSMutableString *methodName
= [NSMutableString stringWithCapacity:eventName.length];
for (NSString *c in [eventName componentsSeparatedByString:@"_"]) {
if (c.length) {
[methodName appendString:
methodName.length ? c.capitalizedString : c.lowercaseString];
}
}
[methodName appendString:@":"];
return methodName;
}
/**
* Passes the given props to the React Native application. The props which we pass
* are a combination of 3 different sources:
*
* - JitsiMeet.defaultConferenceOptions
* - This function's parameters
* - Some extras which are added by this function
*/
- (void)setProps:(NSDictionary *_Nonnull)newProps {
NSMutableDictionary *props = mergeProps([[JitsiMeet sharedInstance] getDefaultProps], newProps);
// Set the PiP flag if it wasn't manually set.
NSMutableDictionary *featureFlags = props[@"flags"];
if (featureFlags[PiPEnabledFeatureFlag] == nil) {
featureFlags[PiPEnabledFeatureFlag]
= [NSNumber numberWithBool:
self.delegate && [self.delegate respondsToSelector:@selector(enterPictureInPicture:)]];
}
// This method is supposed to be imperative i.e. a second
// invocation with one and the same URL is expected to join the respective
// conference again if the first invocation was followed by leaving the
// conference. However, React and, respectively,
// appProperties/initialProperties are declarative expressions i.e. one and
// the same URL will not trigger an automatic re-render in the JavaScript
// source code. The workaround implemented below introduces imperativeness
// in React Component props by defining a unique value per invocation.
props[@"timestamp"] = @(mach_absolute_time());
if (rootView) {
// Update props with the new URL.
rootView.appProperties = props;
} else {
RCTBridge *bridge = [[JitsiMeet sharedInstance] getReactBridge];
rootView
= [[RNRootView alloc] initWithBridge:bridge
moduleName:@"App"
initialProperties:props];
rootView.backgroundColor = self.backgroundColor;
// Add rootView as a subview which completely covers this one.
[rootView setFrame:[self bounds]];
rootView.autoresizingMask
= UIViewAutoresizingFlexibleWidth
| UIViewAutoresizingFlexibleHeight;
[self addSubview:rootView];
}
}
@end
static NSString *recordingModeToString(RecordingMode mode) {
switch (mode) {
case RecordingModeFile:
return @"file";
case RecordingModeStream:
return @"stream";
default:
return nil;
}
}

View File

@@ -0,0 +1,147 @@
/*
* Copyright @ 2017-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.
*/
@protocol JitsiMeetViewDelegate <NSObject>
@optional
/**
* Called when a conference was joined.
*
* The `data` dictionary contains a `url` key with the conference URL.
*/
- (void)conferenceJoined:(NSDictionary *)data;
/**
* Called when the active conference ends, be it because of user choice or
* because of a failure.
*
* The `data` dictionary contains an `error` key with the error and a `url` key
* with the conference URL. If the conference finished gracefully no `error`
* key will be present. The possible values for "error" are described here:
* https://github.com/jitsi/lib-jitsi-meet/blob/master/JitsiConnectionErrors.js
* https://github.com/jitsi/lib-jitsi-meet/blob/master/JitsiConferenceErrors.js
*/
- (void)conferenceTerminated:(NSDictionary *)data;
/**
* Called before a conference is joined.
*
* The `data` dictionary contains a `url` key with the conference URL.
*/
- (void)conferenceWillJoin:(NSDictionary *)data;
/**
* Called when entering Picture-in-Picture is requested by the user. The app
* should now activate its Picture-in-Picture implementation (and resize the
* associated `JitsiMeetView`. The latter will automatically detect its new size
* and adjust its user interface to a variant appropriate for the small size
* ordinarily associated with Picture-in-Picture.)
*
* The `data` dictionary is empty.
*/
- (void)enterPictureInPicture:(NSDictionary *)data;
/**
* Called when a participant has joined the conference.
*
* The `data` dictionary contains a `participantId` key with the id of the participant that has joined.
*/
- (void)participantJoined:(NSDictionary *)data;
/**
* Called when a participant has left the conference.
*
* The `data` dictionary contains a `participantId` key with the id of the participant that has left.
*/
- (void)participantLeft:(NSDictionary *)data;
/**
* Called when audioMuted state changed.
*
* The `data` dictionary contains a `muted` key with state of the audioMuted for the localParticipant.
*/
- (void)audioMutedChanged:(NSDictionary *)data;
/**
* Called when an endpoint text message is received.
*
* The `data` dictionary contains a `senderId` key with the participantId of the sender and a 'message' key with the content.
*/
- (void)endpointTextMessageReceived:(NSDictionary *)data;
/**
* Called when a participant toggled shared screen.
*
* The `data` dictionary contains a `participantId` key with the id of the participant and a 'sharing' key with boolean value.
*/
- (void)screenShareToggled:(NSDictionary *)data;
/**
* Called when a chat message is received.
*
* The `data` dictionary contains `message`, `senderId` and `isPrivate` keys.
*/
- (void)chatMessageReceived:(NSDictionary *)data;
/**
* Called when the chat dialog is displayed/hidden.
*
* The `data` dictionary contains a `isOpen` key.
*/
- (void)chatToggled:(NSDictionary *)data;
/**
* Called when videoMuted state changed.
*
* The `data` dictionary contains a `muted` key with state of the videoMuted for the localParticipant.
*/
- (void)videoMutedChanged:(NSDictionary *)data;
/**
* Called when the SDK is ready to be closed. No meeting is happening at this point.
*/
- (void)readyToClose:(NSDictionary *)data;
/**
* Called when the transcription chunk was received.
*
* The `data` dictionary contains a `messageID`, `language`, `participant` key.
*/
- (void)transcriptionChunkReceived:(NSDictionary *)data;
/**
* Called when the custom overflow menu button is pressed.
*
* The `data` dictionary contains a `id`, `text` key.
*/
- (void)customButtonPressed:(NSDictionary *)data;
/**
* Called when the unique identifier for conference has been set.
*
* The `data` dictionary contains a `sessionId` key.
*/
- (void)conferenceUniqueIdSet:(NSDictionary *)data;
/**
* Called when the recording status has changed.
*
* The `data` dictionary contains a `sessionData` key.
*/
- (void)recordingStatusChanged:(NSDictionary *)data;
@end

View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>99.0.0</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
</plist>

View File

@@ -0,0 +1,40 @@
/*
* Copyright @ 2018-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.
*/
/*
* Based on https://github.com/DylanVann/react-native-locale-detector
*/
#import <Foundation/Foundation.h>
#import <React/RCTBridgeModule.h>
@interface LocaleDetector : NSObject <RCTBridgeModule>
@end
@implementation LocaleDetector
RCT_EXPORT_MODULE();
+ (BOOL)requiresMainQueueSetup {
return NO;
}
- (NSDictionary *)constantsToExport {
return @{ @"locale": [[NSLocale preferredLanguages] objectAtIndex:0] };
}
@end

57
ios/sdk/src/LogBridge.m Normal file
View File

@@ -0,0 +1,57 @@
/*
* Copyright @ 2019-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.
*/
#import <React/RCTBridgeModule.h>
#import "LogUtils.h"
@interface LogBridge : NSObject<RCTBridgeModule>
@end
@implementation LogBridge
RCT_EXPORT_MODULE();
+ (BOOL)requiresMainQueueSetup {
return NO;
}
RCT_EXPORT_METHOD(trace:(NSString *)msg) {
DDLogDebug(@"%@", msg);
}
RCT_EXPORT_METHOD(debug:(NSString *)msg) {
DDLogDebug(@"%@", msg);
}
RCT_EXPORT_METHOD(info:(NSString *)msg) {
DDLogInfo(@"%@", msg);
}
RCT_EXPORT_METHOD(log:(NSString *)msg) {
DDLogInfo(@"%@", msg);
}
RCT_EXPORT_METHOD(warn:(NSString *)msg) {
DDLogWarn(@"%@", msg);
}
RCT_EXPORT_METHOD(error:(NSString *)msg) {
DDLogError(@"%@", msg);
}
@end

23
ios/sdk/src/LogUtils.h Normal file
View File

@@ -0,0 +1,23 @@
/*
* Copyright @ 2019-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.
*/
#ifndef JM_LOG_UTILS_H
#define JM_LOG_UTILS_H
#import <CocoaLumberjack/CocoaLumberjack.h>
static const DDLogLevel ddLogLevel = DDLogLevelVerbose;
#endif

110
ios/sdk/src/POSIX.m Normal file
View File

@@ -0,0 +1,110 @@
/*
* Copyright @ 2017-present Atlassian Pty Ltd
*
* 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.
*/
#import <React/RCTBridgeModule.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
@interface POSIX : NSObject<RCTBridgeModule>
@end
@implementation POSIX
RCT_EXPORT_MODULE();
RCT_EXPORT_METHOD(getaddrinfo:(NSString *)hostname
servname:(NSString *)servname
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject) {
int err;
const char *hostname_ = hostname ? hostname.UTF8String : NULL;
const char *servname_ = servname ? servname.UTF8String : NULL;
struct addrinfo hints;
struct addrinfo *res;
NSString *rejectCode;
memset(&hints, 0, sizeof(hints));
hints.ai_family = PF_UNSPEC;
hints.ai_flags = AI_DEFAULT;
if (0 == (err = getaddrinfo(hostname_, servname_, &hints, &res))) {
char addr_[MAX(INET_ADDRSTRLEN, INET6_ADDRSTRLEN)];
NSMutableArray *res_ = [[NSMutableArray alloc] init];
for (struct addrinfo *ai = res; ai; ai = ai->ai_next) {
int af = ai->ai_family;
struct sockaddr *sa = ai->ai_addr;
void *addr;
switch (af) {
case AF_INET:
addr = &(((struct sockaddr_in *) sa)->sin_addr);
break;
case AF_INET6:
addr = &(((struct sockaddr_in6 *) sa)->sin6_addr);
break;
default:
addr = NULL;
break;
}
if (addr) {
if (inet_ntop(af, addr, addr_, sizeof(addr_))) {
[res_ addObject:@{
@"ai_addr": [NSString stringWithUTF8String:addr_],
@"ai_family": [NSNumber numberWithInt:af],
@"ai_protocol":
[NSNumber numberWithInt:ai->ai_protocol],
@"ai_socktype": [NSNumber numberWithInt:ai->ai_socktype]
}];
} else {
err = errno;
rejectCode = @"inet_ntop";
}
} else {
err = EAFNOSUPPORT;
rejectCode = @"EAFNOSUPPORT";
}
}
freeaddrinfo(res);
// resolve
if (res_.count) {
resolve(res_);
return;
}
if (!err) {
err = ERANGE;
rejectCode = @"ERANGE";
}
} else {
rejectCode = @"getaddrinfo";
}
// reject
NSError *error
= [NSError errorWithDomain:NSPOSIXErrorDomain
code:err
userInfo:nil];
reject(rejectCode, error.localizedDescription, error);
}
@end

44
ios/sdk/src/Proximity.m Normal file
View File

@@ -0,0 +1,44 @@
/*
* Copyright @ 2017-present Atlassian Pty Ltd
*
* 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.
*/
#import <UIKit/UIKit.h>
#import <React/RCTBridgeModule.h>
@interface Proximity : NSObject<RCTBridgeModule>
@end
@implementation Proximity
RCT_EXPORT_MODULE();
- (dispatch_queue_t)methodQueue {
return dispatch_get_main_queue();
}
/**
* Enables / disables the proximity sensor monitoring. On iOS enabling the
* proximity sensor automatically dims the screen and disables touch controls,
* so there is nothing else to do (unlike on Android)!
*
* @param enabled `YES` to enable proximity (sensor) monitoring; `NO`,
* otherwise.
*/
RCT_EXPORT_METHOD(setEnabled:(BOOL)enabled) {
[[UIDevice currentDevice] setProximityMonitoringEnabled:enabled];
}
@end

View File

@@ -0,0 +1,39 @@
/*
* Copyright @ 2017-present Atlassian Pty Ltd
*
* 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.
*/
#import <Foundation/Foundation.h>
#import <React/RCTBridge.h>
#import <React/RCTBridgeDelegate.h>
/**
* A wrapper around the `RCTBridge` which implements the delegate methods
* that allow us to serve the JS bundle from within the framework's resources
* directory. This is the recommended way for those cases where the builtin API
* doesn't cut it, as is the case.
*
* In addition, we will create a single bridge and then create all root views
* off it, thus only loading the JS bundle a single time. This class is not a
* singleton, however, so it's possible for us to create multiple instances of
* it, though that's not currently used.
*/
@interface RCTBridgeWrapper : NSObject<RCTBridgeDelegate>
@property (nonatomic, readonly, strong) RCTBridge *bridge;
- (void)invalidate;
@end

View File

@@ -0,0 +1,130 @@
/*
* Copyright @ 2017-present Atlassian Pty Ltd
*
* 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.
*/
#include "RCTBridgeWrapper.h"
/**
* Wrapper around RCTBridge which also implements the RCTBridgeDelegate methods,
* allowing us to specify where the bundles are loaded from.
*/
@implementation RCTBridgeWrapper
- (instancetype)init {
self = [super init];
if (self) {
_bridge
= [[RCTBridge alloc] initWithDelegate:self
launchOptions:nil];
}
return self;
}
- (void)invalidate {
[_bridge invalidate];
}
#pragma mark helper methods for getting the packager URL
#if DEBUG
static NSURL *serverRootWithHost(NSString *host) {
return
[NSURL URLWithString:
[NSString stringWithFormat:@"http://%@:8081/", host]];
}
- (BOOL)isPackagerRunning:(NSString *)host {
NSURL *url = [serverRootWithHost(host) URLByAppendingPathComponent:@"status"];
NSURLSession *session = [NSURLSession sharedSession];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
__block NSURLResponse *response;
__block NSData *data;
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
[[session dataTaskWithRequest:request
completionHandler:^(NSData *d,
NSURLResponse *res,
__unused NSError *err) {
data = d;
response = res;
dispatch_semaphore_signal(semaphore);
}] resume];
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
NSString *status = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
return [status isEqualToString:@"packager-status:running"];
}
- (NSString *)guessPackagerHost {
static NSString *ipGuess;
static dispatch_once_t dispatchOncePredicate;
dispatch_once(&dispatchOncePredicate, ^{
NSString *ipPath
= [[NSBundle bundleForClass:self.class] pathForResource:@"ip"
ofType:@"txt"];
ipGuess
= [[NSString stringWithContentsOfFile:ipPath
encoding:NSUTF8StringEncoding
error:nil]
stringByTrimmingCharactersInSet:
[NSCharacterSet newlineCharacterSet]];
});
NSString *host = ipGuess ?: @"localhost";
if ([self isPackagerRunning:host]) {
return host;
}
return nil;
}
#endif
#pragma mark RCTBridgeDelegate methods
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge {
#if DEBUG
// In debug mode, try to fetch the bundle from the packager, or fallback to
// the one inside the framework. The IP address for the packager host is
// fetched from the ip.txt file inside the framework.
//
// This duplicates some functionality present in RCTBundleURLProvider, but
// that mode is not designed to work inside a framework, because all
// resources are loaded from the main bundle.
NSString *host = [self guessPackagerHost];
if (host != nil) {
NSString *path = @"/index.bundle";
NSString *query = @"platform=ios&dev=true&minify=false";
NSURLComponents *components
= [NSURLComponents componentsWithURL:serverRootWithHost(host)
resolvingAgainstBaseURL:NO];
components.path = path;
components.query = query;
return components.URL;
}
#endif
return [[NSBundle bundleForClass:self.class] URLForResource:@"main"
withExtension:@"jsbundle"];
}
@end

20
ios/sdk/src/RNRootView.h Normal file
View File

@@ -0,0 +1,20 @@
/*
* Copyright @ 2019-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.
*/
#import <React/RCTRootView.h>
@interface RNRootView : RCTRootView
@end

45
ios/sdk/src/RNRootView.m Normal file
View File

@@ -0,0 +1,45 @@
/*
* Copyright @ 2019-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.
*/
#import <React/RCTRootContentView.h>
#import <React/RCTLog.h>
#import "RNRootView.h"
@implementation RNRootView
// Monkey-patch RCTRootView.runApplication to avoid logging initial props.
- (void)runApplication:(RCTBridge *)bridge
{
NSString *moduleName = [self valueForKey:@"_moduleName"] ?: @"";
RCTRootContentView *_contentView = [self valueForKey:@"_contentView"];
NSNumber *reactTag = [_contentView valueForKey:@"reactTag"];
NSDictionary *appParameters = @{
@"rootTag": reactTag,
@"initialProps": self.appProperties ?: @{},
};
#if DEBUG
RCTLogInfo(@"Running application %@ (%@)", moduleName, appParameters);
#endif
[bridge enqueueJSCall:@"AppRegistry"
method:@"runApplication"
args:@[moduleName, appParameters]
completion:NULL];
}
@end

24
ios/sdk/src/ReactUtils.h Normal file
View File

@@ -0,0 +1,24 @@
/*
* Copyright @ 2019-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.
*/
#ifndef JM_REACTUTILS_H
#define JM_REACTUTILS_H
NSMutableDictionary* mergeProps(NSDictionary *a, NSDictionary *b);
void registerReactFatalErrorHandler(void);
void registerReactLogHandler(void);
#endif /* JM_REACTUTILS_H */

153
ios/sdk/src/ReactUtils.m Normal file
View File

@@ -0,0 +1,153 @@
/*
* Copyright @ 2019-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.
*/
#import <React/RCTAssert.h>
#import <React/RCTLog.h>
#import "LogUtils.h"
#import "ReactUtils.h"
#pragma mark - Utility functions
/**
* Merges 2 sets of props into a single one.
*/
NSMutableDictionary* mergeProps(NSDictionary *a, NSDictionary *b) {
if (a == nil) {
return [NSMutableDictionary dictionaryWithDictionary:b == nil ? @{} : b];
}
if (b == nil) {
return [NSMutableDictionary dictionaryWithDictionary:a];
}
// Both have values, let's merge them, the strategy is to take the value from a first,
// then override it with the one from b. If the value is a dictionary, merge them
// recursively. Same goes for arrays.
NSMutableDictionary *result = [NSMutableDictionary dictionaryWithDictionary:a];
for (NSString *key in b) {
id value = b[key];
id aValue = result[key];
if (aValue == nil) {
result[key] = value;
continue;
}
if ([value isKindOfClass:NSArray.class]) {
result[key] = [aValue arrayByAddingObjectsFromArray:value];
} else if ([value isKindOfClass:NSDictionary.class]) {
result[key] = mergeProps(aValue, value);
} else {
result[key] = value;
}
}
return result;
}
/**
* A `RCTFatalHandler` implementation which swallows JavaScript errors. In the
* Release configuration, React Native will (intentionally) raise an unhandled
* `NSException` for an unhandled JavaScript error. This will effectively kill
* the application. `_RCTFatal` is suitable to be in accord with the Web i.e.
* not kill the application.
*/
RCTFatalHandler _RCTFatal = ^(NSError *error) {
id jsStackTrace = error.userInfo[RCTJSStackTraceKey];
NSString *name
= [NSString stringWithFormat:@"%@: %@", RCTFatalExceptionName, error.localizedDescription];
NSString *message
= RCTFormatError(error.localizedDescription, jsStackTrace, -1);
DDLogError(@"FATAL ERROR: %@\n%@", name, message);
};
/**
* Helper function to register a fatal error handler for React. Our handler
* won't kill the process, it will swallow JS errors and print stack traces
* instead.
*/
void registerReactFatalErrorHandler() {
#if !DEBUG
// In the Release configuration, React Native will (intentionally) raise an
// unhandled `NSException` for an unhandled JavaScript error. This will
// effectively kill the application. In accord with the Web, do not kill the
// application.
if (!RCTGetFatalHandler()) {
RCTSetFatalHandler(_RCTFatal);
}
#endif
}
/**
* A `RTCLogFunction` implementation which uses CocoaLumberjack.
*/
RCTLogFunction _RCTLog
= ^(RCTLogLevel level, __unused RCTLogSource source, NSString *fileName, NSNumber *lineNumber, NSString *message)
{
// Convert RN log levels into Lumberjack's log flags.
//
DDLogFlag logFlag;
switch (level) {
case RCTLogLevelTrace:
logFlag = DDLogFlagDebug;
break;
case RCTLogLevelInfo:
logFlag = DDLogFlagInfo;
break;
case RCTLogLevelWarning:
logFlag = DDLogFlagWarning;
break;
case RCTLogLevelError:
logFlag = DDLogFlagError;
break;
case RCTLogLevelFatal:
logFlag = DDLogFlagError;
break;
default:
// Just in case more are added in the future.
logFlag = DDLogFlagInfo;
break;
}
// Build the message object we want to log.
//
DDLogMessage *logMessage
= [[DDLogMessage alloc] initWithMessage:message
level:LOG_LEVEL_DEF
flag:logFlag
context:0
file:fileName
function:nil
line:[lineNumber integerValue]
tag:nil
options:0
timestamp:nil];
// Log the message. Errors are logged synchronously, and other async, as the Lumberjack defaults.
//
[DDLog log:logFlag != DDLogFlagError
message:logMessage];
};
/**
* Helper function which registers a React Native log handler.
*/
void registerReactLogHandler() {
RCTSetLogFunction(_RCTLog);
RCTSetLogThreshold(RCTLogLevelInfo);
}

View File

@@ -0,0 +1,25 @@
/*
* Copyright @ 2021-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.
*/
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface ScheenshareEventEmiter : NSObject
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,72 @@
/*
* Copyright @ 2021-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.
*/
#import "ScheenshareEventEmiter.h"
#import "JitsiMeet+Private.h"
#import "ExternalAPI.h"
NSNotificationName const kBroadcastStartedNotification = @"iOS_BroadcastStarted";
NSNotificationName const kBroadcastStoppedNotification = @"iOS_BroadcastStopped";
@implementation ScheenshareEventEmiter {
CFNotificationCenterRef _notificationCenter;
}
- (instancetype)init {
self = [super init];
if (self) {
_notificationCenter = CFNotificationCenterGetDarwinNotifyCenter();
[self setupObserver];
}
return self;
}
- (void)dealloc {
[self clearObserver];
}
// MARK: Private Methods
- (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);
}
- (void)clearObserver {
CFNotificationCenterRemoveObserver(_notificationCenter, (__bridge const void *)(self), (__bridge CFStringRef)kBroadcastStartedNotification, NULL);
CFNotificationCenterRemoveObserver(_notificationCenter, (__bridge const void *)(self), (__bridge CFStringRef)kBroadcastStoppedNotification, NULL);
}
void broadcastStartedNotificationCallback(CFNotificationCenterRef center,
void *observer,
CFStringRef name,
const void *object,
CFDictionaryRef userInfo) {
ExternalAPI *externalAPI = [[JitsiMeet sharedInstance] getExternalAPI];
[externalAPI toggleScreenShare:true];
}
void broadcastStoppedNotificationCallback(CFNotificationCenterRef center,
void *observer,
CFStringRef name,
const void *object,
CFDictionaryRef userInfo) {
ExternalAPI *externalAPI = [[JitsiMeet sharedInstance] getExternalAPI];
[externalAPI toggleScreenShare:false];
}
@end

View File

@@ -0,0 +1,347 @@
//
// Based on RNCallKit
//
// Original license:
//
// Copyright (c) 2016, Ian Yu-Hsun Lin
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
//
#import <AVFoundation/AVFoundation.h>
#import <CallKit/CallKit.h>
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <React/RCTBridge.h>
#import <React/RCTEventEmitter.h>
#import <React/RCTUtils.h>
#import <React/RCTLog.h>
#import <WebRTC/WebRTC.h>
#import "../JitsiAudioSession.h"
#import "JMCallKitProxy.h"
// The events emitted/supported by RNCallKit:
static NSString * const RNCallKitPerformAnswerCallAction
= @"performAnswerCallAction";
static NSString * const RNCallKitPerformEndCallAction
= @"performEndCallAction";
static NSString * const RNCallKitPerformSetMutedCallAction
= @"performSetMutedCallAction";
static NSString * const RNCallKitProviderDidReset
= @"providerDidReset";
@interface RNCallKit : RCTEventEmitter <JMCallKitListener>
@end
@implementation RNCallKit
RCT_EXPORT_MODULE();
- (NSArray<NSString *> *)supportedEvents {
return @[
RNCallKitPerformAnswerCallAction,
RNCallKitPerformEndCallAction,
RNCallKitPerformSetMutedCallAction,
RNCallKitProviderDidReset
];
}
- (void)dealloc {
[JMCallKitProxy removeListener:self];
}
- (dispatch_queue_t)methodQueue {
// Make sure all our methods run in the main thread.
return dispatch_get_main_queue();
}
// End call
RCT_EXPORT_METHOD(endCall:(NSString *)callUUID
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject) {
RCTLogInfo(@"[RNCallKit][endCall] callUUID = %@", callUUID);
NSUUID *callUUID_ = [[NSUUID alloc] initWithUUIDString:callUUID];
if (!callUUID_) {
reject(nil, [NSString stringWithFormat:@"Invalid UUID: %@", callUUID], nil);
return;
}
CXEndCallAction *action
= [[CXEndCallAction alloc] initWithCallUUID:callUUID_];
[self requestTransaction:[[CXTransaction alloc] initWithAction:action]
resolve:resolve
reject:reject];
}
// Mute / unmute (audio)
RCT_EXPORT_METHOD(setMuted:(NSString *)callUUID
muted:(BOOL)muted
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject) {
RCTLogInfo(@"[RNCallKit][setMuted] callUUID = %@", callUUID);
NSUUID *callUUID_ = [[NSUUID alloc] initWithUUIDString:callUUID];
if (!callUUID_) {
reject(nil, [NSString stringWithFormat:@"Invalid UUID: %@", callUUID], nil);
return;
}
CXSetMutedCallAction *action
= [[CXSetMutedCallAction alloc] initWithCallUUID:callUUID_ muted:muted];
[self requestTransaction:[[CXTransaction alloc] initWithAction:action]
resolve:resolve
reject:reject];
}
RCT_EXPORT_METHOD(setProviderConfiguration:(NSDictionary *)dictionary) {
RCTLogInfo(@"[RNCallKit][setProviderConfiguration:] dictionary = %@", dictionary);
if (![JMCallKitProxy isProviderConfigured]) {
JMCallKitProxy.enabled = true;
[self configureProviderFromDictionary:dictionary];
}
// register to receive CallKit proxy events
[JMCallKitProxy addListener:self];
}
// Start outgoing call
RCT_EXPORT_METHOD(startCall:(NSString *)callUUID
handle:(NSString *)handle
video:(BOOL)video
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject) {
RCTLogInfo(@"[RNCallKit][startCall] callUUID = %@", callUUID);
NSUUID *callUUID_ = [[NSUUID alloc] initWithUUIDString:callUUID];
if (!callUUID_) {
reject(nil, [NSString stringWithFormat:@"Invalid UUID: %@", callUUID], nil);
return;
}
// Don't start a new call if there's an active call for the specified
// callUUID. JitsiMeetView was configured for an incoming call.
if ([JMCallKitProxy hasActiveCallForUUID:callUUID]) {
resolve(nil);
return;
}
CXHandle *handle_
= [[CXHandle alloc] initWithType:CXHandleTypeGeneric value:handle];
CXStartCallAction *action
= [[CXStartCallAction alloc] initWithCallUUID:callUUID_
handle:handle_];
action.video = video;
CXTransaction *transaction = [[CXTransaction alloc] initWithAction:action];
[self requestTransaction:transaction resolve:resolve reject:reject];
}
// Indicate call failed
RCT_EXPORT_METHOD(reportCallFailed:(NSString *)callUUID
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject) {
NSUUID *callUUID_ = [[NSUUID alloc] initWithUUIDString:callUUID];
if (!callUUID_) {
reject(nil, [NSString stringWithFormat:@"Invalid UUID: %@", callUUID], nil);
return;
}
[JMCallKitProxy reportCallWith:callUUID_
endedAt:nil
reason:CXCallEndedReasonFailed];
resolve(nil);
}
// Indicate outgoing call connected.
RCT_EXPORT_METHOD(reportConnectedOutgoingCall:(NSString *)callUUID
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject) {
NSUUID *callUUID_ = [[NSUUID alloc] initWithUUIDString:callUUID];
if (!callUUID_) {
reject(nil, [NSString stringWithFormat:@"Invalid UUID: %@", callUUID], nil);
return;
}
[JMCallKitProxy reportOutgoingCallWith:callUUID_
connectedAt:nil];
resolve(nil);
}
// Update call in case we have a display name or video capability changes.
RCT_EXPORT_METHOD(updateCall:(NSString *)callUUID
options:(NSDictionary *)options
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject) {
RCTLogInfo(@"[RNCallKit][updateCall] callUUID = %@ options = %@", callUUID, options);
NSUUID *callUUID_ = [[NSUUID alloc] initWithUUIDString:callUUID];
if (!callUUID_) {
reject(nil, [NSString stringWithFormat:@"Invalid UUID: %@", callUUID], nil);
return;
}
NSString *displayName = options[@"displayName"];
BOOL hasVideo = [(NSNumber*)options[@"hasVideo"] boolValue];
[JMCallKitProxy reportCallUpdateWith:callUUID_
handle:nil
displayName:displayName
hasVideo:hasVideo];
resolve(nil);
}
#pragma mark - Helper methods
- (void)configureProviderFromDictionary:(NSDictionary* )dictionary {
RCTLogInfo(@"[RNCallKit][providerConfigurationFromDictionary: %@]", dictionary);
if (!dictionary) {
dictionary = @{};
}
// localizedName
NSString *localizedName = dictionary[@"localizedName"];
if (!localizedName) {
localizedName
= [[NSBundle mainBundle] infoDictionary][@"CFBundleDisplayName"];
}
// iconTemplateImageData
NSString *iconTemplateImageName = dictionary[@"iconTemplateImageName"];
NSData *iconTemplateImageData;
UIImage *iconTemplateImage;
if (iconTemplateImageName) {
// First try to load the resource from the main bundle.
iconTemplateImage = [UIImage imageNamed:iconTemplateImageName];
// If that didn't work, use the one built-in.
if (!iconTemplateImage) {
iconTemplateImage = [UIImage imageNamed:iconTemplateImageName
inBundle:[NSBundle bundleForClass:self.class]
compatibleWithTraitCollection:nil];
}
if (iconTemplateImage) {
iconTemplateImageData = UIImagePNGRepresentation(iconTemplateImage);
}
}
NSString *ringtoneSound = dictionary[@"ringtoneSound"];
[JMCallKitProxy
configureProviderWithLocalizedName:localizedName
ringtoneSound:ringtoneSound
iconTemplateImageData:iconTemplateImageData];
}
- (void)requestTransaction:(CXTransaction *)transaction
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject {
RCTLogInfo(@"[RNCallKit][requestTransaction] transaction = %@", transaction);
[JMCallKitProxy request:transaction
completion:^(NSError * _Nullable error) {
if (error) {
RCTLogError(@"[RNCallKit][requestTransaction] Error requesting transaction (%@): (%@)", transaction.actions, error);
reject(nil, @"Error processing CallKit transaction", error);
} else {
resolve(nil);
}
}];
}
#pragma mark - JMCallKitListener
// Called when the provider has been reset. We should terminate all calls.
- (void)providerDidReset {
RCTLogInfo(@"[RNCallKit][CXProviderDelegate][providerDidReset:]");
[self sendEventWithName:RNCallKitProviderDidReset body:nil];
}
// Answering incoming call
- (void) performAnswerCallWithUUID:(NSUUID *)UUID {
RCTLogInfo(@"[RNCallKit][CXProviderDelegate][provider:performAnswerCallAction:]");
[self sendEventWithName:RNCallKitPerformAnswerCallAction
body:@{ @"callUUID": UUID.UUIDString }];
}
// Call ended, user request
- (void) performEndCallWithUUID:(NSUUID *)UUID {
RCTLogInfo(@"[RNCallKit][CXProviderDelegate][provider:performEndCallAction:]");
[self sendEventWithName:RNCallKitPerformEndCallAction
body:@{ @"callUUID": UUID.UUIDString }];
}
// Handle audio mute from CallKit view
- (void) performSetMutedCallWithUUID:(NSUUID *)UUID
isMuted:(BOOL)isMuted {
RCTLogInfo(@"[RNCallKit][CXProviderDelegate][provider:performSetMutedCallAction:]");
[self sendEventWithName:RNCallKitPerformSetMutedCallAction
body:@{
@"callUUID": UUID.UUIDString,
@"muted": @(isMuted)
}];
}
// Starting outgoing call
- (void) performStartCallWithUUID:(NSUUID *)UUID
isVideo:(BOOL)isVideo {
RCTLogInfo(@"[RNCallKit][CXProviderDelegate][provider:performStartCallAction:]");
[JMCallKitProxy reportOutgoingCallWith:UUID
startedConnectingAt:nil];
}
- (void) providerDidActivateAudioSessionWithSession:(AVAudioSession *)session {
RCTLogInfo(@"[RNCallKit][CXProviderDelegate][provider:didActivateAudioSession:]");
[JitsiAudioSession activateWithAudioSession:session];
}
- (void) providerDidDeactivateAudioSessionWithSession:(AVAudioSession *)session {
RCTLogInfo(@"[RNCallKit][CXProviderDelegate][provider:didDeactivateAudioSession:]");
[JitsiAudioSession deactivateWithAudioSession:session];
}
- (void) providerTimedOutPerformingActionWithAction:(CXAction *)action {
RCTLogWarn(@"[RNCallKit][CXProviderDelegate][provider:timedOutPerformingAction:]");
}
// The bridge might already be invalidated by the time a CallKit event is processed,
// just ignore it and don't emit it.
- (void)sendEventWithName:(NSString *)name body:(id)body {
if (!self.bridge) {
return;
}
[super sendEventWithName:name body:body];
}
@end

View File

@@ -0,0 +1,35 @@
/*
* Copyright @ 2022-present 8x8, Inc.
* Copyright @ 2018-present Atlassian Pty Ltd
*
* 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.
*/
#import <CallKit/CallKit.h>
#import <Foundation/Foundation.h>
#import "JMCallKitListener.h"
NS_ASSUME_NONNULL_BEGIN
@interface JMCallKitEmitter : NSObject <CXProviderDelegate>
#pragma mark Add/Remove listeners
- (void)addListener:(id<JMCallKitListener>)listener;
- (void)removeListener:(id<JMCallKitListener>)listener;
#pragma mark Add mute action
- (void)addMuteAction:(NSUUID *)actionUUID;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,117 @@
/*
* Copyright @ 2022-present 8x8, Inc.
* Copyright @ 2018-present Atlassian Pty Ltd
*
* 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.
*/
#import "JMCallKitEmitter.h"
@interface JMCallKitEmitter()
@property(nonatomic, strong) NSMutableArray<id<JMCallKitListener>> *listeners;
@property(nonatomic, strong) NSMutableSet<NSUUID *> *pendingMuteActions;
@end
@implementation JMCallKitEmitter
- (instancetype)init {
self = [super init];
if (self) {
self.listeners = [[NSMutableArray alloc] init];
self.pendingMuteActions = [[NSMutableSet alloc] init];
}
return self;
}
#pragma mark Add/Remove listeners
- (void)addListener:(id<JMCallKitListener>)listener {
if (![self.listeners containsObject:listener]) {
[self.listeners addObject:listener];
}
}
- (void)removeListener:(id<JMCallKitListener>)listener {
[self.listeners removeObject:listener];
}
#pragma mark Add mute action
- (void)addMuteAction:(NSUUID *)actionUUID {
[self.pendingMuteActions addObject:actionUUID];
}
#pragma mark CXProviderDelegate
- (void)providerDidReset:(CXProvider *)provider {
for (id listener in self.listeners) {
[listener providerDidReset];
}
[self.pendingMuteActions removeAllObjects];
}
- (void)provider:(CXProvider *)provider performAnswerCallAction:(CXAnswerCallAction *)action {
for (id listener in self.listeners) {
[listener performAnswerCallWithUUID:action.callUUID];
}
[action fulfill];
}
- (void)provider:(CXProvider *)provider performEndCallAction:(CXEndCallAction *)action {
for (id listener in self.listeners) {
[listener performEndCallWithUUID:action.callUUID];
}
[action fulfill];
}
- (void)provider:(CXProvider *)provider performSetMutedCallAction:(CXSetMutedCallAction *)action {
NSUUID *uuid = ([self.pendingMuteActions containsObject:action.UUID]) ? action.UUID : nil;
[self.pendingMuteActions removeObject:action.UUID];
// Avoid mute actions ping-pong: if the mute action was caused by
// the JS side (we requested a transaction) don't call the delegate
// method. If it was called by the provider itself (when the user presses
// the mute button in the CallKit view) then call the delegate method.
//
// NOTE: don't try to be clever and remove this. Been there, done that.
// Won't work.
if (uuid == nil) {
for (id listener in self.listeners) {
[listener performSetMutedCallWithUUID:action.callUUID isMuted:action.isMuted];
}
}
[action fulfill];
}
- (void)provider:(CXProvider *)provider performStartCallAction:(CXStartCallAction *)action {
for (id listener in self.listeners) {
[listener performStartCallWithUUID:action.callUUID isVideo:action.isVideo];
}
[action fulfill];
}
- (void)provider:(CXProvider *)provider didActivateAudioSession:(AVAudioSession *)audioSession {
for (id listener in self.listeners) {
[listener providerDidActivateAudioSessionWithSession:audioSession];
}
}
- (void)provider:(CXProvider *)provider didDeactivateAudioSession:(AVAudioSession *)audioSession {
for (id listener in self.listeners) {
[listener providerDidDeactivateAudioSessionWithSession:audioSession];
}
}
@end

View File

@@ -0,0 +1,34 @@
/*
* Copyright @ 2022-present 8x8, Inc.
* Copyright @ 2018-present Atlassian Pty Ltd
*
* 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.
*/
#import <AVKit/AVKit.h>
#import <CallKit/CallKit.h>
#import <Foundation/Foundation.h>
@protocol JMCallKitListener <NSObject>
@optional
- (void)providerDidReset;
- (void)performAnswerCallWithUUID:(nonnull NSUUID *)UUID;
- (void)performEndCallWithUUID:(nonnull NSUUID *)UUID;
- (void)performSetMutedCallWithUUID:(nonnull NSUUID *)UUID isMuted:(BOOL)isMuted;
- (void)performStartCallWithUUID:(nonnull NSUUID *)UUID isVideo:(BOOL)isVideo;
- (void)providerDidActivateAudioSessionWithSession:(nonnull AVAudioSession *)session;
- (void)providerDidDeactivateAudioSessionWithSession:(nonnull AVAudioSession *)session;
- (void)providerTimedOutPerformingActionWithAction:(nonnull CXAction *)action;
@end

View File

@@ -0,0 +1,87 @@
/*
* Copyright @ 2022-present 8x8, Inc.
* Copyright @ 2018-present Atlassian Pty Ltd
*
* 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.
*/
#import <CallKit/CallKit.h>
#import <Foundation/Foundation.h>
#import "JMCallKitListener.h"
NS_ASSUME_NONNULL_BEGIN
@protocol CXProviderProtocol <NSObject>
@property (nonatomic, readwrite, copy) CXProviderConfiguration* configuration;
- (void)setDelegate:(nullable id<CXProviderDelegate>)delegate queue:(nullable dispatch_queue_t)queue;
- (void)reportNewIncomingCallWithUUID:(NSUUID *)uuid update:(CXCallUpdate *)update completion:(void (^)(NSError *))completion;
- (void)reportCallWithUUID:(NSUUID *)uuid updated:(CXCallUpdate *)update;
- (void)reportCallWithUUID:(NSUUID *)uuid endedAtDate:(NSDate *)dateEnded reason:(CXCallEndedReason)endedReason;
- (void)reportOutgoingCallWithUUID:(NSUUID *)uuid startedConnectingAtDate:(NSDate *)dateStartedConnecting;
- (void)reportOutgoingCallWithUUID:(NSUUID *)uuid connectedAtDate:(NSDate *)dateConnected;
- (void)invalidate;
@end
#pragma mark -
@protocol CXCallControllerProtocol <NSObject>
@property (nonatomic, readonly) NSArray<CXCall*> *calls;
- (void)requestTransaction:(CXTransaction *)transaction completion:(void (^)(NSError *_Nullable))completion;
@end
#pragma mark -
/// JitsiMeet CallKit proxy
// NOTE: The methods this class exposes are meant to be called in the UI thread.
// All delegate methods called by JMCallKitEmitter will be called in the UI thread.
@interface JMCallKitProxy : NSObject
/// Enables the proxy in between CallKit and the consumers of the SDK.
/// Defaults to disabled. Set to true when you want to use CallKit.
@property (class) BOOL enabled;
@property (class) id<CXProviderProtocol> callKitProvider;
@property (class) id<CXCallControllerProtocol> callKitCallController;
+ (void)configureProviderWithLocalizedName:(nonnull NSString *)localizedName
ringtoneSound:(nullable NSString *)ringtoneSound
iconTemplateImageData:(nullable NSData*)imageData
NS_SWIFT_NAME(configureProvider(localizedName:ringtoneSound:iconTemplateImageData:));
+ (BOOL)isProviderConfigured;
+ (void)addListener:(nonnull id<JMCallKitListener>)listener NS_SWIFT_NAME(addListener(_:));
+ (void)removeListener:(nonnull id<JMCallKitListener>)listener NS_SWIFT_NAME(removeListener(_:));
+ (BOOL)hasActiveCallForUUID:(nonnull NSString *)callUUID NS_SWIFT_NAME(hasActiveCallForUUID(_:));
+ (void)reportNewIncomingCallWithUUID:(nonnull NSUUID *)uuid
handle:(nullable NSString*)handle
displayName:(nullable NSString*)displayName
hasVideo:(BOOL)hasVideo
completion:(nonnull void (^)(NSError *_Nullable))completion
NS_SWIFT_NAME(reportNewIncomingCall(UUID:handle:displayName:hasVideo:completion:));
+ (void)reportCallUpdateWith:(nonnull NSUUID *)uuid
handle:(nullable NSString *)handle
displayName:(nullable NSString *)displayName
hasVideo:(BOOL)hasVideo;
+ (void)reportCallWith:(nonnull NSUUID *)uuid
endedAt:(nullable NSDate *)dateEnded
reason:(CXCallEndedReason)endedReason;
+ (void)reportOutgoingCallWith:(nonnull NSUUID *)uuid startedConnectingAt:(nullable NSDate *)dateStartedConnecting;
+ (void)reportOutgoingCallWith:(nonnull NSUUID *)uuid connectedAt:(nullable NSDate *)dateConnected;
+ (void)request:(nonnull CXTransaction *)transaction completion:(nonnull void (^)(NSError *_Nullable))completion;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,284 @@
/*
* Copyright @ 2022-present 8x8, Inc.
* Copyright @ 2018-present Atlassian Pty Ltd
*
* 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.
*/
#import "JMCallKitProxy.h"
#import "JMCallKitEmitter.h"
#pragma mark -
@interface CXProvider(CXProviderProtocol) <CXProviderProtocol>
@end
@implementation CXProvider(CXProviderProtocol)
@end
#pragma mark -
@interface CXCallController(CXCallControllerProtocol) <CXCallControllerProtocol>
@property (nonatomic, readonly) NSArray<CXCall*> *calls;
@end
@implementation CXCallController(CXCallControllerProtocol)
@dynamic calls;
- (NSArray<CXCall*> *)calls {
return self.callObserver.calls;
}
@end
#pragma mark -
@interface JMCallKitProxy ()
@property (class) CXProvider *defaultProvider;
@property (class) CXProviderConfiguration *providerConfiguration;
@end
@interface JMCallKitProxy (Helpers)
+ (CXCallUpdate *)makeCXUpdateWithHandle:(nullable NSString *)handle displayName:(nullable NSString *)displayName hasVideo:(BOOL)hasVideo;
@end
@implementation JMCallKitProxy
@dynamic callKitProvider, callKitCallController, enabled;
@dynamic defaultProvider, providerConfiguration;
static id<CXProviderProtocol> _callKitProvider = nil;
static id<CXCallControllerProtocol> _callKitCallController = nil;
static BOOL _enabled = false;
static CXProvider *_defaultProvider = nil;
static CXProviderConfiguration *_providerConfiguration = nil;
#pragma mark CallJit proxy
+ (id<CXProviderProtocol>)callKitProvider {
return _callKitProvider;
}
+ (void)setCallKitProvider:(id<CXProviderProtocol>)callKitProvider {
if (_callKitProvider != callKitProvider) {
_callKitProvider = callKitProvider;
}
}
+ (id<CXCallControllerProtocol>)callKitCallController {
return _callKitCallController;
}
+ (void)setCallKitCallController:(id<CXCallControllerProtocol>)callKitCallController {
if (_callKitCallController != callKitCallController) {
_callKitCallController = callKitCallController;
}
}
+ (BOOL)enabled {
return _enabled;
}
+ (void)setEnabled:(BOOL)enabled {
_enabled = enabled ;
if (!self.callKitProvider) {
[self.provider invalidate];
}
if (enabled) {
CXProviderConfiguration *configuration = self.providerConfiguration? self.providerConfiguration : [[CXProviderConfiguration alloc] initWithLocalizedName:@""];
if (!self.callKitProvider) {
self.defaultProvider = [[CXProvider alloc] initWithConfiguration: configuration];
}
[self.provider setDelegate:self.emitter queue:nil];
} else {
[self.provider setDelegate:nil queue:nil];
}
}
+ (CXProvider *)defaultProvider {
return _defaultProvider;
}
+ (void)setDefaultProvider:(CXProvider *)defaultProvider {
if (_defaultProvider != defaultProvider) {
_defaultProvider = defaultProvider;
}
}
+ (id<CXProviderProtocol>)provider {
return self.callKitProvider != nil ? self.callKitProvider : self.defaultProvider;
}
+ (id<CXCallControllerProtocol>)callController {
return self.callKitCallController != nil ? self.callKitCallController : self.defaultCallController;
}
+ (CXProviderConfiguration *)providerConfiguration {
return _providerConfiguration;
}
+ (void)setProviderConfiguration:(CXProviderConfiguration *)providerConfiguration {
if (_providerConfiguration != providerConfiguration) {
_providerConfiguration = providerConfiguration;
if (providerConfiguration) {
self.provider.configuration = providerConfiguration;
[self.provider setDelegate:self.emitter queue:nil];
}
}
}
+ (CXCallController *)defaultCallController {
static dispatch_once_t once;
static CXCallController *defaultCallController;
dispatch_once(&once, ^{
defaultCallController = [[CXCallController alloc] init];
});
return defaultCallController;
}
+ (JMCallKitEmitter *)emitter {
static dispatch_once_t once;
static JMCallKitEmitter *emitter;
dispatch_once(&once, ^{
emitter = [[JMCallKitEmitter alloc] init];
});
return emitter;
}
+ (void)configureProviderWithLocalizedName:(nonnull NSString *)localizedName
ringtoneSound:(nullable NSString *)ringtoneSound
iconTemplateImageData:(nullable NSData*)imageData {
if (!self.enabled) {
return;
}
CXProviderConfiguration *configuration = [[CXProviderConfiguration alloc] initWithLocalizedName:localizedName];
configuration.iconTemplateImageData = imageData;
configuration.maximumCallGroups = 1;
configuration.maximumCallsPerCallGroup = 1;
configuration.ringtoneSound = ringtoneSound;
configuration.supportedHandleTypes = [NSSet setWithArray:@[@(CXHandleTypeGeneric)]];
configuration.supportsVideo = true;
self.providerConfiguration = configuration;
}
+ (BOOL)isProviderConfigured {
return self.providerConfiguration != nil;
}
+ (void)addListener:(nonnull id<JMCallKitListener>)listener {
[self.emitter addListener:listener];
}
+ (void)removeListener:(nonnull id<JMCallKitListener>)listener {
[self.emitter removeListener:listener];
}
+ (BOOL)hasActiveCallForUUID:(nonnull NSString *)callUUID {
CXCall *activeCallForUUID = [[self.callController calls] filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(CXCall *evaluatedObject, NSDictionary<NSString *,id> *bindings) {
return [evaluatedObject.UUID.UUIDString isEqualToString:callUUID];
}]].firstObject;
if (!activeCallForUUID) {
return false;
}
return true;
}
+ (void)reportNewIncomingCallWithUUID:(nonnull NSUUID *)uuid
handle:(nullable NSString*)handle
displayName:(nullable NSString*)displayName
hasVideo:(BOOL)hasVideo
completion:(nonnull void (^)(NSError *_Nullable))completion {
if (!self.enabled) {
return;
}
CXCallUpdate *callUpdate = [self makeCXUpdateWithHandle:handle displayName:displayName hasVideo:hasVideo];
[self.provider reportNewIncomingCallWithUUID:uuid update:callUpdate completion:completion];
}
+ (void)reportCallUpdateWith:(nonnull NSUUID *)uuid
handle:(nullable NSString *)handle
displayName:(nullable NSString *)displayName
hasVideo:(BOOL)hasVideo {
if (!self.enabled) {
return;
}
CXCallUpdate *callUpdate = [self makeCXUpdateWithHandle:handle displayName:displayName hasVideo:hasVideo];
[self.provider reportCallWithUUID:uuid updated:callUpdate];
}
+ (void)reportCallWith:(nonnull NSUUID *)uuid
endedAt:(nullable NSDate *)dateEnded
reason:(CXCallEndedReason)endedReason {
[self.provider reportCallWithUUID:uuid endedAtDate:dateEnded reason:endedReason];
}
+ (void)reportOutgoingCallWith:(nonnull NSUUID *)uuid startedConnectingAt:(nullable NSDate *)dateStartedConnecting {
[self.provider reportOutgoingCallWithUUID:uuid startedConnectingAtDate:dateStartedConnecting];
}
+ (void)reportOutgoingCallWith:(nonnull NSUUID *)uuid connectedAt:(nullable NSDate *)dateConnected {
[self.provider reportOutgoingCallWithUUID:uuid connectedAtDate:dateConnected];
}
+ (void)request:(nonnull CXTransaction *)transaction completion:(nonnull void (^)(NSError *_Nullable))completion {
if (!self.enabled) {
return;
}
// XXX keep track of muted actions to avoid "ping-pong"ing. See
// JMCallKitEmitter for details on the CXSetMutedCallAction handling.
for (CXAction *action in transaction.actions) {
if ([action isKindOfClass:[CXSetMutedCallAction class]]) {
[self.emitter addMuteAction:action.UUID];
}
}
[self.callController requestTransaction:transaction completion:completion];
}
@end
@implementation JMCallKitProxy (Helpers)
+ (CXCallUpdate *)makeCXUpdateWithHandle:(nullable NSString *)handle displayName:(nullable NSString *)displayName hasVideo:(BOOL)hasVideo {
CXCallUpdate *update = [[CXCallUpdate alloc] init];
update.supportsDTMF = false;
update.supportsHolding = false;
update.supportsGrouping = false;
update.supportsUngrouping = false;
update.hasVideo = hasVideo;
update.localizedCallerName = displayName;
if (handle) {
update.remoteHandle = [[CXHandle alloc] initWithType:CXHandleTypeGeneric value:handle];
}
return update;
}
@end

View File

@@ -0,0 +1,27 @@
/*
* Copyright @ 2018-present Atlassian Pty Ltd
*
* 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.
*/
#import <React/RCTBridge.h>
@interface Dropbox : NSObject<RCTBridgeModule>
+ (BOOL)application:(UIApplication *)app
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options;
+ (void)setAppKey;
@end

View File

@@ -0,0 +1,180 @@
/*
* Copyright @ 2017-present Atlassian Pty Ltd
*
* 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.
*/
#import <React/RCTBridgeModule.h>
#import <ObjectiveDropboxOfficial/ObjectiveDropboxOfficial.h>
#import "Dropbox.h"
RCTPromiseResolveBlock currentResolve = nil;
RCTPromiseRejectBlock currentReject = nil;
@implementation Dropbox
+ (NSString *)getAppKey{
NSArray *urlTypes
= [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleURLTypes"];
for (NSDictionary<NSString *, NSArray *> *urlType in urlTypes) {
NSArray *urlSchemes = urlType[@"CFBundleURLSchemes"];
if (urlSchemes) {
for (NSString *urlScheme in urlSchemes) {
if (urlScheme && [urlScheme hasPrefix:@"db-"]) {
return [urlScheme substringFromIndex:3];
}
}
}
}
return nil;
}
RCT_EXPORT_MODULE();
+ (BOOL)requiresMainQueueSetup {
return NO;
}
- (NSDictionary *)constantsToExport {
BOOL enabled = [Dropbox getAppKey] != nil;
return @{
@"ENABLED": [NSNumber numberWithBool:enabled]
};
};
RCT_EXPORT_METHOD(authorize:(RCTPromiseResolveBlock)resolve
reject:(__unused RCTPromiseRejectBlock)reject) {
currentResolve = resolve;
currentReject = reject;
dispatch_async(dispatch_get_main_queue(), ^{
DBScopeRequest *scopeRequest = [[DBScopeRequest alloc] initWithScopeType:DBScopeTypeUser
scopes:@[]
includeGrantedScopes:NO];
[DBClientsManager authorizeFromControllerV2:[UIApplication sharedApplication]
controller:[[self class] topMostController]
loadingStatusDelegate:nil
openURL:^(NSURL *url) { [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil]; }
scopeRequest:scopeRequest];
});
}
RCT_EXPORT_METHOD(getDisplayName: (NSString *)token
resolve: (RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject) {
DBUserClient *client = [[DBUserClient alloc] initWithAccessToken:token];
[[client.usersRoutes getCurrentAccount] setResponseBlock:^(DBUSERSFullAccount *result, DBNilObject *routeError, DBRequestError *networkError) {
if (result) {
resolve(result.name.displayName);
} else {
NSString *msg = @"Failed!";
if (networkError) {
msg = [NSString stringWithFormat:@"Failed! Error: %@", networkError];
}
reject(@"getDisplayName", @"Failed", nil);
}
}];
}
RCT_EXPORT_METHOD(getSpaceUsage: (NSString *)token
resolve: (RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject) {
DBUserClient *client = [[DBUserClient alloc] initWithAccessToken:token];
[[client.usersRoutes getSpaceUsage] setResponseBlock:^(DBUSERSSpaceUsage *result, DBNilObject *routeError, DBRequestError *networkError) {
if (result) {
DBUSERSSpaceAllocation *allocation = result.allocation;
NSNumber *allocated = 0;
NSNumber *used = 0;
if ([allocation isIndividual]) {
allocated = allocation.individual.allocated;
used = result.used;
} else if ([allocation isTeam]) {
allocated = allocation.team.allocated;
used = allocation.team.used;
}
id objects[] = { used, allocated };
id keys[] = { @"used", @"allocated" };
NSDictionary *dictionary = [NSDictionary dictionaryWithObjects:objects
forKeys:keys
count:2];
resolve(dictionary);
} else {
NSString *msg = @"Failed!";
if (networkError) {
msg = [NSString stringWithFormat:@"Failed! Error: %@", networkError];
}
reject(@"getSpaceUsage", msg, nil);
}
}];
}
+ (BOOL)application:(UIApplication *)app
openURL:(NSURL *)url
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
if (currentReject == nil || currentResolve == nil) {
return NO;
}
BOOL canHandle = [DBClientsManager handleRedirectURL:url completion:^(DBOAuthResult *authResult) {
if (authResult) {
if ([authResult isSuccess]) {
NSInteger msTimestamp = authResult.accessToken.tokenExpirationTimestamp * 1000;
NSDictionary *authInfo = @{@"token": authResult.accessToken.accessToken,
@"rToken": authResult.accessToken.refreshToken,
@"expireDate": @(msTimestamp)
};
currentResolve(authInfo);
} else {
NSString *msg;
if ([authResult isError]) {
msg = [NSString stringWithFormat:@"%@, error type: %zd", [authResult errorDescription], [authResult errorType]];
} else {
msg = @"OAuth canceled!";
}
currentReject(@"authorize", msg, nil);
}
currentResolve = nil;
currentReject = nil;
}
}];
return canHandle;
}
+ (UIViewController *)topMostController {
UIViewController *topController
= [UIApplication sharedApplication].keyWindow.rootViewController;
while (topController.presentedViewController) {
topController = topController.presentedViewController;
}
return topController;
}
+ (void)setAppKey {
NSString *appKey = [self getAppKey];
if (appKey) {
[DBClientsManager setupWithAppKey:appKey];
}
}
@end

View File

@@ -0,0 +1,135 @@
/*
* Copyright @ 2017-present Atlassian Pty Ltd
*
* 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.
*/
import UIKit
final class DragGestureController {
var insets: UIEdgeInsets = UIEdgeInsets.zero
var currentPosition: PiPViewCoordinator.Position? = nil
private var frameBeforeDragging: CGRect = CGRect.zero
private weak var view: UIView?
private lazy var panGesture: UIPanGestureRecognizer = {
UIPanGestureRecognizer(target: self,
action: #selector(handlePan(gesture:)))
}()
func startDragListener(inView view: UIView) {
self.view = view
view.addGestureRecognizer(panGesture)
panGesture.isEnabled = true
}
func stopDragListener() {
panGesture.isEnabled = false
view?.removeGestureRecognizer(panGesture)
view = nil
}
@objc private func handlePan(gesture: UIPanGestureRecognizer) {
guard let view = view else { return }
let translation = gesture.translation(in: view.superview)
let velocity = gesture.velocity(in: view.superview)
var frame = frameBeforeDragging
switch gesture.state {
case .began:
frameBeforeDragging = view.frame
case .changed:
frame.origin.x = floor(frame.origin.x + translation.x)
frame.origin.y = floor(frame.origin.y + translation.y)
view.frame = frame
case .ended:
let currentPos = view.frame.origin
let finalPos = calculateFinalPosition()
let distance = CGPoint(x: currentPos.x - finalPos.x,
y: currentPos.y - finalPos.y)
let distanceMagnitude = magnitude(vector: distance)
let velocityMagnitude = magnitude(vector: velocity)
let animationDuration = 0.5
let initialSpringVelocity =
velocityMagnitude / distanceMagnitude / CGFloat(animationDuration)
frame.origin = CGPoint(x: finalPos.x, y: finalPos.y)
UIView.animate(withDuration: animationDuration,
delay: 0,
usingSpringWithDamping: 0.9,
initialSpringVelocity: initialSpringVelocity,
options: .curveLinear,
animations: {
view.frame = frame })
default:
break
}
}
private func calculateFinalPosition() -> CGPoint {
guard
let view = view,
let bounds = view.superview?.frame
else {
return CGPoint.zero
}
let currentSize = view.frame.size
let adjustedBounds = bounds.inset(by: insets)
let threshold: CGFloat = 20.0
let velocity = panGesture.velocity(in: view.superview)
let location = panGesture.location(in: view.superview)
let goLeft: Bool
if abs(velocity.x) > threshold {
goLeft = velocity.x < -threshold
} else {
goLeft = location.x < bounds.midX
}
let goUp: Bool
if abs(velocity.y) > threshold {
goUp = velocity.y < -threshold
} else {
goUp = location.y < bounds.midY
}
if (goLeft && goUp) {
currentPosition = .upperLeftCorner
}
if (!goLeft && goUp) {
currentPosition = .upperRightCorner
}
if (!goLeft && !goUp) {
currentPosition = .lowerRightCorner
}
if (goLeft && !goUp) {
currentPosition = .lowerLeftCorner
}
return currentPosition!.getOriginIn(bounds: adjustedBounds, size: currentSize)
}
private func magnitude(vector: CGPoint) -> CGFloat {
sqrt(pow(vector.x, 2) + pow(vector.y, 2))
}
}

View File

@@ -0,0 +1,255 @@
/*
* Copyright @ 2017-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.
*/
import UIKit
public typealias AnimationCompletion = (Bool) -> Void
public protocol PiPViewCoordinatorDelegate: class {
func exitPictureInPicture()
}
/// Coordinates the view state of a specified view to allow
/// to be presented in full screen or in a custom Picture in Picture mode.
/// This object will also provide the drag and tap interactions of the view
/// when is presented in Picture in Picture mode.
public class PiPViewCoordinator {
public enum Position {
case lowerRightCorner
case upperRightCorner
case lowerLeftCorner
case upperLeftCorner
}
/// Limits the boundaries of view position on screen when minimized
public var dragBoundInsets: UIEdgeInsets = UIEdgeInsets(top: 25,
left: 5,
bottom: 5,
right: 5) {
didSet {
dragController.insets = dragBoundInsets
}
}
public var initialPositionInSuperView: Position = .lowerRightCorner
// Unused. Remove on the next major release.
@available(*, deprecated, message: "The PiP window size is now fixed to 150px.")
public var c: CGFloat = 0.0
public weak var delegate: PiPViewCoordinatorDelegate?
private(set) var isInPiP: Bool = false // true if view is in PiP mode
private(set) var view: UIView
private var currentBounds: CGRect = CGRect.zero
private var tapGestureRecognizer: UITapGestureRecognizer?
private var exitPiPButton: UIButton?
private let dragController: DragGestureController = DragGestureController()
public init(withView view: UIView) {
self.view = view
// Required because otherwise the view will not rotate correctly.
view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
// Otherwise the enter/exit pip animation looks odd
// when pip window is bottom left, top left or top right,
// because the jitsi view content does not animate, but jumps to the new size immediately.
view.clipsToBounds = true
}
/// Configure the view to be always on top of all the contents
/// of the provided parent view.
/// If a parentView is not provided it will try to use the main window
public func configureAsStickyView(withParentView parentView: UIView? = nil) {
guard
let parentView = parentView ?? UIApplication.shared.keyWindow
else {
return
}
parentView.addSubview(view)
currentBounds = parentView.bounds
view.frame = currentBounds
view.layer.zPosition = CGFloat(Float.greatestFiniteMagnitude)
}
/// Show view with fade in animation
public func show(completion: AnimationCompletion? = nil) {
if view.isHidden || view.alpha < 1 {
view.isHidden = false
view.alpha = 0
animateTransition(animations: { [weak self] in
self?.view.alpha = 1
}, completion: completion)
}
}
/// Hide view with fade out animation
public func hide(completion: AnimationCompletion? = nil) {
if view.isHidden || view.alpha > 0 {
animateTransition(animations: { [weak self] in
self?.view.alpha = 0
self?.view.isHidden = true
}, completion: completion)
}
}
/// Resize view to and change state to custom PictureInPicture mode
/// This will resize view, add a gesture to enable user to "drag" view
/// around screen, and add a button of top of the view to be able to exit mode
public func enterPictureInPicture() {
isInPiP = true
// Resizing is done by hand when in pip.
view.autoresizingMask = []
animateViewChange()
dragController.startDragListener(inView: view)
dragController.insets = dragBoundInsets
// add single tap gesture recognition for displaying exit PiP UI
let exitSelector = #selector(toggleExitPiP)
let tapGestureRecognizer = UITapGestureRecognizer(target: self,
action: exitSelector)
self.tapGestureRecognizer = tapGestureRecognizer
view.addGestureRecognizer(tapGestureRecognizer)
}
/// Exit Picture in picture mode, this will resize view, remove
/// exit pip button, and disable the drag gesture
@objc public func exitPictureInPicture() {
isInPiP = false
// Enable autoresizing again, which got disabled for pip.
view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
animateViewChange()
dragController.stopDragListener()
// hide PiP UI
exitPiPButton?.removeFromSuperview()
exitPiPButton = nil
// remove gesture
let exitSelector = #selector(toggleExitPiP)
tapGestureRecognizer?.removeTarget(self, action: exitSelector)
tapGestureRecognizer = nil
delegate?.exitPictureInPicture()
}
/// Reset view to provide bounds, use this method on rotation or
/// screen size changes
public func resetBounds(bounds: CGRect) {
currentBounds = bounds
// Is required because otherwise the pip window is buggy when rotating the device.
// When not in pip then autoresize will do the job.
if (isInPiP) {
view.frame = changeViewRect()
}
}
/// Stop the dragging gesture of the root view
public func stopDragGesture() {
dragController.stopDragListener()
}
/// Customize the presentation of exit pip button
open func configureExitPiPButton(target: Any,
action: Selector) -> UIButton {
let buttonImage = UIImage.init(named: "image-resize",
in: Bundle(for: type(of: self)),
compatibleWith: nil)
let button = UIButton(type: .custom)
let size: CGSize = CGSize(width: 44, height: 44)
button.setImage(buttonImage, for: .normal)
button.backgroundColor = .gray
button.layer.cornerRadius = size.width / 2
button.frame = CGRect(origin: CGPoint.zero, size: size)
button.center = view.convert(view.center, from: view.superview)
button.addTarget(target, action: action, for: .touchUpInside)
return button
}
// MARK: - Interactions
@objc private func toggleExitPiP() {
if exitPiPButton == nil {
// show button
let exitSelector = #selector(exitPictureInPicture)
let button = configureExitPiPButton(target: self,
action: exitSelector)
view.addSubview(button)
exitPiPButton = button
} else {
// hide button
exitPiPButton?.removeFromSuperview()
exitPiPButton = nil
}
}
func animateViewChange() {
UIView.animate(withDuration: 0.25) {
self.view.frame = self.changeViewRect()
}
}
private func changeViewRect() -> CGRect {
let bounds = currentBounds
if !isInPiP {
return bounds
}
// resize to suggested ratio and position to the bottom right
let adjustedBounds = bounds.inset(by: dragBoundInsets)
let size = CGSize(width: 150, height: 150)
let origin = (dragController.currentPosition ?? initialPositionInSuperView).getOriginIn(bounds: adjustedBounds, size: size)
return CGRect(x: origin.x, y: origin.y, width: size.width, height: size.height)
}
// MARK: - Animation helpers
private func animateTransition(animations: @escaping () -> Void,
completion: AnimationCompletion?) {
UIView.animate(withDuration: 0.1,
delay: 0,
options: .beginFromCurrentState,
animations: animations,
completion: completion)
}
}
// MARK: -
extension PiPViewCoordinator.Position {
func getOriginIn(bounds: CGRect, size: CGSize) -> CGPoint {
switch self {
case .lowerLeftCorner:
return CGPoint(x: bounds.minX, y: bounds.maxY - size.height)
case .lowerRightCorner:
return CGPoint(x: bounds.maxX - size.width, y: bounds.maxY - size.height)
case .upperLeftCorner:
return CGPoint(x: bounds.minX, y: bounds.minY)
case .upperRightCorner:
return CGPoint(x: bounds.maxX - size.width, y: bounds.minY)
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 509 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 724 B