Codying style: naming, formatting, comments

This commit is contained in:
Lyubo Marinov 2018-05-03 17:53:38 -05:00
parent e5309a6482
commit 5e79bbecef
12 changed files with 322 additions and 316 deletions

View File

@ -79,11 +79,11 @@
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
C6F99C3A204DE6BE0001F710 /* AppDelegate.swift */, C6F99C3A204DE6BE0001F710 /* AppDelegate.swift */,
C6F99C3C204DE6BE0001F710 /* ViewController.swift */,
C6F99C3E204DE6BE0001F710 /* Main.storyboard */,
C6F99C41204DE6BE0001F710 /* Assets.xcassets */, C6F99C41204DE6BE0001F710 /* Assets.xcassets */,
C6F99C43204DE6BE0001F710 /* LaunchScreen.storyboard */,
C6F99C46204DE6BE0001F710 /* Info.plist */, C6F99C46204DE6BE0001F710 /* Info.plist */,
C6F99C43204DE6BE0001F710 /* LaunchScreen.storyboard */,
C6F99C3E204DE6BE0001F710 /* Main.storyboard */,
C6F99C3C204DE6BE0001F710 /* ViewController.swift */,
); );
path = src; path = src;
sourceTree = "<group>"; sourceTree = "<group>";

View File

@ -38,9 +38,9 @@
B386B85D20981A75000DEF7A /* Invite.m in Sources */ = {isa = PBXBuildFile; fileRef = B386B85620981A75000DEF7A /* Invite.m */; }; B386B85D20981A75000DEF7A /* Invite.m in Sources */ = {isa = PBXBuildFile; fileRef = B386B85620981A75000DEF7A /* Invite.m */; };
C6245F5D2053091D0040BE68 /* image-resize@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = C6245F5B2053091D0040BE68 /* image-resize@2x.png */; }; C6245F5D2053091D0040BE68 /* image-resize@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = C6245F5B2053091D0040BE68 /* image-resize@2x.png */; };
C6245F5E2053091D0040BE68 /* image-resize@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = C6245F5C2053091D0040BE68 /* image-resize@3x.png */; }; C6245F5E2053091D0040BE68 /* image-resize@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = C6245F5C2053091D0040BE68 /* image-resize@3x.png */; };
C69EFA0C209A0F660027712B /* JMCallKitNotifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = C69EFA09209A0F650027712B /* JMCallKitNotifier.swift */; }; C69EFA0C209A0F660027712B /* JMCallKitEmitter.swift in Sources */ = {isa = PBXBuildFile; fileRef = C69EFA09209A0F650027712B /* JMCallKitEmitter.swift */; };
C69EFA0D209A0F660027712B /* JMCallKitProxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = C69EFA0A209A0F660027712B /* JMCallKitProxy.swift */; }; C69EFA0D209A0F660027712B /* JMCallKitProxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = C69EFA0A209A0F660027712B /* JMCallKitProxy.swift */; };
C69EFA0E209A0F660027712B /* JMCallKitEventListener.swift in Sources */ = {isa = PBXBuildFile; fileRef = C69EFA0B209A0F660027712B /* JMCallKitEventListener.swift */; }; C69EFA0E209A0F660027712B /* JMCallKitListener.swift in Sources */ = {isa = PBXBuildFile; fileRef = C69EFA0B209A0F660027712B /* JMCallKitListener.swift */; };
C6A34261204EF76800E062DD /* DragGestureController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6A3425E204EF76800E062DD /* DragGestureController.swift */; }; C6A34261204EF76800E062DD /* DragGestureController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6A3425E204EF76800E062DD /* DragGestureController.swift */; };
C6CC49AF207412CF000DFA42 /* PiPViewCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6CC49AE207412CF000DFA42 /* PiPViewCoordinator.swift */; }; C6CC49AF207412CF000DFA42 /* PiPViewCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6CC49AE207412CF000DFA42 /* PiPViewCoordinator.swift */; };
C6F99C15204DB63E0001F710 /* JitsiMeetView+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = C6F99C13204DB63D0001F710 /* JitsiMeetView+Private.h */; }; C6F99C15204DB63E0001F710 /* JitsiMeetView+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = C6F99C13204DB63D0001F710 /* JitsiMeetView+Private.h */; };
@ -86,9 +86,9 @@
B386B85620981A75000DEF7A /* Invite.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Invite.m; sourceTree = "<group>"; }; B386B85620981A75000DEF7A /* Invite.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Invite.m; sourceTree = "<group>"; };
C6245F5B2053091D0040BE68 /* image-resize@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "image-resize@2x.png"; path = "src/picture-in-picture/image-resize@2x.png"; sourceTree = "<group>"; }; C6245F5B2053091D0040BE68 /* image-resize@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "image-resize@2x.png"; path = "src/picture-in-picture/image-resize@2x.png"; sourceTree = "<group>"; };
C6245F5C2053091D0040BE68 /* image-resize@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "image-resize@3x.png"; path = "src/picture-in-picture/image-resize@3x.png"; sourceTree = "<group>"; }; C6245F5C2053091D0040BE68 /* image-resize@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "image-resize@3x.png"; path = "src/picture-in-picture/image-resize@3x.png"; sourceTree = "<group>"; };
C69EFA09209A0F650027712B /* JMCallKitNotifier.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JMCallKitNotifier.swift; sourceTree = "<group>"; }; C69EFA09209A0F650027712B /* JMCallKitEmitter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JMCallKitEmitter.swift; sourceTree = "<group>"; };
C69EFA0A209A0F660027712B /* JMCallKitProxy.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JMCallKitProxy.swift; sourceTree = "<group>"; }; C69EFA0A209A0F660027712B /* JMCallKitProxy.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JMCallKitProxy.swift; sourceTree = "<group>"; };
C69EFA0B209A0F660027712B /* JMCallKitEventListener.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JMCallKitEventListener.swift; sourceTree = "<group>"; }; C69EFA0B209A0F660027712B /* JMCallKitListener.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JMCallKitListener.swift; sourceTree = "<group>"; };
C6A3425E204EF76800E062DD /* DragGestureController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DragGestureController.swift; sourceTree = "<group>"; }; C6A3425E204EF76800E062DD /* DragGestureController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DragGestureController.swift; sourceTree = "<group>"; };
C6CC49AE207412CF000DFA42 /* PiPViewCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PiPViewCoordinator.swift; sourceTree = "<group>"; }; C6CC49AE207412CF000DFA42 /* PiPViewCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PiPViewCoordinator.swift; sourceTree = "<group>"; };
C6F99C13204DB63D0001F710 /* JitsiMeetView+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "JitsiMeetView+Private.h"; sourceTree = "<group>"; }; C6F99C13204DB63D0001F710 /* JitsiMeetView+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "JitsiMeetView+Private.h"; sourceTree = "<group>"; };
@ -112,12 +112,12 @@
0BCA49681EC4BBE500B793EE /* Resources */ = { 0BCA49681EC4BBE500B793EE /* Resources */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
75635B0820751D6D00F29C9F /* joined.wav */,
75635B0920751D6D00F29C9F /* left.wav */,
0BC4B8681F8C01E100CE8B21 /* CallKitIcon.png */, 0BC4B8681F8C01E100CE8B21 /* CallKitIcon.png */,
C6245F5B2053091D0040BE68 /* image-resize@2x.png */, C6245F5B2053091D0040BE68 /* image-resize@2x.png */,
C6245F5C2053091D0040BE68 /* image-resize@3x.png */, C6245F5C2053091D0040BE68 /* image-resize@3x.png */,
0BCA496B1EC4BBF900B793EE /* jitsi.ttf */, 0BCA496B1EC4BBF900B793EE /* jitsi.ttf */,
75635B0820751D6D00F29C9F /* joined.wav */,
75635B0920751D6D00F29C9F /* left.wav */,
); );
name = Resources; name = Resources;
sourceTree = "<group>"; sourceTree = "<group>";
@ -144,25 +144,24 @@
0BD906E71EC0C00300C8C18E /* src */ = { 0BD906E71EC0C00300C8C18E /* src */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
C69EFA02209A0EFD0027712B /* callkit */,
B386B84F20981A11000DEF7A /* invite */,
C6A3426B204F127900E062DD /* picture-in-picture */,
0BCA495C1EC4B6C600B793EE /* AudioMode.m */,
0BB9AD7C1F60356D001C08DB /* AppInfo.m */, 0BB9AD7C1F60356D001C08DB /* AppInfo.m */,
0BB9AD7A1F5EC8F4001C08DB /* CallKit.m */, 0BCA495C1EC4B6C600B793EE /* AudioMode.m */,
C69EFA02209A0EFD0027712B /* callkit */,
0BA13D301EE83FF8007BEF7F /* ExternalAPI.m */, 0BA13D301EE83FF8007BEF7F /* ExternalAPI.m */,
0BD906E91EC0C00300C8C18E /* Info.plist */, 0BD906E91EC0C00300C8C18E /* Info.plist */,
0B7C2CFC200F51D60060D076 /* LaunchOptions.m */, B386B84F20981A11000DEF7A /* invite */,
0BD906E81EC0C00300C8C18E /* JitsiMeet.h */, 0BD906E81EC0C00300C8C18E /* JitsiMeet.h */,
0B412F161EDEC65D00B1A0A6 /* JitsiMeetView.h */, 0B412F161EDEC65D00B1A0A6 /* JitsiMeetView.h */,
0B412F171EDEC65D00B1A0A6 /* JitsiMeetView.m */, 0B412F171EDEC65D00B1A0A6 /* JitsiMeetView.m */,
C6F99C13204DB63D0001F710 /* JitsiMeetView+Private.h */, C6F99C13204DB63D0001F710 /* JitsiMeetView+Private.h */,
0B412F1B1EDEC80100B1A0A6 /* JitsiMeetViewDelegate.h */, 0B412F1B1EDEC80100B1A0A6 /* JitsiMeetViewDelegate.h */,
0B7C2CFC200F51D60060D076 /* LaunchOptions.m */,
0B44A0181F902126009D1D64 /* MPVolumeViewManager.m */, 0B44A0181F902126009D1D64 /* MPVolumeViewManager.m */,
0B93EF7C1EC9DDCD0030D24D /* RCTBridgeWrapper.h */, C6A3426B204F127900E062DD /* picture-in-picture */,
0B93EF7D1EC9DDCD0030D24D /* RCTBridgeWrapper.m */,
0BCA495D1EC4B6C600B793EE /* POSIX.m */, 0BCA495D1EC4B6C600B793EE /* POSIX.m */,
0BCA495E1EC4B6C600B793EE /* Proximity.m */, 0BCA495E1EC4B6C600B793EE /* Proximity.m */,
0B93EF7C1EC9DDCD0030D24D /* RCTBridgeWrapper.h */,
0B93EF7D1EC9DDCD0030D24D /* RCTBridgeWrapper.m */,
); );
path = src; path = src;
sourceTree = "<group>"; sourceTree = "<group>";
@ -170,11 +169,11 @@
9C3C6FA2341729836589B856 /* Frameworks */ = { 9C3C6FA2341729836589B856 /* Frameworks */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
0BB9AD781F5EC6D7001C08DB /* Intents.framework */,
0BB9AD761F5EC6CE001C08DB /* CallKit.framework */, 0BB9AD761F5EC6CE001C08DB /* CallKit.framework */,
0B93EF7A1EC608550030D24D /* CoreText.framework */, 0B93EF7A1EC608550030D24D /* CoreText.framework */,
0BCA49631EC4B76D00B793EE /* WebRTC.framework */, 0BB9AD781F5EC6D7001C08DB /* Intents.framework */,
03F2ADC957FF109849B7FCA1 /* libPods-JitsiMeet.a */, 03F2ADC957FF109849B7FCA1 /* libPods-JitsiMeet.a */,
0BCA49631EC4B76D00B793EE /* WebRTC.framework */,
); );
name = Frameworks; name = Frameworks;
sourceTree = "<group>"; sourceTree = "<group>";
@ -208,8 +207,9 @@
C69EFA02209A0EFD0027712B /* callkit */ = { C69EFA02209A0EFD0027712B /* callkit */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
C69EFA0B209A0F660027712B /* JMCallKitEventListener.swift */, 0BB9AD7A1F5EC8F4001C08DB /* CallKit.m */,
C69EFA09209A0F650027712B /* JMCallKitNotifier.swift */, C69EFA09209A0F650027712B /* JMCallKitEmitter.swift */,
C69EFA0B209A0F660027712B /* JMCallKitListener.swift */,
C69EFA0A209A0F660027712B /* JMCallKitProxy.swift */, C69EFA0A209A0F660027712B /* JMCallKitProxy.swift */,
); );
path = callkit; path = callkit;
@ -407,10 +407,10 @@
0BCA495F1EC4B6C600B793EE /* AudioMode.m in Sources */, 0BCA495F1EC4B6C600B793EE /* AudioMode.m in Sources */,
0B44A0191F902126009D1D64 /* MPVolumeViewManager.m in Sources */, 0B44A0191F902126009D1D64 /* MPVolumeViewManager.m in Sources */,
0BCA49611EC4B6C600B793EE /* Proximity.m in Sources */, 0BCA49611EC4B6C600B793EE /* Proximity.m in Sources */,
C69EFA0C209A0F660027712B /* JMCallKitNotifier.swift in Sources */, C69EFA0C209A0F660027712B /* JMCallKitEmitter.swift in Sources */,
C6A34261204EF76800E062DD /* DragGestureController.swift in Sources */, C6A34261204EF76800E062DD /* DragGestureController.swift in Sources */,
C69EFA0D209A0F660027712B /* JMCallKitProxy.swift in Sources */, C69EFA0D209A0F660027712B /* JMCallKitProxy.swift in Sources */,
C69EFA0E209A0F660027712B /* JMCallKitEventListener.swift in Sources */, C69EFA0E209A0F660027712B /* JMCallKitListener.swift in Sources */,
0B412F191EDEC65D00B1A0A6 /* JitsiMeetView.m in Sources */, 0B412F191EDEC65D00B1A0A6 /* JitsiMeetView.m in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;

View File

@ -39,7 +39,7 @@ static NSString * const RNCallKitPerformSetMutedCallAction
static NSString * const RNCallKitProviderDidReset static NSString * const RNCallKitProviderDidReset
= @"providerDidReset"; = @"providerDidReset";
@interface RNCallKit : RCTEventEmitter <JMCallKitEventListener> @interface RNCallKit : RCTEventEmitter <JMCallKitListener>
@end @end
@implementation RNCallKit @implementation RNCallKit
@ -112,7 +112,7 @@ RCT_EXPORT_METHOD(setProviderConfiguration:(NSDictionary *)dictionary) {
dictionary); dictionary);
#endif #endif
if (![JMCallKitProxy hasProviderBeenConfigurated]) { if (![JMCallKitProxy isProviderConfigured]) {
[self configureProviderFromDictionary:dictionary]; [self configureProviderFromDictionary:dictionary];
} }
@ -130,11 +130,8 @@ RCT_EXPORT_METHOD(startCall:(NSString *)callUUID
NSLog(@"[RNCallKit][startCall] callUUID = %@", callUUID); NSLog(@"[RNCallKit][startCall] callUUID = %@", callUUID);
#endif #endif
NSUUID *callUUID_ = [[NSUUID alloc] initWithUUIDString:callUUID]; // Don't start a new call if there's an active call for the specified
// callUUID. JitsiMeetView was configured for an incoming call.
// Don't start a call action if there's
// an active call for this UUID
// (i.e. JitsiMeetView was configured from an incoming call
if ([JMCallKitProxy hasActiveCallForUUID:callUUID]) { if ([JMCallKitProxy hasActiveCallForUUID:callUUID]) {
resolve(nil); resolve(nil);
return; return;
@ -142,6 +139,7 @@ RCT_EXPORT_METHOD(startCall:(NSString *)callUUID
CXHandle *handle_ CXHandle *handle_
= [[CXHandle alloc] initWithType:CXHandleTypeGeneric value:handle]; = [[CXHandle alloc] initWithType:CXHandleTypeGeneric value:handle];
NSUUID *callUUID_ = [[NSUUID alloc] initWithUUIDString:callUUID];
CXStartCallAction *action CXStartCallAction *action
= [[CXStartCallAction alloc] initWithCallUUID:callUUID_ = [[CXStartCallAction alloc] initWithCallUUID:callUUID_
handle:handle_]; handle:handle_];
@ -229,7 +227,8 @@ RCT_EXPORT_METHOD(updateCall:(NSString *)callUUID
NSString *ringtoneSound = dictionary[@"ringtoneSound"]; NSString *ringtoneSound = dictionary[@"ringtoneSound"];
[JMCallKitProxy configureCallKitProviderWithLocalizedName:localizedName [JMCallKitProxy
configureProviderWithLocalizedName:localizedName
ringtoneSound:ringtoneSound ringtoneSound:ringtoneSound
iconTemplateImageData:iconTemplateImageData]; iconTemplateImageData:iconTemplateImageData];
} }
@ -255,7 +254,7 @@ RCT_EXPORT_METHOD(updateCall:(NSString *)callUUID
}]; }];
} }
#pragma mark - JitsiMeetCallKitListener #pragma mark - JMCallKitListener
// Called when the provider has been reset. We should terminate all calls. // Called when the provider has been reset. We should terminate all calls.
- (void)providerDidReset { - (void)providerDidReset {

View File

@ -18,7 +18,7 @@ import AVKit
import CallKit import CallKit
import Foundation import Foundation
internal final class JMCallKitNotifier: NSObject, CXProviderDelegate { internal final class JMCallKitEmitter: NSObject, CXProviderDelegate {
private var listeners = Set<JMCallKitEventListenerWrapper>() private var listeners = Set<JMCallKitEventListenerWrapper>()
@ -26,14 +26,14 @@ internal final class JMCallKitNotifier: NSObject, CXProviderDelegate {
// MARK: - Add/remove listeners // MARK: - Add/remove listeners
func addListener(_ listener: JMCallKitEventListener) { func addListener(_ listener: JMCallKitListener) {
let wrapper = JMCallKitEventListenerWrapper(listener: listener) let wrapper = JMCallKitEventListenerWrapper(listener: listener)
objc_sync_enter(listeners) objc_sync_enter(listeners)
listeners.insert(wrapper) listeners.insert(wrapper)
objc_sync_exit(listeners) objc_sync_exit(listeners)
} }
func removeListener(_ listener: JMCallKitEventListener) { func removeListener(_ listener: JMCallKitListener) {
let wrapper = JMCallKitEventListenerWrapper(listener: listener) let wrapper = JMCallKitEventListenerWrapper(listener: listener)
objc_sync_enter(listeners) objc_sync_enter(listeners)
listeners.remove(wrapper) listeners.remove(wrapper)
@ -50,7 +50,9 @@ internal final class JMCallKitNotifier: NSObject, CXProviderDelegate {
func provider(_ provider: CXProvider, perform action: CXAnswerCallAction) { func provider(_ provider: CXProvider, perform action: CXAnswerCallAction) {
objc_sync_enter(listeners) objc_sync_enter(listeners)
listeners.forEach { $0.listener?.performAnswerCall?(UUID: action.callUUID) } listeners.forEach {
$0.listener?.performAnswerCall?(UUID: action.callUUID)
}
objc_sync_exit(listeners) objc_sync_exit(listeners)
action.fulfill() action.fulfill()
@ -58,7 +60,9 @@ internal final class JMCallKitNotifier: NSObject, CXProviderDelegate {
func provider(_ provider: CXProvider, perform action: CXEndCallAction) { func provider(_ provider: CXProvider, perform action: CXEndCallAction) {
objc_sync_enter(listeners) objc_sync_enter(listeners)
listeners.forEach { $0.listener?.performEndCall?(UUID: action.callUUID) } listeners.forEach {
$0.listener?.performEndCall?(UUID: action.callUUID)
}
objc_sync_exit(listeners) objc_sync_exit(listeners)
action.fulfill() action.fulfill()
@ -86,7 +90,8 @@ internal final class JMCallKitNotifier: NSObject, CXProviderDelegate {
action.fulfill() action.fulfill()
} }
func provider(_ provider: CXProvider, didActivate audioSession: AVAudioSession) { func provider(_ provider: CXProvider,
didActivate audioSession: AVAudioSession) {
objc_sync_enter(listeners) objc_sync_enter(listeners)
listeners.forEach { listeners.forEach {
$0.listener?.providerDidActivateAudioSession?(session: audioSession) $0.listener?.providerDidActivateAudioSession?(session: audioSession)
@ -94,11 +99,32 @@ internal final class JMCallKitNotifier: NSObject, CXProviderDelegate {
objc_sync_exit(listeners) objc_sync_exit(listeners)
} }
func provider(_ provider: CXProvider, didDeactivate audioSession: AVAudioSession) { func provider(_ provider: CXProvider,
didDeactivate audioSession: AVAudioSession) {
objc_sync_enter(listeners) objc_sync_enter(listeners)
listeners.forEach { listeners.forEach {
$0.listener?.providerDidDeactivateAudioSession?(session: audioSession) $0.listener?.providerDidDeactivateAudioSession?(
session: audioSession)
} }
objc_sync_exit(listeners) objc_sync_exit(listeners)
} }
} }
fileprivate struct JMCallKitEventListenerWrapper: Hashable {
public var hashValue: Int
internal weak var listener: JMCallKitListener?
public init(listener: JMCallKitListener) {
self.listener = listener
self.hashValue = listener.hash
}
public static func ==(lhs: JMCallKitEventListenerWrapper,
rhs: JMCallKitEventListenerWrapper) -> Bool {
// XXX We're aware that "[t]wo instances with equal hash values are not
// necessarily equal to each other."
return lhs.hashValue == rhs.hashValue
}
}

View File

@ -18,7 +18,7 @@ import AVKit
import CallKit import CallKit
import Foundation import Foundation
@objc public protocol JMCallKitEventListener: NSObjectProtocol { @objc public protocol JMCallKitListener: NSObjectProtocol {
@available(iOS 10.0, *) @available(iOS 10.0, *)
@objc optional func providerDidReset() @objc optional func providerDidReset()
@ -44,20 +44,3 @@ import Foundation
@available(iOS 10.0, *) @available(iOS 10.0, *)
@objc optional func providerTimedOutPerformingAction(action: CXAction) @objc optional func providerTimedOutPerformingAction(action: CXAction)
} }
internal struct JMCallKitEventListenerWrapper: Hashable {
public var hashValue: Int
internal weak var listener: JMCallKitEventListener?
public init(listener: JMCallKitEventListener) {
self.listener = listener
self.hashValue = listener.hash
}
public static func ==(lhs: JMCallKitEventListenerWrapper,
rhs: JMCallKitEventListenerWrapper) -> Bool {
return lhs.hashValue == rhs.hashValue
}
}

View File

@ -21,77 +21,77 @@ import Foundation
@available(iOS 10.0, *) @available(iOS 10.0, *)
@objc public final class JMCallKitProxy: NSObject { @objc public final class JMCallKitProxy: NSObject {
override private init() {} private override init() {}
// MARK: - CallKit proxy // MARK: - CallKit proxy
internal static let cxProvider: CXProvider = { private static let provider: CXProvider = {
let config = CXProviderConfiguration(localizedName: "") let configuration = CXProviderConfiguration(localizedName: "")
let provider = CXProvider(configuration: config) return CXProvider(configuration: configuration)
return provider
}() }()
internal static let cxCallController: CXCallController = { private static var providerConfiguration: CXProviderConfiguration? {
didSet {
guard let configuration = providerConfiguration else { return }
provider.configuration = configuration
provider.setDelegate(emitter, queue: nil)
}
}
private static let callController: CXCallController = {
return CXCallController() return CXCallController()
}() }()
internal static let callKitNotifier: JMCallKitNotifier = { private static let emitter: JMCallKitEmitter = {
return JMCallKitNotifier() return JMCallKitEmitter()
}() }()
internal static var cxProviderConfiguration: CXProviderConfiguration? { /// Enables the proxy in between CallKit and the consumers of the SDK.
didSet { /// Defaults to enabled, set to false when you don't want to use CallKit.
guard let providerConfiguration = cxProviderConfiguration else { return }
cxProvider.configuration = providerConfiguration
cxProvider.setDelegate(callKitNotifier, queue: nil)
}
}
/// Enables the proxy in between callkit and the consumers of the SDK
/// Default to enabled, set to false when you don't want to use callkit
@objc public static var enabled: Bool = true { @objc public static var enabled: Bool = true {
didSet { didSet {
if enabled == false { if enabled == false {
cxProvider.setDelegate(nil, queue: nil) provider.setDelegate(nil, queue: nil)
} }
} }
} }
@objc public static func hasProviderBeenConfigurated() -> Bool { @objc public static func configureProvider(localizedName: String,
return cxProviderConfiguration != nil
}
@objc public static func configureCallKitProvider(localizedName: String,
ringtoneSound: String?, ringtoneSound: String?,
iconTemplateImageData: Data?) { iconTemplateImageData: Data?) {
let configuration = CXProviderConfiguration(localizedName: localizedName) let configuration = CXProviderConfiguration(localizedName: localizedName)
configuration.ringtoneSound = ringtoneSound
configuration.iconTemplateImageData = iconTemplateImageData configuration.iconTemplateImageData = iconTemplateImageData
configuration.maximumCallGroups = 1 configuration.maximumCallGroups = 1
configuration.maximumCallsPerCallGroup = 1 configuration.maximumCallsPerCallGroup = 1
configuration.ringtoneSound = ringtoneSound
configuration.supportedHandleTypes = [CXHandle.HandleType.generic] configuration.supportedHandleTypes = [CXHandle.HandleType.generic]
configuration.supportsVideo = true configuration.supportsVideo = true
cxProviderConfiguration = configuration
providerConfiguration = configuration
} }
@objc public static func addListener(_ listener: JMCallKitEventListener) { @objc public static func isProviderConfigured() -> Bool {
callKitNotifier.addListener(listener) return providerConfiguration != nil
} }
@objc public static func removeListener(_ listener: JMCallKitEventListener) { @objc public static func addListener(_ listener: JMCallKitListener) {
callKitNotifier.removeListener(listener) emitter.addListener(listener)
}
@objc public static func removeListener(_ listener: JMCallKitListener) {
emitter.removeListener(listener)
} }
@objc public static func hasActiveCallForUUID(_ callUUID: String) -> Bool { @objc public static func hasActiveCallForUUID(_ callUUID: String) -> Bool {
let activeCallForUUID = cxCallController.callObserver.calls.first { let activeCallForUUID = callController.callObserver.calls.first {
$0.uuid == UUID(uuidString: callUUID) $0.uuid == UUID(uuidString: callUUID)
} }
guard activeCallForUUID != nil else { return false } guard activeCallForUUID != nil else { return false }
return true return true
} }
@objc public static func reportNewIncomingCall(UUID: UUID, @objc public static func reportNewIncomingCall(
UUID: UUID,
handle: String?, handle: String?,
displayName: String?, displayName: String?,
hasVideo: Bool, hasVideo: Bool,
@ -101,7 +101,7 @@ import Foundation
let callUpdate = makeCXUpdate(handle: handle, let callUpdate = makeCXUpdate(handle: handle,
displayName: displayName, displayName: displayName,
hasVideo: hasVideo) hasVideo: hasVideo)
cxProvider.reportNewIncomingCall(with: UUID, provider.reportNewIncomingCall(with: UUID,
update: callUpdate, update: callUpdate,
completion: completion) completion: completion)
} }
@ -115,39 +115,43 @@ import Foundation
let callUpdate = makeCXUpdate(handle: handle, let callUpdate = makeCXUpdate(handle: handle,
displayName: displayName, displayName: displayName,
hasVideo: hasVideo) hasVideo: hasVideo)
cxProvider.reportCall(with: UUID, updated: callUpdate) provider.reportCall(with: UUID, updated: callUpdate)
} }
@objc public static func reportCall(with UUID: UUID, @objc public static func reportCall(
with UUID: UUID,
endedAt dateEnded: Date?, endedAt dateEnded: Date?,
reason endedReason: CXCallEndedReason) { reason endedReason: CXCallEndedReason) {
guard enabled else { return } guard enabled else { return }
cxProvider.reportCall(with: UUID, provider.reportCall(with: UUID,
endedAt: dateEnded, endedAt: dateEnded,
reason: endedReason) reason: endedReason)
} }
@objc public static func reportOutgoingCall(with UUID: UUID, @objc public static func reportOutgoingCall(
with UUID: UUID,
startedConnectingAt dateStartedConnecting: Date?) { startedConnectingAt dateStartedConnecting: Date?) {
guard enabled else { return } guard enabled else { return }
cxProvider.reportOutgoingCall(with: UUID, provider.reportOutgoingCall(with: UUID,
startedConnectingAt: dateStartedConnecting) startedConnectingAt: dateStartedConnecting)
} }
@objc public static func reportOutgoingCall(with UUID: UUID, @objc public static func reportOutgoingCall(
with UUID: UUID,
connectedAt dateConnected: Date?) { connectedAt dateConnected: Date?) {
guard enabled else { return } guard enabled else { return }
cxProvider.reportOutgoingCall(with: UUID, connectedAt: dateConnected) provider.reportOutgoingCall(with: UUID, connectedAt: dateConnected)
} }
@objc public static func request(_ transaction: CXTransaction, @objc public static func request(
_ transaction: CXTransaction,
completion: @escaping (Error?) -> Swift.Void) { completion: @escaping (Error?) -> Swift.Void) {
guard enabled else { return } guard enabled else { return }
cxCallController.request(transaction, completion: completion) callController.request(transaction, completion: completion)
} }
// MARK: - Callkit Proxy helpers // MARK: - Callkit Proxy helpers
@ -173,5 +177,4 @@ import Foundation
return update return update
} }
} }

View File

@ -2,10 +2,7 @@
import uuid from 'uuid'; import uuid from 'uuid';
import { import { createTrackMutedEvent, sendAnalytics } from '../../analytics';
createTrackMutedEvent,
sendAnalytics
} from '../../analytics';
import { import {
APP_WILL_MOUNT, APP_WILL_MOUNT,
APP_WILL_UNMOUNT, APP_WILL_UNMOUNT,
@ -29,16 +26,13 @@ import {
setAudioMuted setAudioMuted
} from '../../base/media'; } from '../../base/media';
import { MiddlewareRegistry } from '../../base/redux'; import { MiddlewareRegistry } from '../../base/redux';
import { import { TRACK_CREATE_ERROR, isLocalTrackMuted } from '../../base/tracks';
TRACK_CREATE_ERROR,
isLocalTrackMuted
} from '../../base/tracks';
import { _SET_CALLKIT_SUBSCRIPTIONS } from './actionTypes'; import { _SET_CALLKIT_SUBSCRIPTIONS } from './actionTypes';
import CallKit from './CallKit'; import CallKit from './CallKit';
/** /**
* Middleware that captures several system actions and hooks up CallKit. * Middleware that captures system actions and hooks up CallKit.
* *
* @param {Store} store - The redux store. * @param {Store} store - The redux store.
* @returns {Function} * @returns {Function}
@ -84,17 +78,17 @@ CallKit && MiddlewareRegistry.register(store => next => action => {
}); });
/** /**
* Notifies the feature jwt that the action {@link APP_WILL_MOUNT} is being * Notifies the feature callkit that the action {@link APP_WILL_MOUNT} is being
* dispatched within a specific redux {@code store}. * dispatched within a specific redux {@code store}.
* *
* @param {Store} store - The redux store in which the specified {@code action} * @param {Store} store - The redux store in which the specified {@code action}
* is being dispatched. * is being dispatched.
* @param {Dispatch} next - The redux dispatch function to dispatch the * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
* specified {@code action} to the specified {@code store}. * specified {@code action} in the specified {@code store}.
* @param {Action} action - The redux action {@code APP_WILL_MOUNT} which is * @param {Action} action - The redux action {@code APP_WILL_MOUNT} which is
* being dispatched in the specified {@code store}. * being dispatched in the specified {@code store}.
* @private * @private
* @returns {*} * @returns {*} The value returned by {@code next(action)}.
*/ */
function _appWillMount({ dispatch, getState }, next, action) { function _appWillMount({ dispatch, getState }, next, action) {
const result = next(action); const result = next(action);
@ -119,8 +113,8 @@ function _appWillMount({ dispatch, getState }, next, action) {
context), context),
// According to CallKit's documentation, when the system resets we // According to CallKit's documentation, when the system resets we
// should terminate all calls. Hence, providerDidReset is the same // should terminate all calls. Hence, providerDidReset is the same to us
// to us as performEndCallAction. // as performEndCallAction.
CallKit.addListener( CallKit.addListener(
'providerDidReset', 'providerDidReset',
_onPerformEndCallAction, _onPerformEndCallAction,
@ -136,17 +130,17 @@ function _appWillMount({ dispatch, getState }, next, action) {
} }
/** /**
* Notifies the feature jwt that the action {@link CONFERENCE_FAILED} is being * Notifies the feature callkit that the action {@link CONFERENCE_FAILED} is
* dispatched within a specific redux {@code store}. * being dispatched within a specific redux {@code store}.
* *
* @param {Store} store - The redux store in which the specified {@code action} * @param {Store} store - The redux store in which the specified {@code action}
* is being dispatched. * is being dispatched.
* @param {Dispatch} next - The redux dispatch function to dispatch the * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
* specified {@code action} to the specified {@code store}. * specified {@code action} in the specified {@code store}.
* @param {Action} action - The redux action {@code CONFERENCE_FAILED} which is * @param {Action} action - The redux action {@code CONFERENCE_FAILED} which is
* being dispatched in the specified {@code store}. * being dispatched in the specified {@code store}.
* @private * @private
* @returns {*} * @returns {*} The value returned by {@code next(action)}.
*/ */
function _conferenceFailed(store, next, action) { function _conferenceFailed(store, next, action) {
const result = next(action); const result = next(action);
@ -166,17 +160,17 @@ function _conferenceFailed(store, next, action) {
} }
/** /**
* Notifies the feature jwt that the action {@link CONFERENCE_JOINED} is being * Notifies the feature callkit that the action {@link CONFERENCE_JOINED} is
* dispatched within a specific redux {@code store}. * being dispatched within a specific redux {@code store}.
* *
* @param {Store} store - The redux store in which the specified {@code action} * @param {Store} store - The redux store in which the specified {@code action}
* is being dispatched. * is being dispatched.
* @param {Dispatch} next - The redux dispatch function to dispatch the * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
* specified {@code action} to the specified {@code store}. * specified {@code action} in the specified {@code store}.
* @param {Action} action - The redux action {@code CONFERENCE_JOINED} which is * @param {Action} action - The redux action {@code CONFERENCE_JOINED} which is
* being dispatched in the specified {@code store}. * being dispatched in the specified {@code store}.
* @private * @private
* @returns {*} * @returns {*} The value returned by {@code next(action)}.
*/ */
function _conferenceJoined(store, next, action) { function _conferenceJoined(store, next, action) {
const result = next(action); const result = next(action);
@ -191,17 +185,17 @@ function _conferenceJoined(store, next, action) {
} }
/** /**
* Notifies the feature jwt that the action {@link CONFERENCE_LEFT} is being * Notifies the feature callkit that the action {@link CONFERENCE_LEFT} is being
* dispatched within a specific redux {@code store}. * dispatched within a specific redux {@code store}.
* *
* @param {Store} store - The redux store in which the specified {@code action} * @param {Store} store - The redux store in which the specified {@code action}
* is being dispatched. * is being dispatched.
* @param {Dispatch} next - The redux dispatch function to dispatch the * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
* specified {@code action} to the specified {@code store}. * specified {@code action} in the specified {@code store}.
* @param {Action} action - The redux action {@code CONFERENCE_LEFT} which is * @param {Action} action - The redux action {@code CONFERENCE_LEFT} which is
* being dispatched in the specified {@code store}. * being dispatched in the specified {@code store}.
* @private * @private
* @returns {*} * @returns {*} The value returned by {@code next(action)}.
*/ */
function _conferenceLeft(store, next, action) { function _conferenceLeft(store, next, action) {
const result = next(action); const result = next(action);
@ -216,29 +210,29 @@ function _conferenceLeft(store, next, action) {
} }
/** /**
* Notifies the feature jwt that the action {@link CONFERENCE_WILL_JOIN} is * Notifies the feature callkit that the action {@link CONFERENCE_WILL_JOIN} is
* being dispatched within a specific redux {@code store}. * being dispatched within a specific redux {@code store}.
* *
* @param {Store} store - The redux store in which the specified {@code action} * @param {Store} store - The redux store in which the specified {@code action}
* is being dispatched. * is being dispatched.
* @param {Dispatch} next - The redux dispatch function to dispatch the * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
* specified {@code action} to the specified {@code store}. * specified {@code action} in the specified {@code store}.
* @param {Action} action - The redux action {@code CONFERENCE_WILL_JOIN} which * @param {Action} action - The redux action {@code CONFERENCE_WILL_JOIN} which
* is being dispatched in the specified {@code store}. * is being dispatched in the specified {@code store}.
* @private * @private
* @returns {*} * @returns {*} The value returned by {@code next(action)}.
*/ */
function _conferenceWillJoin({ getState }, next, action) { function _conferenceWillJoin({ getState }, next, action) {
const result = next(action); const result = next(action);
const { conference } = action; const { conference } = action;
const state = getState(); const state = getState();
const { callUUID } = state['features/base/config'];
const url = getInviteURL(state); const url = getInviteURL(state);
const hasVideo = !isVideoMutedByAudioOnly(state); const hasVideo = !isVideoMutedByAudioOnly(state);
const { callUUID } = state['features/base/config'];
// When assigning the call UUID, do so in upper case, since iOS will // When assigning the call UUID, do so in upper case, since iOS will return
// return it upper cased. // it upper cased.
conference.callUUID = (callUUID || uuid.v4()).toUpperCase(); conference.callUUID = (callUUID || uuid.v4()).toUpperCase();
CallKit.startCall(conference.callUUID, url.toString(), hasVideo) CallKit.startCall(conference.callUUID, url.toString(), hasVideo)
@ -306,17 +300,17 @@ function _onPerformSetMutedCallAction({ callUUID, muted: newValue }) {
} }
/** /**
* Notifies the feature jwt that the action {@link SET_AUDIO_MUTED} is being * Notifies the feature callkit that the action {@link SET_AUDIO_MUTED} is being
* dispatched within a specific redux {@code store}. * dispatched within a specific redux {@code store}.
* *
* @param {Store} store - The redux store in which the specified {@code action} * @param {Store} store - The redux store in which the specified {@code action}
* is being dispatched. * is being dispatched.
* @param {Dispatch} next - The redux dispatch function to dispatch the * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
* specified {@code action} to the specified {@code store}. * specified {@code action} in the specified {@code store}.
* @param {Action} action - The redux action {@code SET_AUDIO_MUTED} which is * @param {Action} action - The redux action {@code SET_AUDIO_MUTED} which is
* being dispatched in the specified {@code store}. * being dispatched in the specified {@code store}.
* @private * @private
* @returns {*} * @returns {*} The value returned by {@code next(action)}.
*/ */
function _setAudioMuted({ getState }, next, action) { function _setAudioMuted({ getState }, next, action) {
const result = next(action); const result = next(action);
@ -331,17 +325,18 @@ function _setAudioMuted({ getState }, next, action) {
} }
/** /**
* Notifies the feature jwt that the action {@link _SET_CALLKIT_SUBSCRIPTIONS} * Notifies the feature callkit that the action
* is being dispatched within a specific redux {@code store}. * {@link _SET_CALLKIT_SUBSCRIPTIONS} is being dispatched within a specific
* redux {@code store}.
* *
* @param {Store} store - The redux store in which the specified {@code action} * @param {Store} store - The redux store in which the specified {@code action}
* is being dispatched. * is being dispatched.
* @param {Dispatch} next - The redux dispatch function to dispatch the * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
* specified {@code action} to the specified {@code store}. * specified {@code action} in the specified {@code store}.
* @param {Action} action - The redux action {@code _SET_CALLKIT_SUBSCRIPTIONS} * @param {Action} action - The redux action {@code _SET_CALLKIT_SUBSCRIPTIONS}
* which is being dispatched in the specified {@code store}. * which is being dispatched in the specified {@code store}.
* @private * @private
* @returns {*} * @returns {*} The value returned by {@code next(action)}.
*/ */
function _setCallKitSubscriptions({ getState }, next, action) { function _setCallKitSubscriptions({ getState }, next, action) {
const { subscriptions } = getState()['features/callkit']; const { subscriptions } = getState()['features/callkit'];
@ -356,17 +351,17 @@ function _setCallKitSubscriptions({ getState }, next, action) {
} }
/** /**
* Notifies the feature jwt that the action {@link SET_VIDEO_MUTED} is being * Notifies the feature callkit that the action {@link SET_VIDEO_MUTED} is being
* dispatched within a specific redux {@code store}. * dispatched within a specific redux {@code store}.
* *
* @param {Store} store - The redux store in which the specified {@code action} * @param {Store} store - The redux store in which the specified {@code action}
* is being dispatched. * is being dispatched.
* @param {Dispatch} next - The redux dispatch function to dispatch the * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
* specified {@code action} to the specified {@code store}. * specified {@code action} in the specified {@code store}.
* @param {Action} action - The redux action {@code SET_VIDEO_MUTED} which is * @param {Action} action - The redux action {@code SET_VIDEO_MUTED} which is
* being dispatched in the specified {@code store}. * being dispatched in the specified {@code store}.
* @private * @private
* @returns {*} * @returns {*} The value returned by {@code next(action)}.
*/ */
function _setVideoMuted({ getState }, next, action) { function _setVideoMuted({ getState }, next, action) {
const result = next(action); const result = next(action);
@ -385,17 +380,17 @@ function _setVideoMuted({ getState }, next, action) {
/** /**
* Handles a track creation failure. This is relevant to us in the following * Handles a track creation failure. This is relevant to us in the following
* (corner) case: if the user never gave their permission to use the microphone * (corner) case: if the user never gave their permission to use the microphone
* and try to unmute from the CallKit interface, this will fail, and we need * and try to unmute from the CallKit interface, this will fail, and we need to
* to sync back the CallKit button state. * sync back the CallKit button state.
* *
* @param {Store} store - The redux store in which the specified {@code action} * @param {Store} store - The redux store in which the specified {@code action}
* is being dispatched. * is being dispatched.
* @param {Dispatch} next - The redux dispatch function to dispatch the * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
* specified {@code action} to the specified {@code store}. * specified {@code action} in the specified {@code store}.
* @param {Action} action - The redux action {@code TRACK_CREARE_ERROR} which is * @param {Action} action - The redux action {@code TRACK_CREARE_ERROR} which is
* being dispatched in the specified {@code store}. * being dispatched in the specified {@code store}.
* @private * @private
* @returns {*} * @returns {*} The value returned by {@code next(action)}.
*/ */
function _trackCreateError({ getState }, next, action) { function _trackCreateError({ getState }, next, action) {
const result = next(action); const result = next(action);