vdocipher-rn-bridge 1.16.0 → 1.17.1

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 (43) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/VdoPlayerUIView.tsx +10 -10
  3. package/VdoPlayerView.tsx +170 -70
  4. package/android/build.gradle +3 -3
  5. package/android/src/main/java/com/vdocipher/rnbridge/ReactVdoPlayerUIView.java +13 -7
  6. package/android/src/main/java/com/vdocipher/rnbridge/VdoDownloadModule.java +67 -0
  7. package/downloadMonitor.ts +2 -2
  8. package/downloads.ts +41 -1
  9. package/index.ts +4 -1
  10. package/ios/Podfile +10 -0
  11. package/ios/Podfile.lock +3 -0
  12. package/ios/Pods/Manifest.lock +3 -0
  13. package/ios/Pods/Pods.xcodeproj/project.pbxproj +397 -0
  14. package/ios/Pods/Pods.xcodeproj/xcuserdata/mansisharma.xcuserdatad/xcschemes/Pods-VdocipherRnBridge.xcscheme +58 -0
  15. package/ios/Pods/Pods.xcodeproj/xcuserdata/mansisharma.xcuserdatad/xcschemes/xcschememanagement.plist +16 -0
  16. package/ios/Pods/Target Support Files/Pods-VdocipherRnBridge/Pods-VdocipherRnBridge-Info.plist +26 -0
  17. package/ios/Pods/Target Support Files/Pods-VdocipherRnBridge/Pods-VdocipherRnBridge-acknowledgements.markdown +3 -0
  18. package/ios/Pods/Target Support Files/Pods-VdocipherRnBridge/Pods-VdocipherRnBridge-acknowledgements.plist +29 -0
  19. package/ios/Pods/Target Support Files/Pods-VdocipherRnBridge/Pods-VdocipherRnBridge-dummy.m +5 -0
  20. package/ios/Pods/Target Support Files/Pods-VdocipherRnBridge/Pods-VdocipherRnBridge-umbrella.h +16 -0
  21. package/ios/Pods/Target Support Files/Pods-VdocipherRnBridge/Pods-VdocipherRnBridge.debug.xcconfig +8 -0
  22. package/ios/Pods/Target Support Files/Pods-VdocipherRnBridge/Pods-VdocipherRnBridge.modulemap +6 -0
  23. package/ios/Pods/Target Support Files/Pods-VdocipherRnBridge/Pods-VdocipherRnBridge.release.xcconfig +8 -0
  24. package/ios/RCTVdoPlayerUIView.h +19 -0
  25. package/ios/RCTVdoPlayerUIView.swift +36 -0
  26. package/ios/RCTVdoPlayerView.h +18 -0
  27. package/ios/RCTVdoPlayerView.swift +47 -0
  28. package/ios/TrackSelection.swift +64 -0
  29. package/ios/VdoCipherRNView.h +18 -0
  30. package/ios/VdoCipherRNView.swift +391 -0
  31. package/ios/VdoDownload.swift +453 -0
  32. package/ios/VdoEventEmitter.swift +157 -0
  33. package/ios/VdoPlaybackProperties.h +19 -0
  34. package/ios/VdoPlaybackProperties.swift +21 -0
  35. package/ios/VdocipherRnBridge.h +2 -10
  36. package/ios/VdocipherRnBridgeViewManager.m +106 -0
  37. package/ios/VdocipherRnBridgeViewManager.swift +90 -0
  38. package/package.json +3 -2
  39. package/react-native-vdocipher-rn-bridge.podspec +36 -0
  40. package/type.ts +23 -0
  41. package/ios/VdocipherRnBridge.m +0 -13
  42. package/ios/VdocipherRnBridge.xcodeproj/project.pbxproj +0 -259
  43. package/ios/VdocipherRnBridge.xcworkspace/contents.xcworkspacedata +0 -9
@@ -0,0 +1,453 @@
1
+ //
2
+ // VdoDownload.swift
3
+ // react-native-vdocipher-rn-bridge
4
+ //
5
+ // Created by Manish Gupta on 05/06/23.
6
+ //
7
+
8
+ import Foundation
9
+ import React
10
+
11
+ class DownloadEventEmitter {
12
+
13
+ /// Shared Instance.
14
+ public static var sharedInstance = DownloadEventEmitter()
15
+
16
+ // ReactNativeEventEmitter is instantiated by React Native with the bridge.
17
+ private static var eventEmitter: VdoDownload!
18
+
19
+ private init() {}
20
+
21
+ // When React Native instantiates the emitter it is registered here.
22
+ func registerEventEmitter(eventEmitter: VdoDownload) {
23
+ DownloadEventEmitter.eventEmitter = eventEmitter
24
+ }
25
+
26
+ func dispatch(name: DownloadEventName, params: [String: Any]?) {
27
+ if DownloadEventEmitter.eventEmitter.hasListener == true {
28
+ DownloadEventEmitter.eventEmitter.sendEvent(withName: name.rawValue, body: params)
29
+ }
30
+ }
31
+
32
+ /// All Events which must be support by React Native.
33
+ lazy var allEvents: [String] = {
34
+
35
+ return DownloadEventName.allCases.map { $0.rawValue }
36
+ }()
37
+ }
38
+
39
+
40
+ enum DownloadEventName: String, CaseIterable {
41
+ case EVENT_QUEUED = "onQueued"
42
+ case EVENT_CHANGED = "onChanged"
43
+ case EVENT_COMPLETED = "onCompleted"
44
+ case EVENT_FAILED = "onFailed"
45
+ case EVENT_DELETED = "onDeleted"
46
+ }
47
+
48
+ //enum DownloadStatusKeys: String {
49
+ // case EVENT_PROP_DOWNLOAD_STATUS_MEDIA_INFO = "mediaInfo"
50
+ // case EVENT_PROP_DOWNLOAD_STATUS_LOCAL_STORAGE_FOLDER = "localStorageFolder"
51
+ // case EVENT_PROP_DOWNLOAD_STATUS_STATUS = "status"
52
+ // case EVENT_PROP_DOWNLOAD_STATUS_REASON = "reason"
53
+ // case EVENT_PROP_DOWNLOAD_STATUS_REASON_DESCRIPTION = "reasonDescription"
54
+ // case EVENT_PROP_DOWNLOAD_STATUS_TOTAL_SIZE_BYTES = "totalSizeBytes"
55
+ // case EVENT_PROP_DOWNLOAD_STATUS_BYTES_DOWNLOADED = "bytesDownloaded"
56
+ // case EVENT_PROP_DOWNLOAD_STATUS_DOWNLOAD_PERCENT = "downloadPercent"
57
+ // case EVENT_PROP_DOWNLOAD_STATUS_POSTER = "poster"
58
+ // case EVENT_PROP_DOWNLOAD_STATUS_LAST_MODIFIED_TIMESTAMP = "lastModifiedTimestamp"
59
+ //}
60
+
61
+ @objc(VdoDownload)
62
+ class VdoDownload: RCTEventEmitter {
63
+
64
+ var asset: VdoAsset?
65
+ var availableTracksMap: [[String: Any]]?
66
+ var optionParams: [String: Any]?
67
+
68
+ // MARK: RCTEventEmitter functions
69
+ override init() {
70
+ super.init()
71
+ DownloadEventEmitter.sharedInstance.registerEventEmitter(eventEmitter: self)
72
+ self.addDownloadObservers()
73
+ VdoCipher.logLevel = .info
74
+ }
75
+
76
+ deinit {
77
+ self.removeObservers()
78
+ }
79
+
80
+ var hasListener: Bool?
81
+
82
+ /// Base overide for RCTEventEmitter.
83
+ ///
84
+ /// - Returns: all supported events
85
+ @objc open override func supportedEvents() -> [String] {
86
+ return DownloadEventEmitter.sharedInstance.allEvents
87
+ }
88
+
89
+ @objc open override func startObserving() {
90
+ super.startObserving()
91
+ hasListener = true
92
+ }
93
+
94
+ @objc open override func stopObserving() {
95
+ super.stopObserving()
96
+ hasListener = false
97
+ }
98
+
99
+ open override class func requiresMainQueueSetup() -> Bool {
100
+ return true
101
+ }
102
+
103
+ open override func addListener(_ eventName: String!) {
104
+ super.addListener(eventName)
105
+ }
106
+
107
+ open override func removeListeners(_ count: Double) {
108
+ super.removeListeners(count)
109
+ }
110
+
111
+ open override func invalidate() {
112
+ super.invalidate()
113
+ }
114
+
115
+ // MARK: Download functionality
116
+ @objc func query(_ queryFilters: [String: Any], errorCallback: RCTResponseSenderBlock, successCallback: RCTResponseSenderBlock) {
117
+ let mediaIdsRaw = queryFilters["mediaId"] as? [String]
118
+ let statusNames = queryFilters["status"] as? [String]
119
+ var mediaIds : [String] = []
120
+ if let mediaIdsRaw = mediaIdsRaw {
121
+ mediaIds = mediaIdsRaw
122
+ }
123
+
124
+ let downloadStates: [VdoAsset.DownloadState] = getDownloadStateList(downloadStatesRaw: statusNames)
125
+
126
+ let downloadFilter : DownloadInfoFilter
127
+ if downloadStates.count != 0 {
128
+ downloadFilter = DownloadInfoFilter (videoId: mediaIds.count != 0 ? mediaIds : nil, downloadState: downloadStates)
129
+ }
130
+ else{
131
+ downloadFilter = DownloadInfoFilter (videoId: mediaIds.count != 0 ? mediaIds : nil)
132
+ }
133
+ let downloadedAssests = VdoCipher.getListOfDownloads(filterBy: downloadFilter).map { self.createOfflineVdoAssetMap(with: $0) }
134
+ successCallback([downloadedAssests])
135
+ }
136
+
137
+ private func getDownloadStateList(downloadStatesRaw : [String]?) -> [VdoAsset.DownloadState]{
138
+ var downloadStates : [VdoAsset.DownloadState] = []
139
+ if let downloadStatesRaw = downloadStatesRaw {
140
+ for downloadState in downloadStatesRaw {
141
+ switch(downloadState){
142
+ case "completed":
143
+ downloadStates.append(.downloaded)
144
+ break;
145
+ case "pending":
146
+ downloadStates.append(.notDownloaded)
147
+ break;
148
+ case "paused":
149
+ downloadStates.append(.paused)
150
+ break;
151
+ case "downloading":
152
+ downloadStates.append(.downloading)
153
+ break;
154
+ default:
155
+ break;
156
+ }
157
+ }
158
+ }
159
+ return downloadStates
160
+ }
161
+
162
+ @objc func getDownloadOptions(_ optionParams: [String: Any], errorCallback: @escaping RCTResponseSenderBlock, successCallback: @escaping RCTResponseSenderBlock) {
163
+ guard let playbackInfo = optionParams["playbackInfo"] as? String,
164
+ let decoded = Data(base64Encoded: playbackInfo),
165
+ let parsed = try? JSONDecoder().decode(PlaybackInfo.self, from: decoded),
166
+ let _ = optionParams["otp"] as? String else {
167
+ errorCallback([[Error_Keys.EVENT_PROP_ERROR_CODE.rawValue: "-1",
168
+ Error_Keys.EVENT_PROP_ERROR_MSG.rawValue: "PlaybackInfo or OTP not found"]])
169
+
170
+ return
171
+ }
172
+ VdoAsset.createAsset(videoId: parsed.videoId, onLoad: { asset, err in
173
+ guard let asset = asset else {
174
+ if let error = err {
175
+ errorCallback([[Error_Keys.EVENT_PROP_ERROR_CODE.rawValue: error.code,
176
+ Error_Keys.EVENT_PROP_ERROR_MSG.rawValue: error.message] as [String : Any]])
177
+ } else {
178
+ errorCallback([[Error_Keys.EVENT_PROP_ERROR_CODE.rawValue: "-1",
179
+ Error_Keys.EVENT_PROP_ERROR_MSG.rawValue: "Unknown error occured"]])
180
+ }
181
+ return
182
+ }
183
+ let qualities = asset.getVideoQualities()
184
+ if qualities.count == 0 {
185
+ errorCallback([[Error_Keys.EVENT_PROP_ERROR_CODE.rawValue: "-1",
186
+ Error_Keys.EVENT_PROP_ERROR_MSG.rawValue: "Tracks Not Found"]])
187
+ return
188
+ }
189
+ let availableTracks = self.createTracksMap(with: qualities)
190
+ self.availableTracksMap = availableTracks
191
+ self.asset = asset
192
+ self.optionParams = optionParams
193
+ let mediaInfo = self.createMediaInfoMap(with: asset)
194
+ let downloadOptions = self.createDownloadOptionsMap(with: availableTracks, mediaInfo: mediaInfo)
195
+ let downloadOptionsMap = [playbackInfo, downloadOptions] as [Any]
196
+ successCallback(downloadOptionsMap)
197
+ })
198
+ }
199
+
200
+ @objc func enqueueDownload(_ nativeId: String, requestOptions: [String: Any], errorCallback: @escaping RCTResponseSenderBlock, successCallback: @escaping RCTResponseSenderBlock) {
201
+ guard let optionParams = optionParams, let otp = optionParams["otp"] as? String, let playbackInfo = optionParams["playbackInfo"] as? String else {
202
+ errorCallback([[Error_Keys.EVENT_PROP_ERROR_CODE.rawValue: "-1",
203
+ Error_Keys.EVENT_PROP_ERROR_MSG.rawValue: "PlaybackInfo or OTP not found"]])
204
+ return
205
+ }
206
+ if nativeId != playbackInfo {
207
+ // This is to overcome a condition if last 'getDownloadOptions' api was called for a different mediaId. Since, otp is passed with 'getDownloadOptions' and not with 'enqueue' we need to rely on 'getDownloadOptions'. Also, ReactNative apis are designed in a way that 'enqueue' func is returned on calling 'getDownloadOptions' but 'enqueue' cannot be called indvidually.
208
+ errorCallback([[Error_Keys.EVENT_PROP_ERROR_CODE.rawValue: "-1",
209
+ Error_Keys.EVENT_PROP_ERROR_MSG.rawValue: "Call getDownloadOptions before calling enqueue"]])
210
+ return
211
+ }
212
+ guard let asset = asset else {
213
+ errorCallback([[Error_Keys.EVENT_PROP_ERROR_CODE.rawValue: "-1",
214
+ Error_Keys.EVENT_PROP_ERROR_MSG.rawValue: "Unknown error occured"]])
215
+ return
216
+ }
217
+ if let selections = requestOptions["selections"] as? [Int],
218
+ let index = selections.first,
219
+ asset.getVideoQualities().count > index {
220
+ // assuming index from 'availableTracksMap' is equivalent to index of 'asset.getVideoQualities()' as both are ordered pairs
221
+ asset.startDownload(otp: otp, playbackInfo: playbackInfo, videoQuality: asset.getVideoQualities()[index])
222
+ asset.percentDownload = 0
223
+ successCallback([])
224
+ } else {
225
+ errorCallback([[Error_Keys.EVENT_PROP_ERROR_CODE.rawValue: "-1",
226
+ Error_Keys.EVENT_PROP_ERROR_MSG.rawValue: "Invalid selection"]])
227
+ }
228
+ }
229
+
230
+ @objc func stop(_ mediaIds: [String], errorCallback: @escaping RCTResponseSenderBlock, successCallback: @escaping RCTResponseSenderBlock) {
231
+ for mediaId in mediaIds {
232
+ VdoAsset.createAsset(videoId: mediaId) { asset, error in
233
+ if let asset = asset {
234
+ asset.pauseDownload()
235
+ }
236
+ }
237
+ }
238
+ successCallback([])
239
+ }
240
+
241
+ @objc func resume(_ mediaIds: [String], errorCallback: @escaping RCTResponseSenderBlock, successCallback: @escaping RCTResponseSenderBlock) {
242
+ for mediaId in mediaIds {
243
+ VdoAsset.createAsset(videoId: mediaId) { asset, error in
244
+ if let asset = asset {
245
+ asset.resumeDownload()
246
+ }
247
+ }
248
+ }
249
+ successCallback([])
250
+ }
251
+
252
+
253
+ @objc func remove(_ mediaIds: [String], errorCallback: @escaping RCTResponseSenderBlock, successCallback: @escaping RCTResponseSenderBlock ) {
254
+ for mediaId in mediaIds {
255
+ VdoAsset.createAsset(videoId: mediaId) { asset, error in
256
+ if let asset = asset {
257
+ if asset.downloadState == .downloading || asset.downloadState == .paused {
258
+ asset.cancelDownload()
259
+ }
260
+ else if asset.downloadState == .downloaded {
261
+ asset.deleteDownload()
262
+ }
263
+ asset.percentDownload = 0
264
+ DownloadEventEmitter.sharedInstance.dispatch(name: .EVENT_DELETED, params: ["mediaId": asset.videoId, "downloadStatus": self.createVdoAssetMap(with: asset)])
265
+ }
266
+ }
267
+ }
268
+ successCallback([])
269
+ }
270
+
271
+ // MARK: Add-Remove Observer functions
272
+ private func addDownloadObservers() {
273
+ NotificationCenter.default.addObserver(self, selector: #selector(handleDownloadProgress(_:)), name: .AssetDownloadProgress, object: nil)
274
+ NotificationCenter.default.addObserver(self, selector: #selector(handleDownloadStateChange(_:)), name: .AssetDownloadStateChanged, object: nil)
275
+ NotificationCenter.default.addObserver(self, selector: #selector(handleDownloadFailed(_:)), name: .AssetDownloadFailed, object: nil)
276
+ }
277
+
278
+ private func removeObservers() {
279
+ NotificationCenter.default.removeObserver(self, name: .AssetDownloadProgress, object: nil)
280
+ NotificationCenter.default.removeObserver(self, name: .AssetDownloadStateChanged, object: nil)
281
+ NotificationCenter.default.removeObserver(self, name: .AssetDownloadFailed, object: nil)
282
+ }
283
+
284
+ // MARK: Notification handlers
285
+ @objc func handleDownloadStateChange(_ notification: Notification) {
286
+ let notice = notification.userInfo!
287
+ guard let stateRawValue = notice[VdoAsset.Keys.downloadState] as? String,
288
+ let newState = VdoAsset.DownloadState(rawValue: (stateRawValue)) else {
289
+ return
290
+ }
291
+ if newState == .notDownloaded {
292
+ return
293
+ }
294
+ if let videoId = notice[VdoAsset.Keys.videoId] as? String {
295
+ if videoId == self.asset?.videoId, let asset = asset {
296
+ if newState == .downloaded {
297
+ DownloadEventEmitter.sharedInstance.dispatch(name: .EVENT_COMPLETED, params: ["mediaId": asset.videoId, "downloadStatus": self.createVdoAssetMap(with: asset)])
298
+ } else if newState == .downloading {
299
+ DownloadEventEmitter.sharedInstance.dispatch(name: .EVENT_QUEUED, params: ["mediaId": asset.videoId, "downloadStatus": self.createVdoAssetMap(with: asset)])
300
+ } else {
301
+ DownloadEventEmitter.sharedInstance.dispatch(name: .EVENT_CHANGED, params: ["mediaId": asset.videoId, "downloadStatus": self.createVdoAssetMap(with: asset)])
302
+ }
303
+ } else {
304
+ VdoAsset.createAsset(videoId: videoId) { asset, _ in
305
+ guard let asset = asset else { return }
306
+ if newState == .downloaded {
307
+ DownloadEventEmitter.sharedInstance.dispatch(name: .EVENT_COMPLETED, params: ["mediaId": asset.videoId, "downloadStatus": self.createVdoAssetMap(with: asset)])
308
+ } else if newState == .downloading {
309
+ DownloadEventEmitter.sharedInstance.dispatch(name: .EVENT_QUEUED, params: ["mediaId": asset.videoId, "downloadStatus": self.createVdoAssetMap(with: asset)])
310
+ } else {
311
+ DownloadEventEmitter.sharedInstance.dispatch(name: .EVENT_CHANGED, params: ["mediaId": asset.videoId, "downloadStatus": self.createVdoAssetMap(with: asset)])
312
+ }
313
+ }
314
+ }
315
+ }
316
+ }
317
+
318
+ @objc func handleDownloadProgress(_ notification: Notification) {
319
+ let notice = notification.userInfo!
320
+ guard let percentDownload = notice[VdoAsset.Keys.percentDownloaded] as? Double else {
321
+ return
322
+ }
323
+ if let videoId = notice[VdoAsset.Keys.videoId] as? String {
324
+ if videoId == self.asset?.videoId, let asset = asset {
325
+ asset.percentDownload = percentDownload
326
+ DownloadEventEmitter.sharedInstance.dispatch(name: .EVENT_CHANGED, params: ["mediaId": asset.videoId, "downloadStatus": self.createVdoAssetMap(with: asset)])
327
+ } else {
328
+ VdoAsset.createAsset(videoId: videoId) { asset, _ in
329
+ guard let asset = asset else { return }
330
+ asset.percentDownload = percentDownload
331
+ DownloadEventEmitter.sharedInstance.dispatch(name: .EVENT_CHANGED, params: ["mediaId": asset.videoId, "downloadStatus": self.createVdoAssetMap(with: asset)])
332
+ }
333
+ }
334
+ }
335
+ }
336
+
337
+ @objc func handleDownloadFailed(_ notification: Notification) {
338
+ let notice = notification.userInfo!
339
+ guard let message = notice[VdoAsset.Keys.message] as? String, let code = notice[VdoAsset.Keys.code] else {return}
340
+ if let videoId = notice[VdoAsset.Keys.videoId] as? String {
341
+ if videoId == self.asset?.videoId, let asset = asset {
342
+ var assetMap = self.createVdoAssetMap(with: asset)
343
+ assetMap["reasonDescription"] = message
344
+ assetMap["reason"] = code
345
+ DownloadEventEmitter.sharedInstance.dispatch(name: .EVENT_FAILED, params: ["mediaId": asset.videoId, "downloadStatus": assetMap])
346
+ } else {
347
+ VdoAsset.createAsset(videoId: videoId) { asset, _ in
348
+ guard let asset = asset else { return }
349
+ var assetMap = self.createVdoAssetMap(with: asset)
350
+ assetMap["reasonDescription"] = message
351
+ assetMap["reason"] = code
352
+ DownloadEventEmitter.sharedInstance.dispatch(name: .EVENT_FAILED, params: ["mediaId": asset.videoId, "downloadStatus": assetMap])
353
+ }
354
+ }
355
+ }
356
+ }
357
+
358
+ // MARK: Map creation functions
359
+ private func createTracksMap(with videoQualities: [VdoFramework.VdoAsset.VideoQuality]) -> [[String: Any]] {
360
+ var tracks: [[String: Any]] = []
361
+ var counter = 1
362
+ for quality in videoQualities {
363
+ var track: [String: Any] = [:]
364
+ track["id"] = counter
365
+ track["type"] = "video"
366
+ track["bitrate"] = quality.bitrate
367
+ let resolution = quality.resolution.trimmingCharacters(in: .whitespacesAndNewlines)
368
+ let size = resolution.components(separatedBy: "x")
369
+ if size.count == 2 {
370
+ track["width"] = Int(size.first ?? "") ?? 0
371
+ track["height"] = Int(size.last ?? "") ?? 0
372
+ }
373
+ counter += 1
374
+ tracks.append(track)
375
+ }
376
+
377
+ return tracks
378
+ }
379
+
380
+ private func createDownloadOptionsMap(with availableTracks: [[String: Any]], mediaInfo: [String: Any]) -> [String: Any] {
381
+ var downloadOptionsMap: [String: Any] = [:]
382
+ downloadOptionsMap["mediaId"] = mediaInfo["mediaId"]
383
+ downloadOptionsMap["mediaInfo"] = mediaInfo
384
+ downloadOptionsMap["availableTracks"] = availableTracks
385
+ return downloadOptionsMap
386
+ }
387
+
388
+ private func createMediaInfoMap(with mediaInfo: MediaInfo) -> [String: Any] {
389
+ var mediaInfoMap : [String: Any] = [:]
390
+
391
+ mediaInfoMap["title"] = mediaInfo.title
392
+ mediaInfoMap["duration"] = Int(mediaInfo.duration ) * 1000
393
+ mediaInfoMap["mediaId"] = mediaInfo.videoId
394
+ mediaInfoMap["description"] = mediaInfo.mediaDescription
395
+ mediaInfoMap["type"] = "info"
396
+
397
+ return mediaInfoMap
398
+ }
399
+
400
+ private func createMediaInfoMap(with asset: VdoAsset) -> [String: Any] {
401
+ var mediaInfoMap : [String: Any] = [:]
402
+
403
+ mediaInfoMap["title"] = asset.title
404
+ mediaInfoMap["duration"] = Int(asset.duration ?? 0) * 1000
405
+ mediaInfoMap["mediaId"] = asset.videoId
406
+ mediaInfoMap["description"] = asset.description
407
+ mediaInfoMap["type"] = "info"
408
+
409
+ return mediaInfoMap
410
+ }
411
+
412
+ private func createVdoAssetMap(with asset: VdoAsset) -> [String: Any] {
413
+ var downloadStatus: [String: Any] = [:]
414
+
415
+ downloadStatus["mediaInfo"] = createMediaInfoMap(with: asset)
416
+ downloadStatus["downloadPercent"] = Int(asset.percentDownload * 100)
417
+ downloadStatus["status"] = self.mapDownloadStateToRNText(downloadState: asset.downloadState)
418
+ downloadStatus["aspectRatio"] = asset.aspectRatio
419
+ if (asset.posters?.isEmpty == false) {
420
+ downloadStatus["poster"] = asset.posters?[0].url ?? ""
421
+ }
422
+ else{
423
+ downloadStatus["poster"] = ""
424
+ }
425
+ return downloadStatus
426
+ }
427
+
428
+ private func createOfflineVdoAssetMap(with downloadInfo: DownloadInfo) -> [String: Any] {
429
+ var downloadStatus: [String: Any] = [:]
430
+
431
+ downloadStatus["mediaInfo"] = createMediaInfoMap(with: downloadInfo.mediaInfo)
432
+ downloadStatus["downloadPercent"] = Int(downloadInfo.percentDownloaded * 100)
433
+ downloadStatus["status"] = self.mapDownloadStateToRNText(downloadState: downloadInfo.status)
434
+ downloadStatus["aspectRatio"] = downloadInfo.aspectRatio
435
+ downloadStatus["poster"] = downloadInfo.poster
436
+ return downloadStatus
437
+ }
438
+
439
+ private func mapDownloadStateToRNText(downloadState: VdoAsset.DownloadState) -> String {
440
+ switch downloadState {
441
+ case .downloaded:
442
+ return "completed"
443
+ case.downloading:
444
+ return "downloading"
445
+ case .notDownloaded:
446
+ return "pending"
447
+ case .paused:
448
+ return "paused"
449
+ @unknown default:
450
+ return "pending"
451
+ }
452
+ }
453
+ }
@@ -0,0 +1,157 @@
1
+ //
2
+ // VdoEventEmitter.swift
3
+ // react-native-vdocipher-rn-bridge
4
+ //
5
+ // Created by Manish Gupta on 05/06/23.
6
+ //
7
+
8
+ import Foundation
9
+ import React
10
+
11
+ class EventEmitter {
12
+
13
+ /// Shared Instance.
14
+ public static var sharedInstance = EventEmitter()
15
+
16
+ // ReactNativeEventEmitter is instantiated by React Native with the bridge.
17
+ private static var eventEmitter: VdoEventEmitter!
18
+
19
+ let errorParsingFailDefaultErrInfo: [String: Any] = [Error_Keys.EVENT_PROP_ERROR_CODE.rawValue : -1,
20
+ Error_Keys.EVENT_PROP_ERROR_MSG.rawValue : "Error parsing failed, no error code and description available.",
21
+ Error_Keys.EVENT_PROP_ERROR_HTTP_CODE.rawValue : -1]
22
+
23
+ private init() {}
24
+
25
+ // When React Native instantiates the emitter it is registered here.
26
+ func registerEventEmitter(eventEmitter: VdoEventEmitter) {
27
+ EventEmitter.eventEmitter = eventEmitter
28
+ }
29
+
30
+ func dispatch(name: EventName, params: [String: Any]?) {
31
+ if EventEmitter.eventEmitter.hasListener == true {
32
+ var data = [String: Any] ()
33
+ if let p = params {
34
+ data["nativeEvent"] = p
35
+ }
36
+ // print("event data sent is \(data)")
37
+ EventEmitter.eventEmitter.sendEvent(withName: name.rawValue, body: data)
38
+ }
39
+ }
40
+
41
+ /// All Events which must be support by React Native.
42
+ lazy var allEvents: [String] = {
43
+
44
+ return EventName.allCases.map { $0.rawValue }
45
+ }()
46
+ }
47
+
48
+
49
+ enum EventName: String, CaseIterable {
50
+ case EVENT_INIT_SUCCESS = "onInitSuccess"
51
+ case EVENT_INIT_FAILURE = "onInitFailure"
52
+ case EVENT_LOADING = "onVdoLoading"
53
+ case EVENT_LOADED = "onVdoLoaded"
54
+ case EVENT_LOAD_ERROR = "onVdoLoadError"
55
+ case EVENT_PLAYER_STATE_CHANGED = "onVdoPlayerStateChanged"
56
+ case EVENT_PROGRESS = "onVdoProgress"
57
+ case EVENT_BUFFER_UPDATE = "onVdoBufferUpdate"
58
+ case EVENT_PLAYBACK_SPEED_CHANGED = "onVdoPlaybackSpeedChanged"
59
+ case EVENT_TRACKS_CHANGED = "onVdoTracksChanged"
60
+ case EVENT_MEDIA_ENDED = "onVdoMediaEnded"
61
+ case EVENT_ERROR = "onVdoError"
62
+ case EVENT_PLAYBACK_PROPERTIES = "onVdoPlaybackProperties"
63
+ case EVENT_ENTER_FULLSCREEN = "onVdoEnterFullscreen"
64
+ case EVENT_EXIT_FULLSCREEN = "onVdoExitFullscreen"
65
+ case EVENT_IS_INITIAL_PORTRAIT = "onIsInitialPortrait"
66
+ case EVENT_PICTURE_IN_PICTURE_MODE_CHANGED = "onVdoPictureInPictureModeChanged"
67
+ }
68
+
69
+ enum Keys: String {
70
+ case EVENT_PROP_RESTORED = "restored"
71
+ case EVENT_PROP_MEDIA_INFO = "mediaInfo"
72
+ case EVENT_PROP_CURRENT_TIME = "currentTime"
73
+ case EVENT_PROP_BUFFER_TIME = "bufferTime"
74
+ case EVENT_PROP_SEEK_TIME = "seekTime"
75
+ case EVENT_PROP_ORIENTATION = "orientation"
76
+ case EVENT_PROP_AVAILABLE_TRACKS = "availableTracks"
77
+ case EVENT_PROP_SELECTED_TRACKS = "selectedTracks"
78
+ case EVENT_PROP_PLAY_WHEN_READY = "playWhenReady"
79
+ case EVENT_PROP_PLAYER_STATE = "playerState"
80
+ case EVENT_PROP_PLAYBACK_SPEED = "playbackSpeed"
81
+ case EVENT_PROP_IS_INITIAL_PORTRAIT = "isInitialPortrait"
82
+ case EVENT_PROP_IS_IN_PICTURE_IN_PICTURE_MODE = "isInPictureInPictureMode"
83
+ case EVENT_PROP_ERROR_DESCRIPTION = "errorDescription"
84
+ }
85
+
86
+ enum Error_Keys: String {
87
+ case EVENT_PROP_ERROR_CODE = "errorCode"
88
+ case EVENT_PROP_ERROR_MSG = "errorMsg"
89
+ case EVENT_PROP_ERROR_HTTP_CODE = "httpStatusCode"
90
+ }
91
+
92
+ struct ErrorDescription: Encodable {
93
+ let errorCode: Int
94
+ let errorMsg: String
95
+ let httpStatusCode: Int
96
+ }
97
+
98
+ struct Media: Encodable {
99
+ let mediaId: String
100
+ let type: String
101
+ let title: String
102
+ let description: String
103
+ let duration: Int
104
+ }
105
+
106
+
107
+ @objc(VdoEventEmitter)
108
+ class VdoEventEmitter: RCTEventEmitter {
109
+
110
+ override init() {
111
+ super.init()
112
+ // print("\(type(of: self))).\(#function)")
113
+ EventEmitter.sharedInstance.registerEventEmitter(eventEmitter: self)
114
+ }
115
+
116
+ var hasListener: Bool?
117
+
118
+ /// Base overide for RCTEventEmitter.
119
+ ///
120
+ /// - Returns: all supported events
121
+ @objc open override func supportedEvents() -> [String] {
122
+ // print("\(type(of: self))).\(#function)")
123
+ return EventEmitter.sharedInstance.allEvents
124
+ }
125
+
126
+ @objc open override func startObserving() {
127
+ super.startObserving()
128
+ hasListener = true
129
+ // print("\(type(of: self))).\(#function)")
130
+ }
131
+
132
+ @objc open override func stopObserving() {
133
+ super.stopObserving()
134
+ hasListener = false
135
+ // print("\(type(of: self))).\(#function)")
136
+ }
137
+
138
+ open override class func requiresMainQueueSetup() -> Bool {
139
+ // print("\(type(of: self))).\(#function)")
140
+ return true
141
+ }
142
+
143
+ open override func addListener(_ eventName: String!) {
144
+ super.addListener(eventName)
145
+ // print("\(type(of: self))).\(#function) eventName: \(eventName)")
146
+ }
147
+
148
+ open override func removeListeners(_ count: Double) {
149
+ super.removeListeners(count)
150
+ // print("\(type(of: self))).\(#function) count: \(count)")
151
+ }
152
+
153
+ open override func invalidate() {
154
+ super.invalidate()
155
+ // print("\(type(of: self))).\(#function)")
156
+ }
157
+ }
@@ -0,0 +1,19 @@
1
+ //
2
+ // VdoPlaybackProperties.h
3
+ // Pods
4
+ //
5
+ // Created by Manish Gupta on 07/06/23.
6
+ //
7
+
8
+ #ifndef VdoPlaybackProperties_h
9
+ #define VdoPlaybackProperties_h
10
+
11
+
12
+ #endif /* VdoPlaybackProperties_h */
13
+
14
+
15
+ @interface VdoPlaybackProperties : NSObject
16
+
17
+ + (NSDictionary *) getPlaybackProperties;
18
+
19
+ @end
@@ -0,0 +1,21 @@
1
+ //
2
+ // VdoPlaybackProperties.swift
3
+ // react-native-vdocipher-rn-bridge
4
+ //
5
+ // Created by Manish Gupta on 07/06/23.
6
+ //
7
+
8
+ import Foundation
9
+ import VdoFramework
10
+
11
+ @objc(VdoPlaybackProperties)
12
+ class VdoPlaybackProperties: NSObject {
13
+
14
+ @objc static func getPlaybackProperties() -> [String : Any] {
15
+ let totalPlayed = VdoCipher.getValueOfPlaybackProperty(.totalPlayed)?[VdoCipher.PlaybackProperty.totalPlayed.rawValue] ?? 0
16
+
17
+ let totalCovered = VdoCipher.getValueOfPlaybackProperty(.totalCovered)?[VdoCipher.PlaybackProperty.totalCovered.rawValue] ?? 0
18
+
19
+ return ["totalPlayed": totalPlayed, "totalCovered": totalCovered]
20
+ }
21
+ }
@@ -1,11 +1,3 @@
1
+ #import <React/RCTViewManager.h>
1
2
 
2
- #if __has_include("RCTBridgeModule.h")
3
- #import "RCTBridgeModule.h"
4
- #else
5
- #import <React/RCTBridgeModule.h>
6
- #endif
7
-
8
- @interface VdocipherRnBridge : NSObject <RCTBridgeModule>
9
-
10
- @end
11
-
3
+