@shortkitsdk/react-native 0.2.22 → 0.2.24

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 (30) hide show
  1. package/android/libs/shortkit-release.aar +0 -0
  2. package/android/src/main/java/com/shortkit/reactnative/ShortKitBridge.kt +10 -7
  3. package/ios/ShortKitBridge.swift +97 -2
  4. package/ios/ShortKitModule.mm +25 -2
  5. package/ios/ShortKitSDK.xcframework/Info.plist +5 -5
  6. package/ios/ShortKitSDK.xcframework/ios-arm64/ShortKitSDK.framework/Info.plist +2 -2
  7. package/ios/ShortKitSDK.xcframework/ios-arm64/ShortKitSDK.framework/Modules/ShortKitSDK.swiftmodule/arm64-apple-ios.abi.json +4998 -2499
  8. package/ios/ShortKitSDK.xcframework/ios-arm64/ShortKitSDK.framework/Modules/ShortKitSDK.swiftmodule/arm64-apple-ios.private.swiftinterface +64 -1
  9. package/ios/ShortKitSDK.xcframework/ios-arm64/ShortKitSDK.framework/Modules/ShortKitSDK.swiftmodule/arm64-apple-ios.swiftdoc +0 -0
  10. package/ios/ShortKitSDK.xcframework/ios-arm64/ShortKitSDK.framework/Modules/ShortKitSDK.swiftmodule/arm64-apple-ios.swiftinterface +64 -1
  11. package/ios/ShortKitSDK.xcframework/ios-arm64/ShortKitSDK.framework/ShortKitSDK +0 -0
  12. package/ios/ShortKitSDK.xcframework/ios-arm64/ShortKitSDK.framework/_CodeSignature/CodeResources +9 -9
  13. package/ios/ShortKitSDK.xcframework/ios-arm64_x86_64-simulator/ShortKitSDK.framework/Info.plist +2 -2
  14. package/ios/ShortKitSDK.xcframework/ios-arm64_x86_64-simulator/ShortKitSDK.framework/Modules/ShortKitSDK.swiftmodule/arm64-apple-ios-simulator.abi.json +4998 -2499
  15. package/ios/ShortKitSDK.xcframework/ios-arm64_x86_64-simulator/ShortKitSDK.framework/Modules/ShortKitSDK.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +64 -1
  16. package/ios/ShortKitSDK.xcframework/ios-arm64_x86_64-simulator/ShortKitSDK.framework/Modules/ShortKitSDK.swiftmodule/arm64-apple-ios-simulator.swiftdoc +0 -0
  17. package/ios/ShortKitSDK.xcframework/ios-arm64_x86_64-simulator/ShortKitSDK.framework/Modules/ShortKitSDK.swiftmodule/arm64-apple-ios-simulator.swiftinterface +64 -1
  18. package/ios/ShortKitSDK.xcframework/ios-arm64_x86_64-simulator/ShortKitSDK.framework/Modules/ShortKitSDK.swiftmodule/x86_64-apple-ios-simulator.abi.json +4998 -2499
  19. package/ios/ShortKitSDK.xcframework/ios-arm64_x86_64-simulator/ShortKitSDK.framework/Modules/ShortKitSDK.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface +64 -1
  20. package/ios/ShortKitSDK.xcframework/ios-arm64_x86_64-simulator/ShortKitSDK.framework/Modules/ShortKitSDK.swiftmodule/x86_64-apple-ios-simulator.swiftdoc +0 -0
  21. package/ios/ShortKitSDK.xcframework/ios-arm64_x86_64-simulator/ShortKitSDK.framework/Modules/ShortKitSDK.swiftmodule/x86_64-apple-ios-simulator.swiftinterface +64 -1
  22. package/ios/ShortKitSDK.xcframework/ios-arm64_x86_64-simulator/ShortKitSDK.framework/ShortKitSDK +0 -0
  23. package/ios/ShortKitSDK.xcframework/ios-arm64_x86_64-simulator/ShortKitSDK.framework/_CodeSignature/CodeResources +17 -17
  24. package/package.json +1 -1
  25. package/src/ShortKitCommands.ts +3 -0
  26. package/src/ShortKitContext.ts +6 -0
  27. package/src/ShortKitProvider.tsx +45 -1
  28. package/src/index.ts +2 -0
  29. package/src/specs/NativeShortKitModule.ts +29 -0
  30. package/src/types.ts +44 -1
Binary file
@@ -17,7 +17,8 @@ import com.shortkit.sdk.model.FeedInput
17
17
  import com.shortkit.sdk.model.FeedScrollPhase
18
18
  import com.shortkit.sdk.model.FeedTransitionPhase
19
19
  import com.shortkit.sdk.model.ImageCarouselItem
20
- import com.shortkit.sdk.model.VideoCarouselItem
20
+ import com.shortkit.sdk.model.VideoCarouselInput
21
+ import com.shortkit.sdk.model.VideoCarouselVideoInput
21
22
  import com.shortkit.sdk.model.JsonValue
22
23
  import com.shortkit.sdk.model.PlayerState
23
24
  import com.shortkit.sdk.config.SurveyOverlayMode
@@ -366,22 +367,24 @@ class ShortKitBridge(
366
367
  "videoCarousel" -> {
367
368
  val itemObj = obj.optJSONObject("item") ?: continue
368
369
  val videosArr = itemObj.optJSONArray("videos") ?: continue
369
- val videos = mutableListOf<ContentItem>()
370
+ val videoInputs = mutableListOf<VideoCarouselVideoInput>()
370
371
  for (i in 0 until videosArr.length()) {
371
372
  val videoObj = videosArr.getJSONObject(i)
372
- parseContentItem(videoObj)?.let { videos.add(it) }
373
+ val playbackId = videoObj.optString("playbackId", null) ?: continue
374
+ val fallbackUrl = videoObj.optString("fallbackUrl", null)
375
+ videoInputs.add(VideoCarouselVideoInput(playbackId, fallbackUrl))
373
376
  }
374
- if (videos.isEmpty()) continue
375
- val carouselItem = VideoCarouselItem(
377
+ if (videoInputs.isEmpty()) continue
378
+ val carouselInput = VideoCarouselInput(
376
379
  id = itemObj.getString("id"),
377
- videos = videos,
380
+ videos = videoInputs,
378
381
  title = itemObj.optString("title", null),
379
382
  description = itemObj.optString("description", null),
380
383
  author = itemObj.optString("author", null),
381
384
  section = itemObj.optString("section", null),
382
385
  articleUrl = itemObj.optString("articleUrl", null),
383
386
  )
384
- result.add(FeedInput.VideoCarousel(carouselItem))
387
+ result.add(FeedInput.VideoCarousel(carouselInput))
385
388
  }
386
389
  }
387
390
  }
@@ -18,6 +18,8 @@ import ShortKitSDK
18
18
  private var cancellables = Set<AnyCancellable>()
19
19
  private weak var delegate: ShortKitBridgeDelegateProtocol?
20
20
  private var lastProgressEmitTime: CFTimeInterval = 0
21
+ private var lastDownloadProgressEmitTime: TimeInterval = 0
22
+ private var itemCache: [String: ContentItem] = [:]
21
23
 
22
24
  // Time update coalescing (250ms, matching overlay timer interval)
23
25
  private var cachedTime: (current: Double, duration: Double, buffered: Double) = (0, 0, 0)
@@ -129,6 +131,7 @@ import ShortKitSDK
129
131
  subscribeToPublishers(sdk.player)
130
132
  startTimeCoalescing()
131
133
  sdk.delegate = self
134
+ sdk.downloadDelegate = self
132
135
  }
133
136
 
134
137
  // MARK: - Teardown
@@ -140,6 +143,7 @@ import ShortKitSDK
140
143
  preloadHandles.removeAll()
141
144
  feedRegistry.removeAll()
142
145
  pendingOps.removeAll()
146
+ itemCache.removeAll()
143
147
  shortKit = nil
144
148
  if ShortKitBridge.shared === self {
145
149
  ShortKitBridge.shared = nil
@@ -396,6 +400,7 @@ import ShortKitSDK
396
400
  .receive(on: DispatchQueue.main)
397
401
  .sink { [weak self] item in
398
402
  guard let item else { return }
403
+ self?.itemCache[item.id] = item
399
404
  let body = Self.contentItemDict(item)
400
405
  DispatchQueue.main.async {
401
406
  self?.emit("onCurrentItemChanged", body: body)
@@ -637,6 +642,9 @@ import ShortKitSDK
637
642
  if let fallbackUrl = item.fallbackUrl {
638
643
  dict["fallbackUrl"] = fallbackUrl
639
644
  }
645
+ if let downloadUrl = item.downloadUrl {
646
+ dict["downloadUrl"] = downloadUrl
647
+ }
640
648
 
641
649
  return dict
642
650
  }
@@ -885,10 +893,10 @@ import ShortKitSDK
885
893
  case "videoCarousel":
886
894
  guard let itemData = obj["item"] as? [String: Any],
887
895
  let itemJSON = try? JSONSerialization.data(withJSONObject: itemData),
888
- let carouselItem = try? JSONDecoder().decode(VideoCarouselItem.self, from: itemJSON) else {
896
+ let carouselInput = try? JSONDecoder().decode(VideoCarouselInput.self, from: itemJSON) else {
889
897
  continue
890
898
  }
891
- result.append(.videoCarousel(carouselItem))
899
+ result.append(.videoCarousel(carouselInput))
892
900
  default:
893
901
  continue
894
902
  }
@@ -937,6 +945,11 @@ extension ShortKitBridge: ShortKitDelegate {
937
945
  }
938
946
 
939
947
  public func shortKit(_ shortKit: ShortKit, didFetchContentItems items: [ContentItem]) {
948
+ DispatchQueue.main.async {
949
+ for item in items {
950
+ self.itemCache[item.id] = item
951
+ }
952
+ }
940
953
  Task {
941
954
  let data = try? JSONEncoder().encode(items)
942
955
  let json = data.flatMap { String(data: $0, encoding: .utf8) } ?? "[]"
@@ -953,3 +966,85 @@ extension ShortKitBridge {
953
966
  }
954
967
  }
955
968
 
969
+ // MARK: - ShortKitDownloadDelegate
970
+
971
+ extension ShortKitBridge: ShortKitDownloadDelegate {
972
+ public func shortKit(_ shortKit: ShortKit, didStartDownload item: ContentItem) {
973
+ emitOnMain("onDownloadStarted", body: ["itemId": item.id])
974
+ }
975
+
976
+ public func shortKit(_ shortKit: ShortKit, didUpdateDownloadProgress item: ContentItem, progress: Double) {
977
+ let now = CACurrentMediaTime()
978
+ guard now - lastDownloadProgressEmitTime >= 0.1 else { return }
979
+ lastDownloadProgressEmitTime = now
980
+ emitOnMain("onDownloadProgress", body: [
981
+ "itemId": item.id,
982
+ "progress": progress,
983
+ ])
984
+ }
985
+
986
+ public func shortKit(_ shortKit: ShortKit, didCompleteDownload item: ContentItem, fileURL: URL) {
987
+ emitOnMain("onDownloadCompleted", body: [
988
+ "itemId": item.id,
989
+ "fileUrl": fileURL.absoluteString,
990
+ ])
991
+ }
992
+
993
+ public func shortKit(_ shortKit: ShortKit, didFailDownload item: ContentItem, error: ShortKitDownloadError) {
994
+ let message: String
995
+ switch error {
996
+ case .downloadNotAvailable:
997
+ message = "Download not available"
998
+ case .downloadInProgress:
999
+ message = "Download already in progress"
1000
+ case .networkError(let underlying):
1001
+ message = "Network error: \(underlying.localizedDescription)"
1002
+ case .httpError(let statusCode):
1003
+ message = "HTTP error: \(statusCode)"
1004
+ case .cancelled:
1005
+ message = "Download cancelled"
1006
+ }
1007
+ emitOnMain("onDownloadFailed", body: [
1008
+ "itemId": item.id,
1009
+ "error": message,
1010
+ ])
1011
+ }
1012
+ }
1013
+
1014
+ // MARK: - Downloads
1015
+
1016
+ extension ShortKitBridge {
1017
+ @objc public func downloadVideo(_ itemId: String, mode: String, completion: @escaping (String?, NSError?) -> Void) {
1018
+ DispatchQueue.main.async {
1019
+ guard let shortKit = self.shortKit else {
1020
+ completion(nil, NSError(domain: "ShortKitBridge", code: 1, userInfo: [
1021
+ NSLocalizedDescriptionKey: "ShortKit not initialized"
1022
+ ]))
1023
+ return
1024
+ }
1025
+
1026
+ guard let item = self.itemCache[itemId] else {
1027
+ completion(nil, NSError(domain: "ShortKitBridge", code: 2, userInfo: [
1028
+ NSLocalizedDescriptionKey: "Content item not found: \(itemId)"
1029
+ ]))
1030
+ return
1031
+ }
1032
+
1033
+ let downloadMode: DownloadMode = mode == "interruptive" ? .interruptive : .nonInterruptive
1034
+
1035
+ Task {
1036
+ do {
1037
+ let fileURL = try await shortKit.downloadVideo(item, mode: downloadMode)
1038
+ completion(fileURL.absoluteString, nil)
1039
+ } catch {
1040
+ completion(nil, error as NSError)
1041
+ }
1042
+ }
1043
+ }
1044
+ }
1045
+
1046
+ @objc public func cancelDownload() {
1047
+ shortKit?.cancelDownload()
1048
+ }
1049
+ }
1050
+
@@ -84,6 +84,10 @@ RCT_EXPORT_MODULE(ShortKitModule)
84
84
  @"onOverlayFullState",
85
85
  @"onCarouselActiveImageChanged",
86
86
  @"onVideoCarouselActiveVideoChanged",
87
+ @"onDownloadStarted",
88
+ @"onDownloadProgress",
89
+ @"onDownloadCompleted",
90
+ @"onDownloadFailed",
87
91
  ];
88
92
  }
89
93
 
@@ -124,7 +128,7 @@ RCT_EXPORT_METHOD(initialize:(NSString *)apiKey
124
128
  clientAppName:(NSString *)clientAppName
125
129
  clientAppVersion:(NSString *)clientAppVersion
126
130
  customDimensions:(NSString *)customDimensions
127
- debugPanel:(BOOL)debugPanel) {
131
+ debugPanel:(NSNumber *)debugPanel) {
128
132
  // Tear down any existing instance to prevent leaks on re-initialize
129
133
  [_shortKitBridge teardown];
130
134
 
@@ -133,7 +137,7 @@ RCT_EXPORT_METHOD(initialize:(NSString *)apiKey
133
137
  clientAppName:clientAppName
134
138
  clientAppVersion:clientAppVersion
135
139
  customDimensions:customDimensions
136
- debugPanel:debugPanel
140
+ debugPanel:[debugPanel boolValue]
137
141
  delegate:self
138
142
  surfacePresenter:_surfacePresenter];
139
143
 
@@ -297,6 +301,25 @@ RCT_EXPORT_METHOD(getStoryboardData:(NSString *)playbackId
297
301
  }];
298
302
  }
299
303
 
304
+ // MARK: - Download Management
305
+
306
+ RCT_EXPORT_METHOD(downloadVideo:(NSString *)itemId
307
+ mode:(NSString *)mode
308
+ resolve:(RCTPromiseResolveBlock)resolve
309
+ reject:(RCTPromiseRejectBlock)reject) {
310
+ [_shortKitBridge downloadVideo:itemId mode:mode completion:^(NSString *fileUrl, NSError *error) {
311
+ if (error) {
312
+ reject(@"DOWNLOAD_ERROR", error.localizedDescription, error);
313
+ } else {
314
+ resolve(fileUrl);
315
+ }
316
+ }];
317
+ }
318
+
319
+ RCT_EXPORT_METHOD(cancelDownload) {
320
+ [_shortKitBridge cancelDownload];
321
+ }
322
+
300
323
  // MARK: - New Architecture (TurboModule)
301
324
 
302
325
  #ifdef RCT_NEW_ARCH_ENABLED
@@ -8,32 +8,32 @@
8
8
  <key>BinaryPath</key>
9
9
  <string>ShortKitSDK.framework/ShortKitSDK</string>
10
10
  <key>LibraryIdentifier</key>
11
- <string>ios-arm64</string>
11
+ <string>ios-arm64_x86_64-simulator</string>
12
12
  <key>LibraryPath</key>
13
13
  <string>ShortKitSDK.framework</string>
14
14
  <key>SupportedArchitectures</key>
15
15
  <array>
16
16
  <string>arm64</string>
17
+ <string>x86_64</string>
17
18
  </array>
18
19
  <key>SupportedPlatform</key>
19
20
  <string>ios</string>
21
+ <key>SupportedPlatformVariant</key>
22
+ <string>simulator</string>
20
23
  </dict>
21
24
  <dict>
22
25
  <key>BinaryPath</key>
23
26
  <string>ShortKitSDK.framework/ShortKitSDK</string>
24
27
  <key>LibraryIdentifier</key>
25
- <string>ios-arm64_x86_64-simulator</string>
28
+ <string>ios-arm64</string>
26
29
  <key>LibraryPath</key>
27
30
  <string>ShortKitSDK.framework</string>
28
31
  <key>SupportedArchitectures</key>
29
32
  <array>
30
33
  <string>arm64</string>
31
- <string>x86_64</string>
32
34
  </array>
33
35
  <key>SupportedPlatform</key>
34
36
  <string>ios</string>
35
- <key>SupportedPlatformVariant</key>
36
- <string>simulator</string>
37
37
  </dict>
38
38
  </array>
39
39
  <key>CFBundlePackageType</key>
@@ -11,9 +11,9 @@
11
11
  <key>CFBundlePackageType</key>
12
12
  <string>FMWK</string>
13
13
  <key>CFBundleVersion</key>
14
- <string>0.2.22</string>
14
+ <string>0.2.24</string>
15
15
  <key>CFBundleShortVersionString</key>
16
- <string>0.2.22</string>
16
+ <string>0.2.24</string>
17
17
  <key>MinimumOSVersion</key>
18
18
  <string>16.0</string>
19
19
  </dict>