@kaleyra/video-react-native-module 1.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 (271) hide show
  1. package/LICENSE +165 -0
  2. package/README.md +292 -0
  3. package/android/build.gradle +100 -0
  4. package/android/gradle.properties +9 -0
  5. package/android/settings.gradle +6 -0
  6. package/android/src/main/AndroidManifest.xml +1 -0
  7. package/android/src/main/assets/kaleyra_video_wrapper_info.txt +1 -0
  8. package/android/src/main/java/com/kaleyra/video_react_native_module/ReactNativeAccessTokenProvider.kt +22 -0
  9. package/android/src/main/java/com/kaleyra/video_react_native_module/ReactNativeContextContainer.kt +9 -0
  10. package/android/src/main/java/com/kaleyra/video_react_native_module/ReactNativeVideoHybridBridge.kt +30 -0
  11. package/android/src/main/java/com/kaleyra/video_react_native_module/VideoNativeEmitter.kt +45 -0
  12. package/android/src/main/java/com/kaleyra/video_react_native_module/VideoNativeModule.kt +109 -0
  13. package/android/src/main/java/com/kaleyra/video_react_native_module/VideoReactPackage.kt +20 -0
  14. package/index.ts +47 -0
  15. package/ios/PluginInfo/_KaleyraVideoHybridVersionInfo.swift +31 -0
  16. package/ios/ReactEvents/ReactNativeEventEmitter.swift +31 -0
  17. package/ios/ReactEvents/VideoNativeEmitter.m +17 -0
  18. package/ios/ReactEvents/VideoNativeEmitter.swift +42 -0
  19. package/ios/ReactNativePlugin-Bridging-Header.h +5 -0
  20. package/ios/ReactNativePlugin.xcodeproj/project.pbxproj +301 -0
  21. package/ios/VideoNativeModule.m +45 -0
  22. package/ios/VideoNativeModule.swift +154 -0
  23. package/lib/commonjs/index.js +12 -0
  24. package/lib/commonjs/native-bridge/TypeScript/Environments.js +41 -0
  25. package/lib/commonjs/native-bridge/TypeScript/Events.js +46 -0
  26. package/lib/commonjs/native-bridge/TypeScript/Regions.js +47 -0
  27. package/lib/commonjs/native-bridge/TypeScript/UserDetailsFormatValidator.js +32 -0
  28. package/lib/commonjs/native-bridge/TypeScript/errors/IllegalArgumentError.js +12 -0
  29. package/lib/commonjs/native-bridge/TypeScript/types/AccessTokenRequest.js +4 -0
  30. package/lib/commonjs/native-bridge/TypeScript/types/AccessTokenResponse.js +36 -0
  31. package/lib/commonjs/native-bridge/TypeScript/types/AudioCallOptions.js +4 -0
  32. package/lib/commonjs/native-bridge/TypeScript/types/AudioCallType.js +19 -0
  33. package/lib/commonjs/native-bridge/TypeScript/types/CallDisplayMode.js +23 -0
  34. package/lib/commonjs/native-bridge/TypeScript/types/CallKitConfiguration.js +4 -0
  35. package/lib/commonjs/native-bridge/TypeScript/types/CallOptions.js +4 -0
  36. package/lib/commonjs/native-bridge/TypeScript/types/CallType.js +23 -0
  37. package/lib/commonjs/native-bridge/TypeScript/types/ChatToolConfiguration.js +4 -0
  38. package/lib/commonjs/native-bridge/TypeScript/types/CreateCallOptions.js +4 -0
  39. package/lib/commonjs/native-bridge/TypeScript/types/Environment.js +4 -0
  40. package/lib/commonjs/native-bridge/TypeScript/types/IosConfiguration.js +4 -0
  41. package/lib/commonjs/native-bridge/TypeScript/types/KaleyraVideoConfiguration.js +4 -0
  42. package/lib/commonjs/native-bridge/TypeScript/types/RecordingType.js +23 -0
  43. package/lib/commonjs/native-bridge/TypeScript/types/Region.js +4 -0
  44. package/lib/commonjs/native-bridge/TypeScript/types/ScreenShareToolConfiguration.js +4 -0
  45. package/lib/commonjs/native-bridge/TypeScript/types/Session.js +4 -0
  46. package/lib/commonjs/native-bridge/TypeScript/types/Tools.js +4 -0
  47. package/lib/commonjs/native-bridge/TypeScript/types/UserDetails.js +4 -0
  48. package/lib/commonjs/native-bridge/TypeScript/types/UserDetailsFormat.js +4 -0
  49. package/lib/commonjs/native-bridge/TypeScript/types/VoipHandlingStrategy.js +19 -0
  50. package/lib/commonjs/src/KaleyraVideo.js +259 -0
  51. package/lib/commonjs/src/ReactNativeEventEmitter.js +40 -0
  52. package/lib/commonjs/src/events/Events.js +4 -0
  53. package/lib/module/index.js +2 -0
  54. package/lib/module/native-bridge/TypeScript/Environments.js +37 -0
  55. package/lib/module/native-bridge/TypeScript/Events.js +43 -0
  56. package/lib/module/native-bridge/TypeScript/Regions.js +43 -0
  57. package/lib/module/native-bridge/TypeScript/UserDetailsFormatValidator.js +28 -0
  58. package/lib/module/native-bridge/TypeScript/errors/IllegalArgumentError.js +8 -0
  59. package/lib/module/native-bridge/TypeScript/types/AccessTokenRequest.js +3 -0
  60. package/lib/module/native-bridge/TypeScript/types/AccessTokenResponse.js +32 -0
  61. package/lib/module/native-bridge/TypeScript/types/AudioCallOptions.js +3 -0
  62. package/lib/module/native-bridge/TypeScript/types/AudioCallType.js +16 -0
  63. package/lib/module/native-bridge/TypeScript/types/CallDisplayMode.js +20 -0
  64. package/lib/module/native-bridge/TypeScript/types/CallKitConfiguration.js +3 -0
  65. package/lib/module/native-bridge/TypeScript/types/CallOptions.js +3 -0
  66. package/lib/module/native-bridge/TypeScript/types/CallType.js +20 -0
  67. package/lib/module/native-bridge/TypeScript/types/ChatToolConfiguration.js +3 -0
  68. package/lib/module/native-bridge/TypeScript/types/CreateCallOptions.js +3 -0
  69. package/lib/module/native-bridge/TypeScript/types/Environment.js +3 -0
  70. package/lib/module/native-bridge/TypeScript/types/IosConfiguration.js +3 -0
  71. package/lib/module/native-bridge/TypeScript/types/KaleyraVideoConfiguration.js +3 -0
  72. package/lib/module/native-bridge/TypeScript/types/RecordingType.js +20 -0
  73. package/lib/module/native-bridge/TypeScript/types/Region.js +3 -0
  74. package/lib/module/native-bridge/TypeScript/types/ScreenShareToolConfiguration.js +3 -0
  75. package/lib/module/native-bridge/TypeScript/types/Session.js +3 -0
  76. package/lib/module/native-bridge/TypeScript/types/Tools.js +3 -0
  77. package/lib/module/native-bridge/TypeScript/types/UserDetails.js +3 -0
  78. package/lib/module/native-bridge/TypeScript/types/UserDetailsFormat.js +3 -0
  79. package/lib/module/native-bridge/TypeScript/types/VoipHandlingStrategy.js +16 -0
  80. package/lib/module/src/KaleyraVideo.js +249 -0
  81. package/lib/module/src/ReactNativeEventEmitter.js +36 -0
  82. package/lib/module/src/events/Events.js +3 -0
  83. package/lib/typescript/index.d.ts +2 -0
  84. package/lib/typescript/native-bridge/TypeScript/Environments.d.ts +28 -0
  85. package/lib/typescript/native-bridge/TypeScript/Events.d.ts +40 -0
  86. package/lib/typescript/native-bridge/TypeScript/Regions.d.ts +32 -0
  87. package/lib/typescript/native-bridge/TypeScript/UserDetailsFormatValidator.d.ts +4 -0
  88. package/lib/typescript/native-bridge/TypeScript/errors/IllegalArgumentError.d.ts +6 -0
  89. package/lib/typescript/native-bridge/TypeScript/types/AccessTokenRequest.d.ts +4 -0
  90. package/lib/typescript/native-bridge/TypeScript/types/AccessTokenResponse.d.ts +12 -0
  91. package/lib/typescript/native-bridge/TypeScript/types/AudioCallOptions.d.ts +11 -0
  92. package/lib/typescript/native-bridge/TypeScript/types/AudioCallType.d.ts +13 -0
  93. package/lib/typescript/native-bridge/TypeScript/types/CallDisplayMode.d.ts +17 -0
  94. package/lib/typescript/native-bridge/TypeScript/types/CallKitConfiguration.d.ts +26 -0
  95. package/lib/typescript/native-bridge/TypeScript/types/CallOptions.d.ts +13 -0
  96. package/lib/typescript/native-bridge/TypeScript/types/CallType.d.ts +17 -0
  97. package/lib/typescript/native-bridge/TypeScript/types/ChatToolConfiguration.d.ts +15 -0
  98. package/lib/typescript/native-bridge/TypeScript/types/CreateCallOptions.d.ts +15 -0
  99. package/lib/typescript/native-bridge/TypeScript/types/Environment.d.ts +9 -0
  100. package/lib/typescript/native-bridge/TypeScript/types/IosConfiguration.d.ts +23 -0
  101. package/lib/typescript/native-bridge/TypeScript/types/KaleyraVideoConfiguration.d.ts +33 -0
  102. package/lib/typescript/native-bridge/TypeScript/types/RecordingType.d.ts +17 -0
  103. package/lib/typescript/native-bridge/TypeScript/types/Region.d.ts +9 -0
  104. package/lib/typescript/native-bridge/TypeScript/types/ScreenShareToolConfiguration.d.ts +19 -0
  105. package/lib/typescript/native-bridge/TypeScript/types/Session.d.ts +16 -0
  106. package/lib/typescript/native-bridge/TypeScript/types/Tools.d.ts +42 -0
  107. package/lib/typescript/native-bridge/TypeScript/types/UserDetails.d.ts +29 -0
  108. package/lib/typescript/native-bridge/TypeScript/types/UserDetailsFormat.d.ts +19 -0
  109. package/lib/typescript/native-bridge/TypeScript/types/VoipHandlingStrategy.d.ts +13 -0
  110. package/lib/typescript/src/KaleyraVideo.d.ts +125 -0
  111. package/lib/typescript/src/ReactNativeEventEmitter.d.ts +15 -0
  112. package/lib/typescript/src/events/Events.d.ts +37 -0
  113. package/native-bridge/LICENSE +165 -0
  114. package/native-bridge/TypeScript/Environments.ts +44 -0
  115. package/native-bridge/TypeScript/Events.ts +43 -0
  116. package/native-bridge/TypeScript/Regions.ts +51 -0
  117. package/native-bridge/TypeScript/UserDetailsFormatValidator.ts +35 -0
  118. package/native-bridge/TypeScript/errors/IllegalArgumentError.ts +9 -0
  119. package/native-bridge/TypeScript/types/AccessTokenRequest.ts +7 -0
  120. package/native-bridge/TypeScript/types/AccessTokenResponse.ts +41 -0
  121. package/native-bridge/TypeScript/types/AudioCallOptions.ts +15 -0
  122. package/native-bridge/TypeScript/types/AudioCallType.ts +17 -0
  123. package/native-bridge/TypeScript/types/CallDisplayMode.ts +22 -0
  124. package/native-bridge/TypeScript/types/CallKitConfiguration.ts +32 -0
  125. package/native-bridge/TypeScript/types/CallOptions.ts +18 -0
  126. package/native-bridge/TypeScript/types/CallType.ts +22 -0
  127. package/native-bridge/TypeScript/types/ChatToolConfiguration.ts +21 -0
  128. package/native-bridge/TypeScript/types/CreateCallOptions.ts +20 -0
  129. package/native-bridge/TypeScript/types/Environment.ts +12 -0
  130. package/native-bridge/TypeScript/types/IosConfiguration.ts +29 -0
  131. package/native-bridge/TypeScript/types/KaleyraVideoConfiguration.ts +42 -0
  132. package/native-bridge/TypeScript/types/RecordingType.ts +22 -0
  133. package/native-bridge/TypeScript/types/Region.ts +12 -0
  134. package/native-bridge/TypeScript/types/ScreenShareToolConfiguration.ts +24 -0
  135. package/native-bridge/TypeScript/types/Session.ts +20 -0
  136. package/native-bridge/TypeScript/types/Tools.ts +50 -0
  137. package/native-bridge/TypeScript/types/UserDetails.ts +37 -0
  138. package/native-bridge/TypeScript/types/UserDetailsFormat.ts +23 -0
  139. package/native-bridge/TypeScript/types/VoipHandlingStrategy.ts +17 -0
  140. package/native-bridge/android/build.gradle +72 -0
  141. package/native-bridge/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  142. package/native-bridge/android/gradle/wrapper/gradle-wrapper.properties +5 -0
  143. package/native-bridge/android/gradle.properties +22 -0
  144. package/native-bridge/android/gradlew +234 -0
  145. package/native-bridge/android/gradlew.bat +89 -0
  146. package/native-bridge/android/settings.gradle +1 -0
  147. package/native-bridge/android/src/main/AndroidManifest.xml +1 -0
  148. package/native-bridge/android/src/main/java/com/kaleyra/video_hybrid_native_bridge/AccessTokenProvider.kt +8 -0
  149. package/native-bridge/android/src/main/java/com/kaleyra/video_hybrid_native_bridge/CallOptionsProxy.kt +9 -0
  150. package/native-bridge/android/src/main/java/com/kaleyra/video_hybrid_native_bridge/ContextContainer.kt +10 -0
  151. package/native-bridge/android/src/main/java/com/kaleyra/video_hybrid_native_bridge/DTOs.kt +407 -0
  152. package/native-bridge/android/src/main/java/com/kaleyra/video_hybrid_native_bridge/SDKAccessTokenProviderProxy.kt +16 -0
  153. package/native-bridge/android/src/main/java/com/kaleyra/video_hybrid_native_bridge/VideoHybridBridge.kt +21 -0
  154. package/native-bridge/android/src/main/java/com/kaleyra/video_hybrid_native_bridge/VideoSDKHybridBridge.kt +64 -0
  155. package/native-bridge/android/src/main/java/com/kaleyra/video_hybrid_native_bridge/configurator/CachedSDKConfigurator.kt +15 -0
  156. package/native-bridge/android/src/main/java/com/kaleyra/video_hybrid_native_bridge/configurator/VideoSDKConfigurator.kt +46 -0
  157. package/native-bridge/android/src/main/java/com/kaleyra/video_hybrid_native_bridge/connector/CachedUserConnector.kt +15 -0
  158. package/native-bridge/android/src/main/java/com/kaleyra/video_hybrid_native_bridge/connector/VideoSDKCachedUserConnector.kt +60 -0
  159. package/native-bridge/android/src/main/java/com/kaleyra/video_hybrid_native_bridge/events/Events.kt +29 -0
  160. package/native-bridge/android/src/main/java/com/kaleyra/video_hybrid_native_bridge/events/EventsEmitter.kt +8 -0
  161. package/native-bridge/android/src/main/java/com/kaleyra/video_hybrid_native_bridge/events/EventsReporter.kt +9 -0
  162. package/native-bridge/android/src/main/java/com/kaleyra/video_hybrid_native_bridge/events/reporter/CallEventsReporter.kt +54 -0
  163. package/native-bridge/android/src/main/java/com/kaleyra/video_hybrid_native_bridge/events/reporter/ChatEventsReporter.kt +43 -0
  164. package/native-bridge/android/src/main/java/com/kaleyra/video_hybrid_native_bridge/events/reporter/CrossPlatformModuleStatus.kt +29 -0
  165. package/native-bridge/android/src/main/java/com/kaleyra/video_hybrid_native_bridge/events/reporter/ModuleEventsReporter.kt +34 -0
  166. package/native-bridge/android/src/main/java/com/kaleyra/video_hybrid_native_bridge/events/reporter/SDKEventsReporter.kt +63 -0
  167. package/native-bridge/android/src/main/java/com/kaleyra/video_hybrid_native_bridge/extensions/CallDisplayExtension.kt +15 -0
  168. package/native-bridge/android/src/main/java/com/kaleyra/video_hybrid_native_bridge/extensions/ConfigurationExtension.kt +39 -0
  169. package/native-bridge/android/src/main/java/com/kaleyra/video_hybrid_native_bridge/extensions/EnvironmentExtension.kt +12 -0
  170. package/native-bridge/android/src/main/java/com/kaleyra/video_hybrid_native_bridge/extensions/RecordingTypeExtension.kt +15 -0
  171. package/native-bridge/android/src/main/java/com/kaleyra/video_hybrid_native_bridge/extensions/RegionExtension.kt +13 -0
  172. package/native-bridge/android/src/main/java/com/kaleyra/video_hybrid_native_bridge/extensions/ScreenShareToolConfigurationExtension.kt +15 -0
  173. package/native-bridge/android/src/main/java/com/kaleyra/video_hybrid_native_bridge/extensions/ToolsExtension.kt +95 -0
  174. package/native-bridge/android/src/main/java/com/kaleyra/video_hybrid_native_bridge/extensions/UserExtensions.kt +35 -0
  175. package/native-bridge/android/src/main/java/com/kaleyra/video_hybrid_native_bridge/notifications/KaleyraVideoNotificationReceiver.kt +139 -0
  176. package/native-bridge/android/src/main/java/com/kaleyra/video_hybrid_native_bridge/notifications/KaleyraVideoNotificationService.kt +85 -0
  177. package/native-bridge/android/src/main/java/com/kaleyra/video_hybrid_native_bridge/repository/ConfigurationEntity.kt +27 -0
  178. package/native-bridge/android/src/main/java/com/kaleyra/video_hybrid_native_bridge/repository/ConnectedUserEntity.kt +30 -0
  179. package/native-bridge/android/src/main/java/com/kaleyra/video_hybrid_native_bridge/repository/Converters.kt +25 -0
  180. package/native-bridge/android/src/main/java/com/kaleyra/video_hybrid_native_bridge/repository/UserDetailsDao.kt +21 -0
  181. package/native-bridge/android/src/main/java/com/kaleyra/video_hybrid_native_bridge/repository/UserDetailsEntity.kt +22 -0
  182. package/native-bridge/android/src/main/java/com/kaleyra/video_hybrid_native_bridge/repository/VideoHybridBridgeRepository.kt +39 -0
  183. package/native-bridge/android/src/main/java/com/kaleyra/video_hybrid_native_bridge/ui/SDKUserInterfacePresenter.kt +49 -0
  184. package/native-bridge/android/src/main/java/com/kaleyra/video_hybrid_native_bridge/ui/UserInterfacePresenter.kt +14 -0
  185. package/native-bridge/android/src/main/java/com/kaleyra/video_hybrid_native_bridge/user_details/CachedUserDetails.kt +18 -0
  186. package/native-bridge/android/src/main/java/com/kaleyra/video_hybrid_native_bridge/user_details/CachedUserDetailsFormatter.kt +59 -0
  187. package/native-bridge/android/src/main/java/com/kaleyra/video_hybrid_native_bridge/user_details/SDKCachedUserDetails.kt +74 -0
  188. package/native-bridge/android/src/main/java/com/kaleyra/video_hybrid_native_bridge/utils/CaseInsensitiveEnumTypeAdapterFactory.kt +48 -0
  189. package/native-bridge/android/src/main/java/com/kaleyra/video_hybrid_native_bridge/utils/TLSSocketFactoryCompat.kt +76 -0
  190. package/native-bridge/iOS/KaleyraVideoHybridNativeBridge.xcodeproj/project.pbxproj +1399 -0
  191. package/native-bridge/iOS/KaleyraVideoHybridNativeBridge.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  192. package/native-bridge/iOS/KaleyraVideoHybridNativeBridge.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  193. package/native-bridge/iOS/KaleyraVideoHybridNativeBridge.xcodeproj/xcshareddata/IDETemplateMacros.plist +9 -0
  194. package/native-bridge/iOS/KaleyraVideoHybridNativeBridge.xcodeproj/xcshareddata/xcschemes/KaleyraVideoHybridNativeBridge.xcscheme +79 -0
  195. package/native-bridge/iOS/KaleyraVideoHybridNativeBridge.xcworkspace/contents.xcworkspacedata +10 -0
  196. package/native-bridge/iOS/KaleyraVideoHybridNativeBridge.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  197. package/native-bridge/iOS/Podfile +28 -0
  198. package/native-bridge/iOS/Podfile.lock +20 -0
  199. package/native-bridge/iOS/Source/Abstractions/BandyerSDKProtocol.swift +24 -0
  200. package/native-bridge/iOS/Source/Abstractions/CallWindowProtocol.swift +18 -0
  201. package/native-bridge/iOS/Source/AccessToken/AccessTokenRequester.swift +9 -0
  202. package/native-bridge/iOS/Source/AccessToken/TokenProvider.swift +78 -0
  203. package/native-bridge/iOS/Source/Broadcast/BroadcastConfigurationPlistReader.swift +49 -0
  204. package/native-bridge/iOS/Source/Concurrency/DispatchQueue+isMain.swift +19 -0
  205. package/native-bridge/iOS/Source/Concurrency/Lock.swift +21 -0
  206. package/native-bridge/iOS/Source/Concurrency/MainQueueDispatcher.swift +23 -0
  207. package/native-bridge/iOS/Source/Concurrency/MainQueueRelay.swift +18 -0
  208. package/native-bridge/iOS/Source/DTOs/AccessTokenRequest+Encodable.swift +27 -0
  209. package/native-bridge/iOS/Source/DTOs/AccessTokenResponse+Decodable.swift +24 -0
  210. package/native-bridge/iOS/Source/DTOs/Array+JSON.swift +6 -0
  211. package/native-bridge/iOS/Source/DTOs/AudioCallOptions+Bandyer.swift +14 -0
  212. package/native-bridge/iOS/Source/DTOs/AudioCallOptions+Decodable.swift +18 -0
  213. package/native-bridge/iOS/Source/DTOs/AudioCallOptions+Equatable.swift +12 -0
  214. package/native-bridge/iOS/Source/DTOs/AudioCallType+Bandyer.swift +18 -0
  215. package/native-bridge/iOS/Source/DTOs/AudioCallType+Decodable.swift +25 -0
  216. package/native-bridge/iOS/Source/DTOs/CallKitConfiguration+Decodable.swift +20 -0
  217. package/native-bridge/iOS/Source/DTOs/CallOptions+Bandyer.swift +14 -0
  218. package/native-bridge/iOS/Source/DTOs/CallOptions+Decodable.swift +16 -0
  219. package/native-bridge/iOS/Source/DTOs/CallOptions+Equatable.swift +12 -0
  220. package/native-bridge/iOS/Source/DTOs/CallType+Bandyer.swift +20 -0
  221. package/native-bridge/iOS/Source/DTOs/CallType+Decodable.swift +27 -0
  222. package/native-bridge/iOS/Source/DTOs/ChatToolConfiguration+Decodable.swift +18 -0
  223. package/native-bridge/iOS/Source/DTOs/CreateCallOptions+Decodable.swift +22 -0
  224. package/native-bridge/iOS/Source/DTOs/CreateCallOptions+Equatable.swift +13 -0
  225. package/native-bridge/iOS/Source/DTOs/CreateCallOptions+Intent.swift +17 -0
  226. package/native-bridge/iOS/Source/DTOs/DTOs.swift +314 -0
  227. package/native-bridge/iOS/Source/DTOs/Environment+Bandyer.swift +20 -0
  228. package/native-bridge/iOS/Source/DTOs/Environment+Decodable.swift +16 -0
  229. package/native-bridge/iOS/Source/DTOs/IosConfiguration+Decodable.swift +18 -0
  230. package/native-bridge/iOS/Source/DTOs/JSONDecodable.swift +27 -0
  231. package/native-bridge/iOS/Source/DTOs/KaleyraVideoConfiguration+Bandyer.swift +158 -0
  232. package/native-bridge/iOS/Source/DTOs/KaleyraVideoConfiguration+Decodable.swift +28 -0
  233. package/native-bridge/iOS/Source/DTOs/KaleyraVideoConfiguration+UserInterfacePresenterConfiguration.swift +29 -0
  234. package/native-bridge/iOS/Source/DTOs/RecordingType+Bandyer.swift +33 -0
  235. package/native-bridge/iOS/Source/DTOs/RecordingType+Decodable.swift +27 -0
  236. package/native-bridge/iOS/Source/DTOs/Region+Bandyer.swift +22 -0
  237. package/native-bridge/iOS/Source/DTOs/Region+Decodable.swift +16 -0
  238. package/native-bridge/iOS/Source/DTOs/ScreenShareToolConfiguration+Decodable.swift +18 -0
  239. package/native-bridge/iOS/Source/DTOs/Tools+Decodable.swift +24 -0
  240. package/native-bridge/iOS/Source/DTOs/UserDetails+Bandyer.swift +18 -0
  241. package/native-bridge/iOS/Source/DTOs/UserDetails+Decodable.swift +28 -0
  242. package/native-bridge/iOS/Source/DTOs/UserDetailsFormat+Decodable.swift +19 -0
  243. package/native-bridge/iOS/Source/DTOs/VoipHandlingStrategy+Decodable.swift +25 -0
  244. package/native-bridge/iOS/Source/Events/Emitter/EventEmitter.swift +8 -0
  245. package/native-bridge/iOS/Source/Events/Events+CaseIterable.swift +18 -0
  246. package/native-bridge/iOS/Source/Events/Events+Description.swift +28 -0
  247. package/native-bridge/iOS/Source/Events/Events.swift +21 -0
  248. package/native-bridge/iOS/Source/Events/Reporters/CallClientEventsReporter.swift +46 -0
  249. package/native-bridge/iOS/Source/Events/Reporters/ChatClientEventsReporter.swift +46 -0
  250. package/native-bridge/iOS/Source/Events/Reporters/ClientState.swift +61 -0
  251. package/native-bridge/iOS/Source/Events/Reporters/EventsReporter.swift +69 -0
  252. package/native-bridge/iOS/Source/Events/Reporters/PushTokenEventsReporter.swift +34 -0
  253. package/native-bridge/iOS/Source/Extensions/URL+FromString.swift +26 -0
  254. package/native-bridge/iOS/Source/KaleyraVideoHybridNativeBridge.h +14 -0
  255. package/native-bridge/iOS/Source/NativeHybridBridge/VideoHybridNativeBridge.swift +173 -0
  256. package/native-bridge/iOS/Source/NativeHybridBridge/VideoHybridNativeBridgeError.swift +33 -0
  257. package/native-bridge/iOS/Source/UI/KaleyraVideoSDKUserInterfacePresenter.swift +249 -0
  258. package/native-bridge/iOS/Source/UI/Presenters/PresentingViewControllerViewControllerPresenter.swift +44 -0
  259. package/native-bridge/iOS/Source/UI/Presenters/ViewControllerPresenter.swift +17 -0
  260. package/native-bridge/iOS/Source/UI/Presenters/WindowViewControllerPresenter.swift +111 -0
  261. package/native-bridge/iOS/Source/UI/UserInterfacePresenter+MainQueueRelay.swift +30 -0
  262. package/native-bridge/iOS/Source/UI/UserInterfacePresenter.swift +14 -0
  263. package/native-bridge/iOS/Source/User Details/Cache/UsersDetailsCache.swift +36 -0
  264. package/native-bridge/iOS/Source/User Details/Formatter/FormatterProxy.swift +47 -0
  265. package/native-bridge/iOS/Source/User Details/Formatter/UserDetailsFormatter.swift +83 -0
  266. package/native-bridge/iOS/Source/User Details/Providers/UsersDetailsProvider.swift +39 -0
  267. package/package.json +147 -0
  268. package/src/KaleyraVideo.ts +343 -0
  269. package/src/ReactNativeEventEmitter.ts +51 -0
  270. package/src/events/Events.ts +46 -0
  271. package/video-react-native-module.podspec +36 -0
@@ -0,0 +1,158 @@
1
+ // Copyright © 2018-2023 Kaleyra S.p.a. All Rights Reserved.
2
+ // See LICENSE for licensing information
3
+
4
+ import Foundation
5
+ import UIKit
6
+ import Bandyer
7
+ import PushKit
8
+
9
+ @available(iOS 12.0, *)
10
+ extension KaleyraVideoConfiguration {
11
+
12
+ private enum ConfigurationError: Error {
13
+ case unsupportedEnvironment
14
+ case unsupportedRegion
15
+ }
16
+
17
+ var isCallkitEnabled: Bool {
18
+ iosConfig?.callkit?.enabled ?? true
19
+ }
20
+
21
+ var voipStrategy: VoipHandlingStrategy {
22
+ iosConfig?.voipHandlingStrategy ?? .automatic
23
+ }
24
+
25
+ func makeBandyerConfig(registryDelegate: PKPushRegistryDelegate? = nil) throws -> Bandyer.Config {
26
+ guard let bandyerEnv = environment.bandyerEnvironment else {
27
+ throw ConfigurationError.unsupportedEnvironment
28
+ }
29
+
30
+ guard let bandyerRegion = region.bandyerRegion else {
31
+ throw ConfigurationError.unsupportedRegion
32
+ }
33
+
34
+ return try ConfigBuilder(appID: appID, environment: bandyerEnv, region: bandyerRegion)
35
+ .callKit(iosConfig.makeCallkitConfigurationBuilder())
36
+ .tools(tools.makeToolsConfigurationBuilder())
37
+ .voip(iosConfig.makeVoipConfigurationBuilder(registryDelegate: registryDelegate))
38
+ .build()
39
+ }
40
+ }
41
+
42
+ @available(iOS 12.0, *)
43
+ private extension Optional where Wrapped == IosConfiguration {
44
+
45
+ func makeCallkitConfigurationBuilder() -> CallKitConfigurationBuilder {
46
+ switch self {
47
+ case .none:
48
+ let builder = CallKitConfigurationBuilder()
49
+ builder.enabled()
50
+ return builder
51
+ case .some(let wrapped):
52
+ return wrapped.makeCallkitConfigurationBuilder()
53
+ }
54
+ }
55
+
56
+ func makeVoipConfigurationBuilder(registryDelegate: PKPushRegistryDelegate?) -> VoIPPushConfigurationBuilder {
57
+ switch self {
58
+ case .none:
59
+ let builder = VoIPPushConfigurationBuilder()
60
+ builder.manual()
61
+ return builder
62
+ case .some(let wrapped):
63
+ return wrapped.makeVoipConfigurationBuilder(registryDelegate: registryDelegate)
64
+ }
65
+ }
66
+ }
67
+
68
+ @available(iOS 12.0, *)
69
+ private extension Optional where Wrapped == Tools {
70
+
71
+ func makeToolsConfigurationBuilder() -> ToolsConfigurationBuilder {
72
+ switch self {
73
+ case .none:
74
+ return ToolsConfigurationBuilder()
75
+ case .some(let wrapped):
76
+ return wrapped.makeToolsConfigurationBuilder()
77
+ }
78
+ }
79
+ }
80
+
81
+ @available(iOS 12.0, *)
82
+ private extension IosConfiguration {
83
+
84
+ func makeCallkitConfigurationBuilder() -> CallKitConfigurationBuilder {
85
+ let builder = CallKitConfigurationBuilder()
86
+
87
+ guard let callkitConfig = callkit else {
88
+ builder.enabled()
89
+ return builder
90
+ }
91
+
92
+ if callkitConfig.enabled ?? true {
93
+ builder.enabled { providerConf in
94
+ if let iconName = callkitConfig.appIconName,
95
+ let image = UIImage(named: iconName) {
96
+ providerConf.icon(image)
97
+ }
98
+ if let ringtone = callkitConfig.ringtoneSoundName {
99
+ providerConf.ringtoneSound(ringtone)
100
+ }
101
+ }
102
+ } else {
103
+ builder.disabled()
104
+ }
105
+ return builder
106
+ }
107
+
108
+ func makeVoipConfigurationBuilder(registryDelegate: PKPushRegistryDelegate?) -> VoIPPushConfigurationBuilder {
109
+ let builder = VoIPPushConfigurationBuilder()
110
+
111
+ if (voipHandlingStrategy == nil || voipHandlingStrategy == .automatic),
112
+ let delegate = registryDelegate {
113
+ builder.automatic(pushRegistryDelegate: delegate)
114
+ } else {
115
+ builder.manual()
116
+ }
117
+
118
+ return builder
119
+ }
120
+ }
121
+
122
+ @available(iOS 12.0, *)
123
+ private extension Tools {
124
+
125
+ func makeToolsConfigurationBuilder() -> ToolsConfigurationBuilder {
126
+ let builder = ToolsConfigurationBuilder()
127
+
128
+ if chat != nil {
129
+ builder.chat()
130
+ }
131
+
132
+ if fileShare != nil {
133
+ builder.fileshare()
134
+ }
135
+
136
+ if whiteboard != nil {
137
+ builder.whiteboard(uploadEnabled: true)
138
+ }
139
+
140
+ if let screenshare = screenShare {
141
+ if screenshare.inApp ?? false {
142
+ builder.inAppScreenSharing()
143
+ }
144
+
145
+ if screenshare.wholeDevice ?? false {
146
+ if let configURL = Bundle.main.url(forResource: "KaleyraVideoConfig", withExtension: "plist") {
147
+ let reader = BroadcastConfigurationPlistReader()
148
+ if let broadcastConfig = try? reader.read(fileURL: configURL) {
149
+ builder.broadcastScreenSharing(appGroupIdentifier: broadcastConfig.appGroupID,
150
+ broadcastExtensionBundleIdentifier: broadcastConfig.extensionBundleID)
151
+ }
152
+ }
153
+ }
154
+ }
155
+
156
+ return builder
157
+ }
158
+ }
@@ -0,0 +1,28 @@
1
+ // Copyright © 2018-2023 Kaleyra S.p.a. All Rights Reserved.
2
+ // See LICENSE for licensing information
3
+
4
+ import Foundation
5
+
6
+ extension KaleyraVideoConfiguration: Decodable {
7
+
8
+ private enum CodingKeys: String, CodingKey {
9
+ case appID
10
+ case environment
11
+ case region
12
+ case logEnabled
13
+ case iosConfig
14
+ case tools
15
+ }
16
+
17
+ init(from decoder: Decoder) throws {
18
+ let container = try decoder.container(keyedBy: CodingKeys.self)
19
+ self.appID = try container.decode(String.self, forKey: .appID)
20
+ self.environment = try container.decode(Environment.self, forKey: .environment)
21
+ self.region = try container.decode(Region.self, forKey: .region)
22
+ self.logEnabled = try container.decodeIfPresent(Bool.self, forKey: .logEnabled) ?? false
23
+ self.iosConfig = try container.decodeIfPresent(IosConfiguration.self, forKey: .iosConfig)
24
+ self.tools = try container.decodeIfPresent(Tools.self, forKey: .tools)
25
+ }
26
+ }
27
+
28
+ extension KaleyraVideoConfiguration: JSONDecodable {}
@@ -0,0 +1,29 @@
1
+ // Copyright © 2018-2023 Kaleyra S.p.a. All Rights Reserved.
2
+ // See LICENSE for licensing information
3
+
4
+ import Foundation
5
+
6
+ @available(iOS 12.0, *)
7
+ extension KaleyraVideoConfiguration {
8
+
9
+ func uiPresenterConfiguration() -> UserInterfacePresenterConfiguration {
10
+ .init(showsFeedbackWhenCallEnds: tools?.feedback ?? false,
11
+ chatAudioButtonConf: chatAudioButtonConf,
12
+ chatVideoButtonConf: chatVideoButtonConf)
13
+ }
14
+
15
+ private var chatAudioButtonConf: UserInterfacePresenterConfiguration.ChatAudioButtonConfiguration {
16
+ guard let audioOptions = tools?.chat?.audioCallOption else {
17
+ return .disabled
18
+ }
19
+ return .enabled(audioOptions)
20
+ }
21
+
22
+ private var chatVideoButtonConf: UserInterfacePresenterConfiguration.ChatVideoButtonConfiguration {
23
+ guard let videoOptions = tools?.chat?.videoCallOption else {
24
+ return .disabled
25
+ }
26
+ return .enabled(videoOptions)
27
+ }
28
+ }
29
+
@@ -0,0 +1,33 @@
1
+ // Copyright © 2018-2023 Kaleyra S.p.a. All Rights Reserved.
2
+ // See LICENSE for licensing information
3
+
4
+ import Foundation
5
+ import Bandyer
6
+
7
+ @available(iOS 12.0, *)
8
+ extension RecordingType {
9
+
10
+ var callRecordingType: Bandyer.CallRecordingType {
11
+ switch self {
12
+ case .automatic:
13
+ return .automatic
14
+ case .manual:
15
+ return .manual
16
+ case .none:
17
+ return .none
18
+ }
19
+ }
20
+ }
21
+
22
+ @available(iOS 12.0, *)
23
+ extension Optional where Wrapped == RecordingType {
24
+
25
+ var callRecordingType: Bandyer.CallRecordingType {
26
+ switch self {
27
+ case nil:
28
+ return .none
29
+ case .some(let wrapped):
30
+ return wrapped.callRecordingType
31
+ }
32
+ }
33
+ }
@@ -0,0 +1,27 @@
1
+ // Copyright © 2018-2023 Kaleyra S.p.a. All Rights Reserved.
2
+ // See LICENSE for licensing information
3
+
4
+ import Foundation
5
+
6
+ struct UnknownRecordingTypeError: Error {}
7
+
8
+ extension RecordingType: Decodable {
9
+
10
+ init(from decoder: Decoder) throws {
11
+ let container = try decoder.singleValueContainer()
12
+ try self.init(try container.decode(String.self))
13
+ }
14
+
15
+ init(_ string: String) throws {
16
+ switch string {
17
+ case "none":
18
+ self = .none
19
+ case "automatic":
20
+ self = .automatic
21
+ case "manual":
22
+ self = .manual
23
+ default:
24
+ throw UnknownRecordingTypeError()
25
+ }
26
+ }
27
+ }
@@ -0,0 +1,22 @@
1
+ // Copyright © 2018-2023 Kaleyra S.p.a. All Rights Reserved.
2
+ // See LICENSE for licensing information
3
+
4
+ import Foundation
5
+ import Bandyer
6
+
7
+ @available(iOS 12.0, *)
8
+ extension Region {
9
+
10
+ var bandyerRegion: Bandyer.Region? {
11
+ switch name.lowercased() {
12
+ case "europe", "eu":
13
+ return .europe
14
+ case "india", "in":
15
+ return .india
16
+ case "us", "usa":
17
+ return .us
18
+ default:
19
+ return nil
20
+ }
21
+ }
22
+ }
@@ -0,0 +1,16 @@
1
+ // Copyright © 2018-2023 Kaleyra S.p.a. All Rights Reserved.
2
+ // See LICENSE for licensing information
3
+
4
+ import Foundation
5
+
6
+ extension Region: Decodable {
7
+
8
+ private enum CodingKeys: String, CodingKey {
9
+ case name
10
+ }
11
+
12
+ init(from decoder: Decoder) throws {
13
+ let container = try decoder.container(keyedBy: CodingKeys.self)
14
+ self.name = try container.decode(String.self, forKey: .name)
15
+ }
16
+ }
@@ -0,0 +1,18 @@
1
+ // Copyright © 2018-2023 Kaleyra S.p.a. All Rights Reserved.
2
+ // See LICENSE for licensing information
3
+
4
+ import Foundation
5
+
6
+ extension ScreenShareToolConfiguration: Decodable {
7
+
8
+ private enum CodingKeys: String, CodingKey {
9
+ case inApp
10
+ case wholeDevice
11
+ }
12
+
13
+ init(from decoder: Decoder) throws {
14
+ let container = try decoder.container(keyedBy: CodingKeys.self)
15
+ self.inApp = try container.decodeIfPresent(Bool.self, forKey: .inApp) ?? false
16
+ self.wholeDevice = try container.decodeIfPresent(Bool.self, forKey: .wholeDevice) ?? false
17
+ }
18
+ }
@@ -0,0 +1,24 @@
1
+ // Copyright © 2018-2023 Kaleyra S.p.a. All Rights Reserved.
2
+ // See LICENSE for licensing information
3
+
4
+ import Foundation
5
+
6
+ extension Tools: Decodable {
7
+
8
+ private enum CodingKeys: String, CodingKey {
9
+ case chat
10
+ case fileShare
11
+ case whiteboard
12
+ case screenShare
13
+ case feedback
14
+ }
15
+
16
+ init(from decoder: Decoder) throws {
17
+ let container = try decoder.container(keyedBy: CodingKeys.self)
18
+ self.chat = try container.decodeIfPresent(ChatToolConfiguration.self, forKey: .chat)
19
+ self.fileShare = try container.decodeIfPresent(Bool.self, forKey: .fileShare) ?? false
20
+ self.whiteboard = try container.decodeIfPresent(Bool.self, forKey: .whiteboard) ?? false
21
+ self.screenShare = try container.decodeIfPresent(ScreenShareToolConfiguration.self, forKey: .screenShare) ?? .init(inApp: false, wholeDevice: false)
22
+ self.feedback = try container.decodeIfPresent(Bool.self, forKey: .feedback) ?? false
23
+ }
24
+ }
@@ -0,0 +1,18 @@
1
+ // Copyright © 2018-2023 Kaleyra S.p.a. All Rights Reserved.
2
+ // See LICENSE for licensing information
3
+
4
+ import Foundation
5
+ import Bandyer
6
+
7
+ @available(iOS 12.0, *)
8
+ extension UserDetails {
9
+
10
+ var bandyerDetails: Bandyer.UserDetails {
11
+ .init(userID: userID,
12
+ firstname: firstName,
13
+ lastname: lastName,
14
+ email: email,
15
+ nickname: nickName,
16
+ imageURL: URL(string: profileImageURL ?? ""))
17
+ }
18
+ }
@@ -0,0 +1,28 @@
1
+ // Copyright © 2018-2023 Kaleyra S.p.a. All Rights Reserved.
2
+ // See LICENSE for licensing information
3
+
4
+ import Foundation
5
+
6
+ extension UserDetails: Decodable {
7
+
8
+ private enum CodingKeys: String, CodingKey {
9
+ case userID
10
+ case firstName
11
+ case lastName
12
+ case email
13
+ case nickName
14
+ case profileImageURL
15
+ }
16
+
17
+ init(from decoder: Decoder) throws {
18
+ let container = try decoder.container(keyedBy: CodingKeys.self)
19
+ self.userID = try container.decode(String.self, forKey: .userID)
20
+ self.firstName = try container.decodeIfPresent(String.self, forKey: .firstName)
21
+ self.lastName = try container.decodeIfPresent(String.self, forKey: .lastName)
22
+ self.email = try container.decodeIfPresent(String.self, forKey: .email)
23
+ self.nickName = try container.decodeIfPresent(String.self, forKey: .nickName)
24
+ self.profileImageURL = try container.decodeIfPresent(String.self, forKey: .profileImageURL)
25
+ }
26
+ }
27
+
28
+ extension UserDetails: JSONDecodable {}
@@ -0,0 +1,19 @@
1
+ // Copyright © 2018-2023 Kaleyra S.p.a. All Rights Reserved.
2
+ // See LICENSE for licensing information
3
+
4
+ import Foundation
5
+
6
+ extension UserDetailsFormat: Decodable {
7
+
8
+ private enum CodingKeys: String, CodingKey {
9
+ case `default`
10
+ }
11
+
12
+ init(from decoder: Decoder) throws {
13
+ let container = try decoder.container(keyedBy: CodingKeys.self)
14
+ self.userDetailsFormatDefault = try container.decode(String.self, forKey: .default)
15
+ self.androidNotification = nil
16
+ }
17
+ }
18
+
19
+ extension UserDetailsFormat: JSONDecodable {}
@@ -0,0 +1,25 @@
1
+ // Copyright © 2018-2023 Kaleyra S.p.a. All Rights Reserved.
2
+ // See LICENSE for licensing information
3
+
4
+ import Foundation
5
+
6
+ struct UnknownVoipHandlingStrategyError: Error {}
7
+
8
+ extension VoipHandlingStrategy: Decodable {
9
+
10
+ init(from decoder: Decoder) throws {
11
+ let container = try decoder.singleValueContainer()
12
+ try self.init(try container.decode(String.self))
13
+ }
14
+
15
+ init(_ string: String) throws {
16
+ switch string {
17
+ case "automatic":
18
+ self = .automatic
19
+ case "disabled":
20
+ self = .disabled
21
+ default:
22
+ throw UnknownVoipHandlingStrategyError()
23
+ }
24
+ }
25
+ }
@@ -0,0 +1,8 @@
1
+ // Copyright © 2018-2023 Kaleyra S.p.a. All Rights Reserved.
2
+ // See LICENSE for licensing information
3
+
4
+ import Foundation
5
+
6
+ protocol EventEmitter {
7
+ func sendEvent(_ event: Events, args: Any?)
8
+ }
@@ -0,0 +1,18 @@
1
+ // Copyright © 2018-2023 Kaleyra S.p.a. All Rights Reserved.
2
+ // See LICENSE for licensing information
3
+
4
+ import Foundation
5
+
6
+ extension Events: CaseIterable {
7
+
8
+ static var allCases: [Events] {
9
+ [.accessTokenRequest,
10
+ .callError,
11
+ .callModuleStatusChanged,
12
+ .chatError,
13
+ .chatModuleStatusChanged,
14
+ .iOSVoipPushTokenInvalidated,
15
+ .iOSVoipPushTokenUpdated,
16
+ .setupError]
17
+ }
18
+ }
@@ -0,0 +1,28 @@
1
+ // Copyright © 2018-2023 Kaleyra S.p.a. All Rights Reserved.
2
+ // See LICENSE for licensing information
3
+
4
+ import Foundation
5
+
6
+ extension Events: CustomStringConvertible {
7
+
8
+ var description: String {
9
+ switch self {
10
+ case .accessTokenRequest:
11
+ return "accessTokenRequest"
12
+ case .callError:
13
+ return "callError"
14
+ case .callModuleStatusChanged:
15
+ return "callModuleStatusChanged"
16
+ case .chatError:
17
+ return "chatError"
18
+ case .chatModuleStatusChanged:
19
+ return "chatModuleStatusChanged"
20
+ case .iOSVoipPushTokenInvalidated:
21
+ return "iOSVoipPushTokenInvalidated"
22
+ case .iOSVoipPushTokenUpdated:
23
+ return "iOSVoipPushTokenUpdated"
24
+ case .setupError:
25
+ return "setupError"
26
+ }
27
+ }
28
+ }
@@ -0,0 +1,21 @@
1
+ // This file was generated from JSON Schema using quicktype, do not modify it directly.
2
+ // To parse the JSON, add this file to your project and do:
3
+ //
4
+ // let events = try? JSONDecoder().decode(Events.self, from: jsonData)
5
+
6
+ import Foundation
7
+
8
+ /// This enum defines all the events that may be handled
9
+ /// <br/>
10
+ /// <br/>
11
+ /// You can listen to these events via [[BandyerPlugin.on]]
12
+ enum Events {
13
+ case accessTokenRequest
14
+ case callError
15
+ case callModuleStatusChanged
16
+ case chatError
17
+ case chatModuleStatusChanged
18
+ case iOSVoipPushTokenInvalidated
19
+ case iOSVoipPushTokenUpdated
20
+ case setupError
21
+ }
@@ -0,0 +1,46 @@
1
+ // Copyright © 2018-2023 Kaleyra S.p.a. All Rights Reserved.
2
+ // See LICENSE for licensing information
3
+
4
+ import Foundation
5
+ import Bandyer
6
+
7
+ @available(iOS 12.0, *)
8
+ class CallClientEventsReporter: NSObject, CallClientObserver {
9
+
10
+ private let client: CallClient
11
+ private let emitter: EventEmitter
12
+ private(set) var isRunning = false
13
+
14
+ init(client: CallClient, emitter: EventEmitter) {
15
+ self.client = client
16
+ self.emitter = emitter
17
+ super.init()
18
+ }
19
+
20
+ func start() {
21
+ guard !isRunning else { return }
22
+
23
+ isRunning = true
24
+ client.add(observer: self, queue: .main)
25
+ }
26
+
27
+ func stop() {
28
+ guard isRunning else { return }
29
+
30
+ client.remove(observer: self)
31
+ isRunning = false
32
+ }
33
+
34
+ // MARK: - Call client observer
35
+
36
+ func callClientDidChangeState(_ client: CallClient, oldState: CallClientState, newState: CallClientState) {
37
+ guard let clientState = ClientState(clientState: newState) else { return }
38
+
39
+ emitter.sendEvent(Events.callModuleStatusChanged, args: clientState.rawValue)
40
+ }
41
+
42
+ func callClient(_ client: CallClient, didFailWithError error: Error) {
43
+ emitter.sendEvent(Events.callError, args: error.localizedDescription)
44
+ emitter.sendEvent(Events.callModuleStatusChanged, args: ClientState.failed.rawValue)
45
+ }
46
+ }
@@ -0,0 +1,46 @@
1
+ // Copyright © 2018-2023 Kaleyra S.p.a. All Rights Reserved.
2
+ // See LICENSE for licensing information
3
+
4
+ import Foundation
5
+ import Bandyer
6
+
7
+ @available(iOS 12.0, *)
8
+ class ChatClientEventsReporter: NSObject, ChatClientObserver {
9
+
10
+ private let client: ChatClient
11
+ private let emitter: EventEmitter
12
+ private(set) var isRunning = false
13
+
14
+ init(client: ChatClient, emitter: EventEmitter) {
15
+ self.client = client
16
+ self.emitter = emitter
17
+ super.init()
18
+ }
19
+
20
+ func start() {
21
+ guard !isRunning else { return }
22
+
23
+ isRunning = true
24
+ client.add(observer: self, queue: .main)
25
+ }
26
+
27
+ func stop() {
28
+ guard isRunning else { return }
29
+
30
+ client.remove(observer: self)
31
+ isRunning = false
32
+ }
33
+
34
+ // MARK: - Chat client observer
35
+
36
+ func chatClientDidChangeState(_ client: ChatClient, oldState: ChatClientState, newState: ChatClientState) {
37
+ guard let clientState = ClientState(clientState: newState) else { return }
38
+
39
+ emitter.sendEvent(Events.chatModuleStatusChanged, args: clientState.rawValue)
40
+ }
41
+
42
+ func chatClient(_ client: ChatClient, didFailWithError error: Error) {
43
+ emitter.sendEvent(Events.chatError, args: error.localizedDescription)
44
+ emitter.sendEvent(Events.chatModuleStatusChanged, args: ClientState.failed.rawValue)
45
+ }
46
+ }