livevoice-sdk-react-native 2.0.1 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (207) hide show
  1. package/README.md +105 -66
  2. package/android/build.gradle +5 -4
  3. package/android/src/main/java/io/livevoice/react/LiveVoiceModule.kt +122 -188
  4. package/android/src/main/java/io/livevoice/react/__SDK.kt +2 -2
  5. package/ios/LiveVoiceRNBridge.swift +362 -0
  6. package/ios/LiveVoiceSdkReactNative.mm +187 -158
  7. package/ios/__SDK.h +1 -1
  8. package/ios/livevoice_spm_backport.rb +202 -0
  9. package/lib/module/components/BrandingView.js +58 -39
  10. package/lib/module/components/BrandingView.js.map +1 -1
  11. package/lib/module/components/ChannelView.js +355 -44
  12. package/lib/module/components/ChannelView.js.map +1 -1
  13. package/lib/module/components/ErrorView.js +5 -6
  14. package/lib/module/components/ErrorView.js.map +1 -1
  15. package/lib/module/components/LiveVoiceSpinner.js +81 -0
  16. package/lib/module/components/LiveVoiceSpinner.js.map +1 -0
  17. package/lib/module/components/LiveVoiceView.js +311 -133
  18. package/lib/module/components/LiveVoiceView.js.map +1 -1
  19. package/lib/module/components/PasswordPrompt.js +165 -0
  20. package/lib/module/components/PasswordPrompt.js.map +1 -0
  21. package/lib/module/components/PlayButtonView.js +180 -244
  22. package/lib/module/components/PlayButtonView.js.map +1 -1
  23. package/lib/module/components/ReconnectingView.js +31 -53
  24. package/lib/module/components/ReconnectingView.js.map +1 -1
  25. package/lib/module/icons/branding-ios.png +0 -0
  26. package/lib/module/icons/camera-off-android.png +0 -0
  27. package/lib/module/icons/camera-off-android@2x.png +0 -0
  28. package/lib/module/icons/camera-off-android@3x.png +0 -0
  29. package/lib/module/icons/cpu-android.png +0 -0
  30. package/lib/module/icons/cpu-android@2x.png +0 -0
  31. package/lib/module/icons/cpu-android@3x.png +0 -0
  32. package/lib/module/icons/cpu-ios.png +0 -0
  33. package/lib/module/icons/cpu-ios@2x.png +0 -0
  34. package/lib/module/icons/cpu-ios@3x.png +0 -0
  35. package/lib/module/icons/lock-android.png +0 -0
  36. package/lib/module/icons/lock-android@2x.png +0 -0
  37. package/lib/module/icons/lock-android@3x.png +0 -0
  38. package/lib/module/icons/lock-ios.png +0 -0
  39. package/lib/module/icons/lock-ios@2x.png +0 -0
  40. package/lib/module/icons/lock-ios@3x.png +0 -0
  41. package/lib/module/icons/mic-off-android.png +0 -0
  42. package/lib/module/icons/mic-off-android@2x.png +0 -0
  43. package/lib/module/icons/mic-off-android@3x.png +0 -0
  44. package/lib/module/icons/mic-slash-ios.png +0 -0
  45. package/lib/module/icons/mic-slash-ios@2x.png +0 -0
  46. package/lib/module/icons/mic-slash-ios@3x.png +0 -0
  47. package/lib/module/icons/video-slash-ios.png +0 -0
  48. package/lib/module/icons/video-slash-ios@2x.png +0 -0
  49. package/lib/module/icons/video-slash-ios@3x.png +0 -0
  50. package/lib/module/index.js +11 -6
  51. package/lib/module/index.js.map +1 -1
  52. package/lib/module/sdk/Bridge.js +236 -0
  53. package/lib/module/sdk/Bridge.js.map +1 -0
  54. package/lib/module/sdk/Event.js +160 -0
  55. package/lib/module/sdk/Event.js.map +1 -0
  56. package/lib/module/sdk/Lifecycle.js +331 -0
  57. package/lib/module/sdk/Lifecycle.js.map +1 -0
  58. package/lib/module/sdk/LiveVoiceSdk.js +262 -268
  59. package/lib/module/sdk/LiveVoiceSdk.js.map +1 -1
  60. package/lib/module/sdk/LiveVoiceState.js +208 -40
  61. package/lib/module/sdk/LiveVoiceState.js.map +1 -1
  62. package/lib/module/sdk/LogEntries.js +99 -0
  63. package/lib/module/sdk/LogEntries.js.map +1 -0
  64. package/lib/module/sdk/Models.js +2 -0
  65. package/lib/module/{util/UIState.js.map → sdk/Models.js.map} +1 -1
  66. package/lib/module/{util/PlayingState.js → sdk/NativeSdkVersions.js} +9 -8
  67. package/lib/module/sdk/NativeSdkVersions.js.map +1 -0
  68. package/lib/module/sdk/Observables.js +391 -0
  69. package/lib/module/sdk/Observables.js.map +1 -0
  70. package/lib/module/sdk/Passwords.js +298 -0
  71. package/lib/module/sdk/Passwords.js.map +1 -0
  72. package/lib/module/sdk/Playback.js +35 -0
  73. package/lib/module/sdk/Playback.js.map +1 -0
  74. package/lib/module/specs/NativeLiveVoiceSdk.js.map +1 -1
  75. package/lib/module/util/Colors.js +2 -1
  76. package/lib/module/util/Colors.js.map +1 -1
  77. package/lib/module/util/Translations.js +34 -11
  78. package/lib/module/util/Translations.js.map +1 -1
  79. package/lib/module/util/freeze.js +26 -0
  80. package/lib/module/util/freeze.js.map +1 -0
  81. package/lib/module/util/logger.js +79 -41
  82. package/lib/module/util/logger.js.map +1 -1
  83. package/lib/typescript/src/components/BrandingView.d.ts +4 -0
  84. package/lib/typescript/src/components/BrandingView.d.ts.map +1 -1
  85. package/lib/typescript/src/components/ChannelView.d.ts +29 -3
  86. package/lib/typescript/src/components/ChannelView.d.ts.map +1 -1
  87. package/lib/typescript/src/components/ErrorView.d.ts +5 -3
  88. package/lib/typescript/src/components/ErrorView.d.ts.map +1 -1
  89. package/lib/typescript/src/components/LiveVoiceSpinner.d.ts +16 -0
  90. package/lib/typescript/src/components/LiveVoiceSpinner.d.ts.map +1 -0
  91. package/lib/typescript/src/components/LiveVoiceView.d.ts +81 -21
  92. package/lib/typescript/src/components/LiveVoiceView.d.ts.map +1 -1
  93. package/lib/typescript/src/components/PasswordPrompt.d.ts +13 -0
  94. package/lib/typescript/src/components/PasswordPrompt.d.ts.map +1 -0
  95. package/lib/typescript/src/components/PlayButtonView.d.ts +12 -329
  96. package/lib/typescript/src/components/PlayButtonView.d.ts.map +1 -1
  97. package/lib/typescript/src/components/ReconnectingView.d.ts +6 -3
  98. package/lib/typescript/src/components/ReconnectingView.d.ts.map +1 -1
  99. package/lib/typescript/src/index.d.ts +15 -6
  100. package/lib/typescript/src/index.d.ts.map +1 -1
  101. package/lib/typescript/src/sdk/Bridge.d.ts +36 -0
  102. package/lib/typescript/src/sdk/Bridge.d.ts.map +1 -0
  103. package/lib/typescript/src/sdk/Event.d.ts +97 -0
  104. package/lib/typescript/src/sdk/Event.d.ts.map +1 -0
  105. package/lib/typescript/src/sdk/Lifecycle.d.ts +191 -0
  106. package/lib/typescript/src/sdk/Lifecycle.d.ts.map +1 -0
  107. package/lib/typescript/src/sdk/LiveVoiceSdk.d.ts +195 -190
  108. package/lib/typescript/src/sdk/LiveVoiceSdk.d.ts.map +1 -1
  109. package/lib/typescript/src/sdk/LiveVoiceState.d.ts +77 -9
  110. package/lib/typescript/src/sdk/LiveVoiceState.d.ts.map +1 -1
  111. package/lib/typescript/src/sdk/LogEntries.d.ts +28 -0
  112. package/lib/typescript/src/sdk/LogEntries.d.ts.map +1 -0
  113. package/lib/typescript/src/sdk/Models.d.ts +114 -0
  114. package/lib/typescript/src/sdk/Models.d.ts.map +1 -0
  115. package/lib/typescript/src/sdk/NativeSdkVersions.d.ts +6 -0
  116. package/lib/typescript/src/sdk/NativeSdkVersions.d.ts.map +1 -0
  117. package/lib/typescript/src/sdk/Observables.d.ts +123 -0
  118. package/lib/typescript/src/sdk/Observables.d.ts.map +1 -0
  119. package/lib/typescript/src/sdk/Passwords.d.ts +72 -0
  120. package/lib/typescript/src/sdk/Passwords.d.ts.map +1 -0
  121. package/lib/typescript/src/sdk/Playback.d.ts +9 -0
  122. package/lib/typescript/src/sdk/Playback.d.ts.map +1 -0
  123. package/lib/typescript/src/specs/NativeLiveVoiceSdk.d.ts +34 -31
  124. package/lib/typescript/src/specs/NativeLiveVoiceSdk.d.ts.map +1 -1
  125. package/lib/typescript/src/util/Colors.d.ts.map +1 -1
  126. package/lib/typescript/src/util/Translations.d.ts +30 -8
  127. package/lib/typescript/src/util/Translations.d.ts.map +1 -1
  128. package/lib/typescript/src/util/freeze.d.ts +6 -0
  129. package/lib/typescript/src/util/freeze.d.ts.map +1 -0
  130. package/lib/typescript/src/util/logger.d.ts +17 -7
  131. package/lib/typescript/src/util/logger.d.ts.map +1 -1
  132. package/livevoice-sdk-react-native.podspec +29 -4
  133. package/package.json +12 -9
  134. package/src/components/BrandingView.tsx +42 -55
  135. package/src/components/ChannelView.tsx +329 -38
  136. package/src/components/ErrorView.tsx +9 -12
  137. package/src/components/LiveVoiceSpinner.tsx +87 -0
  138. package/src/components/LiveVoiceView.tsx +319 -201
  139. package/src/components/PasswordPrompt.tsx +144 -0
  140. package/src/components/PlayButtonView.tsx +165 -269
  141. package/src/components/ReconnectingView.tsx +28 -81
  142. package/src/icons/branding-ios.png +0 -0
  143. package/src/icons/camera-off-android.png +0 -0
  144. package/src/icons/camera-off-android@2x.png +0 -0
  145. package/src/icons/camera-off-android@3x.png +0 -0
  146. package/src/icons/cpu-android.png +0 -0
  147. package/src/icons/cpu-android@2x.png +0 -0
  148. package/src/icons/cpu-android@3x.png +0 -0
  149. package/src/icons/cpu-ios.png +0 -0
  150. package/src/icons/cpu-ios@2x.png +0 -0
  151. package/src/icons/cpu-ios@3x.png +0 -0
  152. package/src/icons/lock-android.png +0 -0
  153. package/src/icons/lock-android@2x.png +0 -0
  154. package/src/icons/lock-android@3x.png +0 -0
  155. package/src/icons/lock-ios.png +0 -0
  156. package/src/icons/lock-ios@2x.png +0 -0
  157. package/src/icons/lock-ios@3x.png +0 -0
  158. package/src/icons/mic-off-android.png +0 -0
  159. package/src/icons/mic-off-android@2x.png +0 -0
  160. package/src/icons/mic-off-android@3x.png +0 -0
  161. package/src/icons/mic-slash-ios.png +0 -0
  162. package/src/icons/mic-slash-ios@2x.png +0 -0
  163. package/src/icons/mic-slash-ios@3x.png +0 -0
  164. package/src/icons/video-slash-ios.png +0 -0
  165. package/src/icons/video-slash-ios@2x.png +0 -0
  166. package/src/icons/video-slash-ios@3x.png +0 -0
  167. package/src/index.tsx +92 -6
  168. package/src/sdk/Bridge.ts +259 -0
  169. package/src/sdk/Event.ts +187 -0
  170. package/src/sdk/Lifecycle.ts +366 -0
  171. package/src/sdk/LiveVoiceSdk.ts +285 -309
  172. package/src/sdk/LiveVoiceState.ts +230 -60
  173. package/src/sdk/LogEntries.ts +88 -0
  174. package/src/sdk/Models.ts +129 -0
  175. package/src/{util/PlayingState.ts → sdk/NativeSdkVersions.ts} +7 -6
  176. package/src/sdk/Observables.ts +414 -0
  177. package/src/sdk/Passwords.ts +286 -0
  178. package/src/sdk/Playback.ts +30 -0
  179. package/src/specs/NativeLiveVoiceSdk.ts +42 -38
  180. package/src/util/Colors.ts +2 -1
  181. package/src/util/Translations.ts +34 -12
  182. package/src/util/freeze.ts +23 -0
  183. package/src/util/logger.ts +79 -52
  184. package/lib/module/components/AudioOutputSwitchView.js +0 -138
  185. package/lib/module/components/AudioOutputSwitchView.js.map +0 -1
  186. package/lib/module/components/index.js +0 -24
  187. package/lib/module/components/index.js.map +0 -1
  188. package/lib/module/icons/mic.png +0 -0
  189. package/lib/module/util/ForegroundServiceConfig.js +0 -38
  190. package/lib/module/util/ForegroundServiceConfig.js.map +0 -1
  191. package/lib/module/util/PlayingState.js.map +0 -1
  192. package/lib/module/util/UIState.js +0 -4
  193. package/lib/typescript/src/components/AudioOutputSwitchView.d.ts +0 -6
  194. package/lib/typescript/src/components/AudioOutputSwitchView.d.ts.map +0 -1
  195. package/lib/typescript/src/components/index.d.ts +0 -9
  196. package/lib/typescript/src/components/index.d.ts.map +0 -1
  197. package/lib/typescript/src/util/ForegroundServiceConfig.d.ts +0 -19
  198. package/lib/typescript/src/util/ForegroundServiceConfig.d.ts.map +0 -1
  199. package/lib/typescript/src/util/PlayingState.d.ts +0 -7
  200. package/lib/typescript/src/util/PlayingState.d.ts.map +0 -1
  201. package/lib/typescript/src/util/UIState.d.ts +0 -86
  202. package/lib/typescript/src/util/UIState.d.ts.map +0 -1
  203. package/src/components/AudioOutputSwitchView.tsx +0 -146
  204. package/src/components/index.tsx +0 -21
  205. package/src/icons/mic.png +0 -0
  206. package/src/util/ForegroundServiceConfig.tsx +0 -42
  207. package/src/util/UIState.ts +0 -106
@@ -12,7 +12,12 @@
12
12
  //===----------------------------------------------------------------------===//
13
13
 
14
14
  #import "LiveVoiceSdkReactNative.h"
15
- #import "LiveVoiceSDK/LiveVoiceSDK.h"
15
+ // The SDK is reached only through LiveVoiceRNBridge.swift.
16
+ #if __has_include(<livevoice_sdk_react_native/livevoice_sdk_react_native-Swift.h>)
17
+ #import <livevoice_sdk_react_native/livevoice_sdk_react_native-Swift.h>
18
+ #else
19
+ #import "livevoice_sdk_react_native-Swift.h"
20
+ #endif
16
21
  #import "React/RCTVersion.h"
17
22
  #import "__SDK.h"
18
23
  #import <os/log.h>
@@ -50,22 +55,66 @@ static void LiveVoiceLogInfo(NSString *event, NSDictionary<NSString *, id> *fiel
50
55
  message.UTF8String);
51
56
  }
52
57
 
53
- // Declare conformance privately
54
- @interface LiveVoiceSdkReactNative () <LiveVoiceDelegate>
58
+ @interface LiveVoiceSdkReactNative ()
59
+ // Ownership is protected by @synchronized(self). Never call Swift or a reply
60
+ // while holding it: attaching asynchronously enters the main actor.
61
+ @property(nonatomic, strong, nullable) LiveVoiceRNBridge *liveVoice;
62
+ @property(nonatomic) BOOL runtimeInvalidated;
63
+ @property(nonatomic) BOOL attaching;
64
+ @property(nonatomic, strong) NSMutableArray<void (^)(LiveVoiceRNBridge *_Nullable)> *attachReplies;
65
+ // Events reach JavaScript through the runtime's C++ module, which a reload
66
+ // destroys once `invalidate` returns. The bridge's streams end later, on the
67
+ // main actor, so values still queued must be dropped. This lock makes an
68
+ // emission and `invalidate` exclude each other; nothing else is called under it.
69
+ @property(nonatomic, strong) NSLock *emitLock;
70
+ @property(nonatomic) BOOL emitsStopped;
55
71
  @end
56
72
 
57
73
  @implementation LiveVoiceSdkReactNative
58
74
 
59
75
  RCT_EXPORT_MODULE(LiveVoiceModule)
60
76
 
77
+ - (instancetype)init {
78
+ if ((self = [super init])) _emitLock = [NSLock new];
79
+ return self;
80
+ }
81
+
82
+ /// Runs `emit` unless the runtime went away; `invalidate` waits for one in progress.
83
+ - (void)emitUnlessInvalidated:(void (NS_NOESCAPE ^)(void))emit {
84
+ [self.emitLock lock];
85
+ if (!self.emitsStopped) emit();
86
+ [self.emitLock unlock];
87
+ }
88
+
61
89
  - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
62
90
  (const facebook::react::ObjCTurboModule::InitParams &)params {
63
91
  return std::make_shared<facebook::react::NativeLiveVoiceSdkSpecJSI>(params);
64
92
  }
65
93
 
94
+ static void LiveVoiceReject(RCTPromiseRejectBlock reject, NSString *error) {
95
+ NSDictionary *wire = [NSJSONSerialization JSONObjectWithData:[error dataUsingEncoding:NSUTF8StringEncoding] options:0 error:nil];
96
+ NSString *code = [wire isKindOfClass:[NSDictionary class]] ? wire[@"code"] : nil;
97
+ reject([code isKindOfClass:[NSString class]] ? code : @"generic", error, nil);
98
+ }
99
+
100
+ /// Calls `use` with the attached bridge, attaching it first if needed, or with
101
+ /// nil once the runtime went away.
102
+ - (void)withBridge:(void (^)(LiveVoiceRNBridge *_Nullable))use {
103
+ BOOL invalidated = NO;
104
+ LiveVoiceRNBridge *attached;
105
+ @synchronized(self) {
106
+ invalidated = self.runtimeInvalidated;
107
+ attached = self.liveVoice;
108
+ if (!invalidated && !attached) {
109
+ if (!self.attachReplies) self.attachReplies = [NSMutableArray new];
110
+ [self.attachReplies addObject:use];
111
+ if (self.attaching) return;
112
+ self.attaching = YES;
113
+ }
114
+ }
115
+ if (invalidated) { use(nil); return; }
116
+ if (attached) { use(attached); return; }
66
117
 
67
-
68
- - (void)initialize:(NSString *_Nullable)androidServiceConfig {
69
118
  NSDictionary *versionInfo = RCTGetReactNativeVersion();
70
119
  NSString *major = versionInfo[RCTVersionMajor];
71
120
  NSString *minor = versionInfo[RCTVersionMinor];
@@ -73,236 +122,216 @@ RCT_EXPORT_MODULE(LiveVoiceModule)
73
122
  NSString *const PLATFORM_VERSION =
74
123
  [NSString stringWithFormat:@"%@.%@.%@", major, minor, patch];
75
124
 
76
- [LiveVoice initializeWithDelegate:self
77
- platform:SDKPlatformReactNative
78
- platformVersion:PLATFORM_VERSION
79
- sdkVersion:SDK_VERSION];
80
- LiveVoiceLogInfo(@"LV_INIT", @{@"platformVersion" : PLATFORM_VERSION});
81
- }
82
-
83
- // The bridge commands take a completion now. These turbomodule methods are
84
- // void/fire-and-forget: the bridge serializes lifecycle commands internally and
85
- // turbomodule calls arrive in order, so leave→join stays ordered without it.
86
- - (void)joinEvent:(nonnull NSString *)joinCode
87
- password:(nullable NSString *)password
88
- apiKey:(nonnull NSString *)apiKey {
89
- [LiveVoice joinEventWithCode:joinCode password:password apiKey:apiKey completion:^{}];
90
- }
91
-
92
- - (void)leaveEvent {
93
- [LiveVoice leaveEventWithCompletion:^{}];
94
- }
95
-
96
- - (void)reconnect {
97
- [LiveVoice reconnectWithCompletion:^{}];
98
- }
99
-
100
- #pragma mark - Initial values
101
-
102
- // The bridge accessors are completion-based; RN turbomodule getters must return
103
- // synchronously, so we block on a semaphore until the completion lands. These run
104
- // on the JS thread (off-main) while the completion fires on the main actor, so the
105
- // wait can't deadlock. `getCurrentClaims` keeps its wire name but reads `currentFeatures`.
106
- - (nullable NSString *)getCurrentClaims {
107
- __block NSString *result = nil;
108
- dispatch_semaphore_t sema = dispatch_semaphore_create(0);
109
- [LiveVoice currentFeaturesWithCompletion:^(NSString *_Nullable value) {
110
- result = value;
111
- dispatch_semaphore_signal(sema);
125
+ __weak LiveVoiceSdkReactNative *weakSelf = self;
126
+ [LiveVoiceRNBridge
127
+ startWithReactNativeVersion:PLATFORM_VERSION
128
+ wrapperVersion:SDK_VERSION
129
+ onState:^(NSString *value) {
130
+ LiveVoiceSdkReactNative *module = weakSelf;
131
+ [module emitUnlessInvalidated:^{ [module emitOnState:value]; }];
132
+ }
133
+ onPasswordRequest:^(NSString *value) {
134
+ LiveVoiceSdkReactNative *module = weakSelf;
135
+ [module emitUnlessInvalidated:^{ [module emitOnPasswordRequest:value]; }];
136
+ }
137
+ onPasswordRequestCancelled:^(NSString *value) {
138
+ LiveVoiceSdkReactNative *module = weakSelf;
139
+ [module emitUnlessInvalidated:^{ [module emitOnPasswordRequestCancelled:value]; }];
140
+ }
141
+ onPasswordStoreRequest:^(NSString *value) {
142
+ LiveVoiceSdkReactNative *module = weakSelf;
143
+ [module emitUnlessInvalidated:^{ [module emitOnPasswordStoreRequest:value]; }];
144
+ }
145
+ onLogEntry:^(NSString *value) {
146
+ LiveVoiceSdkReactNative *module = weakSelf;
147
+ [module emitUnlessInvalidated:^{ [module emitOnLogEntry:value]; }];
148
+ }
149
+ completion:^(LiveVoiceRNBridge *created) {
150
+ LiveVoiceSdkReactNative *module = weakSelf;
151
+ if (!module) { [created invalidate]; return; }
152
+ NSArray<void (^)(LiveVoiceRNBridge *_Nullable)> *replies;
153
+ BOOL invalidated;
154
+ @synchronized(module) {
155
+ invalidated = module.runtimeInvalidated;
156
+ if (!invalidated) module.liveVoice = created;
157
+ module.attaching = NO;
158
+ replies = [module.attachReplies copy];
159
+ module.attachReplies = nil;
160
+ }
161
+ if (invalidated) [created invalidate];
162
+ else LiveVoiceLogInfo(@"LV_INIT", @{@"platformVersion" : PLATFORM_VERSION});
163
+ for (void (^pending)(LiveVoiceRNBridge *_Nullable) in replies) pending(invalidated ? nil : created);
112
164
  }];
113
- dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
114
- return result;
115
165
  }
116
166
 
117
- - (nonnull NSString *)getCurrentUiState {
118
- __block NSString *result = @"";
119
- dispatch_semaphore_t sema = dispatch_semaphore_create(0);
120
- [LiveVoice currentViewStateWithCompletion:^(NSString *value) {
121
- result = value;
122
- dispatch_semaphore_signal(sema);
167
+ - (void)initialize:(NSString *)configuration
168
+ resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
169
+ [self withBridge:^(LiveVoiceRNBridge *bridge) {
170
+ if (bridge == nil) { LiveVoiceReject(reject, [LiveVoiceRNBridge errorJSONWithCode:@"cancelled"]); return; }
171
+ [bridge initializeWithConfiguration:configuration completion:^(NSString *snapshot, NSString *error) {
172
+ if (error != nil) LiveVoiceReject(reject, error);
173
+ else resolve(snapshot);
174
+ }];
123
175
  }];
124
- dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
125
- return result;
126
176
  }
127
177
 
128
- // true=speaker, false=headphones
129
- - (nonnull NSNumber *)getCurrentAudioState {
130
- __block BOOL result = NO;
131
- dispatch_semaphore_t sema = dispatch_semaphore_create(0);
132
- [LiveVoice currentAudioOutputIsSpeakerWithCompletion:^(BOOL value) {
133
- result = value;
134
- dispatch_semaphore_signal(sema);
178
+ - (void)execute:(NSString *)command payload:(NSString *)arguments
179
+ resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject {
180
+ LiveVoiceRNBridge *bridge;
181
+ BOOL invalidated;
182
+ @synchronized(self) { bridge = self.liveVoice; invalidated = self.runtimeInvalidated; }
183
+ if (bridge == nil) {
184
+ LiveVoiceReject(reject, [LiveVoiceRNBridge errorJSONWithCode:invalidated ? @"cancelled" : @"not_initialized"]);
185
+ return;
186
+ }
187
+ [bridge executeWithName:command arguments:arguments completion:^(NSString *value, NSString *error) {
188
+ if (error != nil) LiveVoiceReject(reject, error);
189
+ else resolve(value ?: @"null");
135
190
  }];
136
- dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
137
- return [NSNumber numberWithBool:result];
138
191
  }
139
192
 
140
- - (nonnull NSString *)getCurrentAvailableSubtitleConfigs {
141
- __block NSString *result = @"";
142
- dispatch_semaphore_t sema = dispatch_semaphore_create(0);
143
- [LiveVoice currentAvailableSubtitlesWithCompletion:^(NSString *value) {
144
- result = value;
145
- dispatch_semaphore_signal(sema);
146
- }];
147
- dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
148
- return result;
193
+ - (NSString *)getErrorMessages {
194
+ return LiveVoiceRNBridge.errorMessages;
149
195
  }
150
196
 
151
- - (nonnull NSString *)getCurrentSubtitles {
152
- __block NSString *result = @"";
153
- dispatch_semaphore_t sema = dispatch_semaphore_create(0);
154
- [LiveVoice currentSubtitlesWithCompletion:^(NSString *value) {
155
- result = value;
156
- dispatch_semaphore_signal(sema);
197
+ // Works before `initialize`: attaches the bridge first if needed, so the
198
+ // preference reaches native and the snapshot later carries it. Ignored once
199
+ // the runtime went away.
200
+ - (void)setAudioOutput:(NSString *)payload {
201
+ [self withBridge:^(LiveVoiceRNBridge *bridge) {
202
+ [bridge setAudioOutput:payload];
157
203
  }];
158
- dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
159
- return result;
160
204
  }
161
205
 
162
- - (nonnull NSString *)getCurrentSubtitleState {
163
- __block NSString *result = @"";
164
- dispatch_semaphore_t sema = dispatch_semaphore_create(0);
165
- [LiveVoice currentSubtitleStateWithCompletion:^(NSString *value) {
166
- result = value;
167
- dispatch_semaphore_signal(sema);
168
- }];
169
- dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
170
- return result;
206
+ - (void)writeLogEntry:(NSString *)payload {
207
+ [LiveVoiceRNBridge writeLogEntry:payload];
171
208
  }
172
209
 
173
- #pragma mark - Actions
174
-
175
- - (void)setLiveVoiceUseSpeaker:(BOOL)useSpeaker {
176
- [LiveVoice setAudioOutputToSpeaker:useSpeaker completion:^{}];
210
+ - (void)answerPasswordRequest:(NSString *)payload {
211
+ [[self bridgeSnapshot] answerPasswordRequest:payload];
177
212
  }
178
213
 
179
- - (void)startChannel:(double)channelID {
180
- [LiveVoice startWithChannelID:channelID completion:^{}];
214
+ - (void)answerPasswordStoreRequest:(NSString *)payload {
215
+ [[self bridgeSnapshot] answerPasswordStoreRequest:payload];
181
216
  }
182
217
 
183
- - (void)stopChannel {
184
- [LiveVoice stopWithCompletion:^{}];
218
+ - (void)setPasswordStore:(NSString *)payload {
219
+ [[self bridgeSnapshot] setPasswordStore:payload];
185
220
  }
186
221
 
187
- #pragma mark - Subtitles
188
-
189
- - (void)startSubtitles:(double)channelId {
190
- NSNumber *_Nullable optionalChannelID =
191
- (channelId == -1) ? nil : [NSNumber numberWithLongLong:channelId];
192
- [LiveVoice startSubtitlesWithChannelID:optionalChannelID completion:^{}];
222
+ - (LiveVoiceRNBridge *)bridgeSnapshot {
223
+ @synchronized(self) { return self.runtimeInvalidated ? nil : self.liveVoice; }
193
224
  }
194
225
 
195
- - (void)stopSubtitles {
196
- [LiveVoice stopSubtitlesWithCompletion:^{}];
226
+ - (void)invalidate {
227
+ [self.emitLock lock];
228
+ self.emitsStopped = YES;
229
+ [self.emitLock unlock];
230
+ LiveVoiceRNBridge *bridge;
231
+ NSArray<void (^)(LiveVoiceRNBridge *_Nullable)> *replies;
232
+ @synchronized(self) {
233
+ self.runtimeInvalidated = YES;
234
+ bridge = self.liveVoice;
235
+ self.liveVoice = nil;
236
+ replies = [self.attachReplies copy];
237
+ self.attachReplies = nil;
238
+ }
239
+ [bridge invalidate];
240
+ for (void (^pending)(LiveVoiceRNBridge *_Nullable) in replies) pending(nil);
197
241
  }
198
242
 
243
+ #pragma mark - Actions
244
+
199
245
  - (void)openLiveVoiceWebsite {
200
- [LiveVoice openLiveVoiceWebsiteWithCompletion:^{}];
246
+ [LiveVoiceRNBridge openLiveVoiceWebsite];
201
247
  }
202
248
 
203
249
  - (nonnull NSString *)getSdkVersion {
204
250
  return SDK_VERSION;
205
251
  }
206
252
 
253
+ - (nonnull NSString *)getNativeSdkVersion {
254
+ return LiveVoiceRNBridge.nativeSdkVersion;
255
+ }
256
+
207
257
  #pragma mark - Translations
208
258
 
209
259
  - (nonnull NSString *)channelStatusOffline {
210
- return [Translations channel_status_offline];
260
+ return [LiveVoiceRNBridge translation:@"channel_status_offline" seconds:0];
211
261
  }
212
262
 
213
263
  - (nonnull NSString *)errorScreenRetrying {
214
- return [Translations error_screen_retrying];
264
+ return [LiveVoiceRNBridge translation:@"error_screen_retrying" seconds:0];
215
265
  }
216
266
 
217
267
  - (nonnull NSString *)errorScreenRetryingIn:(double)seconds {
218
- return [Translations error_screen_retrying_in:(int)seconds];
219
- }
220
-
221
- - (nonnull NSString *)sdkErrorGeneric {
222
- return [Translations sdk_error_generic];
223
- }
224
-
225
- - (nonnull NSString *)sdkErrorInactive {
226
- return [Translations sdk_error_inactive];
227
- }
228
-
229
- - (nonnull NSString *)sdkErrorInvalidApiKey {
230
- return [Translations sdk_error_invalid_api_key];
231
- }
232
-
233
- - (nonnull NSString *)sdkErrorListenerLimitReached {
234
- return [Translations sdk_error_listener_limit_reached];
235
- }
236
-
237
- - (nonnull NSString *)sdkErrorNoNetwork {
238
- return [Translations sdk_error_no_network];
239
- }
240
-
241
- - (nonnull NSString *)sdkErrorNotFound {
242
- return [Translations sdk_error_not_found];
243
- }
244
-
245
- - (nonnull NSString *)sdkErrorRequestFailed:(double)errorCode {
246
- return [Translations
247
- sdk_error_request_failed:[NSString stringWithFormat:@"%1.0f", errorCode]];
248
- }
249
-
250
- - (nonnull NSString *)sdkErrorWrongPassword {
251
- return [Translations sdk_error_wrong_password];
268
+ return [LiveVoiceRNBridge translation:@"error_screen_retrying_in" seconds:(NSInteger)seconds];
252
269
  }
253
270
 
254
271
  - (nonnull NSString *)sdkNoMatchingChannels {
255
- return [Translations sdk_no_matching_channels];
272
+ return [LiveVoiceRNBridge translation:@"sdk_no_matching_channels" seconds:0];
256
273
  }
257
274
 
258
275
  - (nonnull NSString *)streamingByTitle {
259
- return [Translations streaming_by_title];
276
+ return [LiveVoiceRNBridge translation:@"streaming_by_title" seconds:0];
260
277
  }
261
278
 
262
279
  - (nonnull NSString *)accessibilityChannelPlay {
263
- return [Translations a11y_channel_play];
280
+ return [LiveVoiceRNBridge translation:@"a11y_channel_play" seconds:0];
264
281
  }
265
282
 
266
283
  - (nonnull NSString *)accessibilityChannelStatusMuted {
267
- return [Translations a11y_channel_status_muted];
284
+ return [LiveVoiceRNBridge translation:@"a11y_channel_status_muted" seconds:0];
268
285
  }
269
286
 
270
287
  - (nonnull NSString *)accessibilityChannelStop {
271
- return [Translations a11y_channel_stop];
288
+ return [LiveVoiceRNBridge translation:@"a11y_channel_stop" seconds:0];
272
289
  }
273
290
 
274
291
  - (nonnull NSString *)isAiChannelStatusMessage {
275
- return [Translations channel_status_is_ai];
292
+ return [LiveVoiceRNBridge translation:@"channel_status_is_ai" seconds:0];
276
293
  }
277
294
 
278
295
  - (nonnull NSString *)noChannels {
279
- return [Translations sdk_no_matching_channels];
296
+ return [LiveVoiceRNBridge translation:@"no_channels" seconds:0];
280
297
  }
281
298
 
282
299
  - (nonnull NSString *)errorRetryNowButton {
283
- return [Translations action_retry_now];
300
+ return [LiveVoiceRNBridge translation:@"action_retry_now" seconds:0];
284
301
  }
285
302
 
286
- #pragma mark - LiveVoiceDelegate
303
+ #pragma mark - Password prompt
304
+
305
+ - (nonnull NSString *)passwordPromptTitle {
306
+ return [LiveVoiceRNBridge translation:@"password_prompt_title" seconds:0];
307
+ }
308
+
309
+ - (nonnull NSString *)passwordPromptChannelMessage {
310
+ return [LiveVoiceRNBridge translation:@"password_prompt_channel_message" seconds:0];
311
+ }
312
+
313
+ - (nonnull NSString *)passwordPromptEventMessage {
314
+ return [LiveVoiceRNBridge translation:@"password_prompt_event_message" seconds:0];
315
+ }
287
316
 
288
- - (void)viewStateDidChange:(nonnull NSString *)serializedState {
289
- [self emitOnUiStateChanged:serializedState];
317
+ - (nonnull NSString *)passwordPromptWrongPassword {
318
+ return [LiveVoiceRNBridge translation:@"password_prompt_wrong_password" seconds:0];
290
319
  }
291
320
 
292
- - (void)audioOutputDidChange:(BOOL)useSpeaker {
293
- [self emitOnAudioOutputChanged:useSpeaker];
321
+ - (nonnull NSString *)passwordPromptField {
322
+ return [LiveVoiceRNBridge translation:@"password_prompt_field" seconds:0];
294
323
  }
295
324
 
296
- - (void)availableSubtitlesDidChange:(NSString *)available {
297
- [self emitOnAvailableSubtitleConfigsChanged:available];
325
+ - (nonnull NSString *)passwordPromptCancelButton {
326
+ return [LiveVoiceRNBridge translation:@"password_prompt_cancel_button" seconds:0];
298
327
  }
299
328
 
300
- - (void)subtitlesDidChange:(NSString *)subtitles {
301
- [self emitOnSubtitlesChanged:subtitles];
329
+ - (nonnull NSString *)passwordPromptChannelConfirmButton {
330
+ return [LiveVoiceRNBridge translation:@"password_prompt_channel_confirm_button" seconds:0];
302
331
  }
303
332
 
304
- - (void)subtitleStateDidChange:(nonnull NSString *)serialized {
305
- [self emitOnSubtitleStateChanged:serialized];
333
+ - (nonnull NSString *)passwordPromptEventConfirmButton {
334
+ return [LiveVoiceRNBridge translation:@"password_prompt_event_confirm_button" seconds:0];
306
335
  }
307
336
 
308
337
  @end
package/ios/__SDK.h CHANGED
@@ -15,4 +15,4 @@
15
15
  // Generated by tool/generate-native-versions.mjs from package.json.
16
16
  #import <Foundation/Foundation.h>
17
17
 
18
- NSString* const SDK_VERSION = @"2.0.1";
18
+ NSString* const SDK_VERSION = @"3.0.0";
@@ -0,0 +1,202 @@
1
+ #===----------------------------------------------------------------------===#
2
+ #
3
+ # This source file is part of the LiveVoice SDK project
4
+ #
5
+ # Copyright (c) LiveVoice GmbH
6
+ # Licensed under the MIT license
7
+ #
8
+ # See LICENSE for license information
9
+ #
10
+ # SPDX-License-Identifier: MIT
11
+ #
12
+ #===----------------------------------------------------------------------===#
13
+
14
+ # React Native before 0.89 attaches a Swift package from `spm_dependency` to
15
+ # the pod only. Two things then go wrong for a package with dynamic binary
16
+ # frameworks, as the native LiveVoice SDK is:
17
+ #
18
+ # - CocoaPods embeds only the frameworks of pods, so the SDK and WebRTC are
19
+ # linked but never copied into the app, which fails at launch with dyld
20
+ # "Library not loaded".
21
+ # - Xcode writes each binary target's signature both to the shared products
22
+ # dir and to the pod's build dir, and archiving fails on the duplicate.
23
+ #
24
+ # React Native 0.87 and 0.88 add a third: they build the pod straight into the
25
+ # shared products dir and rewrite the app's references to its module map, but
26
+ # name the file after the pod (livevoice-sdk-react-native) instead of its
27
+ # module (livevoice_sdk_react_native), so the app's build cannot find it.
28
+ #
29
+ # React Native 0.89 fixes all three (facebook/react-native#58781). This
30
+ # backports that fix for this pod only, from the podspec, so apps need no
31
+ # Podfile change; with Expo, prebuild would discard one anyway. It does
32
+ # nothing when React Native already has the fix.
33
+
34
+ module LiveVoiceSPMBackport
35
+ EMBED_FUNCTION = 'livevoice_install_spm_framework'
36
+ SIGNATURE_PHASE_NAME = '[LV] Remove duplicate Swift package xcframework signatures'
37
+
38
+ # Taken from React Native 0.89's install_spm_framework: embeds framework $1
39
+ # from where Xcode puts binary targets, if it is a dynamic one.
40
+ EMBED_FUNCTION_SOURCE = <<~'SH'
41
+ livevoice_install_spm_framework()
42
+ {
43
+ local dir
44
+ for dir in "${PODS_CONFIGURATION_BUILD_DIR}" "${PODS_CONFIGURATION_BUILD_DIR}/PackageFrameworks" "${OBJROOT}/UninstalledProducts/${PLATFORM_NAME}"; do
45
+ if [ -d "$dir/$1.framework" ]; then
46
+ if file -b "$dir/$1.framework/$1" | grep -q "dynamically linked"; then
47
+ install_framework "$dir/$1.framework"
48
+ fi
49
+ return
50
+ fi
51
+ done
52
+ }
53
+ SH
54
+
55
+ # The installed React Native embeds Swift package frameworks itself.
56
+ def self.native_support?
57
+ defined?(SPMManager) && SPMManager.const_defined?(:EMBED_FUNCTION)
58
+ end
59
+
60
+ # Hooks into React Native's own post-install step for `pod_name`.
61
+ def self.install(pod_name:, frameworks:, requirement_comment:)
62
+ return if native_support? || !defined?(SPMManager)
63
+
64
+ @pods ||= {}
65
+ @pods[pod_name] = { frameworks: frameworks, comment: requirement_comment }
66
+ SPMManager.prepend(Hook) unless SPMManager.ancestors.include?(Hook)
67
+ end
68
+
69
+ def self.pods
70
+ @pods || {}
71
+ end
72
+
73
+ module Hook
74
+ def apply_on_post_install(installer)
75
+ super
76
+ LiveVoiceSPMBackport.pods.each do |pod_name, info|
77
+ LiveVoiceSPMBackport.embed_frameworks(installer, pod_name, info)
78
+ if LiveVoiceSPMBackport.built_into_products_dir?(installer.pods_project, pod_name)
79
+ # One copy of everything, signatures included: nothing to remove.
80
+ LiveVoiceSPMBackport.fix_modulemap_references(installer, pod_name)
81
+ else
82
+ LiveVoiceSPMBackport.remove_duplicate_signatures(installer.pods_project, pod_name)
83
+ end
84
+ end
85
+ end
86
+ end
87
+
88
+ def self.embed_frameworks(installer, pod_name, info)
89
+ installer.aggregate_targets.each do |aggregate_target|
90
+ next unless aggregate_target.pod_targets.any? { |t| t.name == pod_name }
91
+
92
+ script_path = aggregate_target.embed_frameworks_script_path
93
+ script = File.exist?(script_path) ? File.read(script_path) : nil
94
+ next if script&.include?("#{EMBED_FUNCTION}()")
95
+
96
+ # A project that already gets the frameworks into the app keeps its own
97
+ # way, so nothing is copied twice.
98
+ if embedded_elsewhere?(aggregate_target, script, info[:frameworks])
99
+ ::Pod::UI.puts "[LiveVoice] #{aggregate_target.name} already embeds #{info[:frameworks].join(', ')}"
100
+ next
101
+ end
102
+
103
+ anchor = /^if \[ "\$\{COCOAPODS_PARALLEL_CODE_SIGN\}" == "true" \]; then$/
104
+ unless script&.match?(anchor)
105
+ # Failing here beats an app that installs and then crashes at launch.
106
+ raise ::Pod::Informative, <<~MSG
107
+ [LiveVoice] Cannot embed #{info[:frameworks].join(' and ')} in #{aggregate_target.name}:
108
+ #{script.nil? ? "#{script_path} does not exist" : "#{script_path} does not have the expected CocoaPods layout"}.
109
+ Without them the app fails to launch with dyld "Library not loaded".
110
+ Embed them another way, for example by adding the LiveVoiceSDK Swift package
111
+ product to the app target, or move to React Native 0.89 or later, which embeds
112
+ them itself.
113
+ MSG
114
+ end
115
+
116
+ # The comment names the version, so a version change rewrites this
117
+ # script, an input of the embed phase, and the phase runs again.
118
+ calls = info[:frameworks].map { |name| "#{EMBED_FUNCTION} \"#{name}\"\n" }.join
119
+ File.write(script_path, script.sub(anchor) { "#{EMBED_FUNCTION_SOURCE}# #{info[:comment]}\n#{calls}#{$&}" })
120
+ ::Pod::UI.puts "[LiveVoice] Embedding #{info[:frameworks].join(', ')} in #{aggregate_target.name}"
121
+ end
122
+ end
123
+
124
+ # The app target uses the LiveVoiceSDK package product itself, so Xcode
125
+ # embeds its frameworks, or the embed script already installs them.
126
+ def self.embedded_elsewhere?(aggregate_target, script, frameworks)
127
+ by_package = aggregate_target.user_targets.any? do |target|
128
+ target.respond_to?(:package_product_dependencies) &&
129
+ target.package_product_dependencies.any? { |d| d.product_name == 'LiveVoiceSDK' }
130
+ end
131
+ by_script = !script.nil? && frameworks.all? { |name| script.include?("/#{name}.framework\"") }
132
+ by_package || by_script
133
+ end
134
+
135
+ # React Native 0.87 and later build a static pod with a Swift package
136
+ # straight into the shared products dir.
137
+ def self.built_into_products_dir?(project, pod_name)
138
+ target = project.targets.find { |t| t.name == pod_name }
139
+ !target.nil? && target.build_configurations.all? do |config|
140
+ config.build_settings['CONFIGURATION_BUILD_DIR'] == '${PODS_CONFIGURATION_BUILD_DIR}'
141
+ end
142
+ end
143
+
144
+ # Points the app's -fmodule-map-file flags at the module map where the pod
145
+ # now builds it. Like React Native 0.89, this changes the in-memory xcconfig
146
+ # attributes, because later post-install steps save the same objects again.
147
+ def self.fix_modulemap_references(installer, pod_name)
148
+ pod_target = installer.pod_targets.find { |t| t.name == pod_name }
149
+ return if pod_target.nil?
150
+
151
+ module_name = pod_target.product_module_name
152
+ installer.aggregate_targets.each do |aggregate_target|
153
+ next unless aggregate_target.pod_targets.include?(pod_target)
154
+
155
+ aggregate_target.xcconfigs.each do |config_name, config_file|
156
+ changed = false
157
+ %w[OTHER_CFLAGS OTHER_SWIFT_FLAGS].each do |key|
158
+ value = config_file.attributes[key]
159
+ next unless value
160
+
161
+ updated = value
162
+ .gsub("${PODS_CONFIGURATION_BUILD_DIR}/#{pod_name}/#{module_name}.modulemap",
163
+ "${PODS_CONFIGURATION_BUILD_DIR}/#{module_name}.modulemap")
164
+ .gsub("${PODS_CONFIGURATION_BUILD_DIR}/#{pod_name}.modulemap",
165
+ "${PODS_CONFIGURATION_BUILD_DIR}/#{module_name}.modulemap")
166
+ next if updated == value
167
+
168
+ config_file.attributes[key] = updated
169
+ changed = true
170
+ end
171
+ config_file.save_as(aggregate_target.xcconfig_path(config_name)) if changed
172
+ end
173
+ end
174
+ end
175
+
176
+ def self.remove_duplicate_signatures(project, pod_name)
177
+ target = project.targets.find { |t| t.name == pod_name }
178
+ return if target.nil? || target.shell_script_build_phases.any? { |p| p.name == SIGNATURE_PHASE_NAME }
179
+
180
+ # A fresh UUID that is really unused: Pod::Project's generator skips the
181
+ # check and can collide during post_install (see React Native's spm.rb).
182
+ uuid = project.generate_uuid
183
+ uuid = project.generate_uuid while project.objects_by_uuid.key?(uuid)
184
+ phase = Xcodeproj::Project::Object::PBXShellScriptBuildPhase.new(project, uuid)
185
+ phase.initialize_defaults
186
+ phase.name = SIGNATURE_PHASE_NAME
187
+ # Removes only copies that also exist in the shared products dir, so the
188
+ # only copy stays if the pod is built there after all (for example by the
189
+ # app's own Podfile, after this ran).
190
+ phase.shell_script = <<~'SH'
191
+ for signature in "${CONFIGURATION_BUILD_DIR}"/*.xcframework-*.signature; do
192
+ [ -e "$signature" ] || continue
193
+ [ "${CONFIGURATION_BUILD_DIR}" != "${PODS_CONFIGURATION_BUILD_DIR}" ] || continue
194
+ if [ -e "${PODS_CONFIGURATION_BUILD_DIR}/$(basename "$signature")" ]; then
195
+ rm -f "$signature"
196
+ fi
197
+ done
198
+ SH
199
+ phase.always_out_of_date = '1'
200
+ target.build_phases << phase
201
+ end
202
+ end