vdocipher-rn-bridge 1.15.0 → 1.17.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.
- package/CHANGELOG.md +27 -0
- package/VdoPlayerSupportView.tsx +6 -4
- package/VdoPlayerUIView.tsx +21 -9
- package/VdoPlayerView.tsx +184 -58
- package/android/build.gradle +3 -3
- package/android/src/main/java/com/vdocipher/rnbridge/ReactVdoPlayerUIView.java +47 -32
- package/android/src/main/java/com/vdocipher/rnbridge/ReactVdoPlayerUIViewManager.java +5 -0
- package/android/src/main/java/com/vdocipher/rnbridge/ReactVdoPlayerView.java +10 -10
- package/android/src/main/java/com/vdocipher/rnbridge/VdoDownloadModule.java +67 -0
- package/android/src/main/java/com/vdocipher/rnbridge/VdoEventEmitter.java +1 -10
- package/downloadMonitor.ts +2 -2
- package/downloads.ts +63 -1
- package/index.ts +4 -1
- package/ios/Podfile +10 -0
- package/ios/Podfile.lock +3 -0
- package/ios/Pods/Manifest.lock +3 -0
- package/ios/Pods/Pods.xcodeproj/project.pbxproj +397 -0
- package/ios/Pods/Pods.xcodeproj/xcuserdata/mansisharma.xcuserdatad/xcschemes/Pods-VdocipherRnBridge.xcscheme +58 -0
- package/ios/Pods/Pods.xcodeproj/xcuserdata/mansisharma.xcuserdatad/xcschemes/xcschememanagement.plist +16 -0
- package/ios/Pods/Target Support Files/Pods-VdocipherRnBridge/Pods-VdocipherRnBridge-Info.plist +26 -0
- package/ios/Pods/Target Support Files/Pods-VdocipherRnBridge/Pods-VdocipherRnBridge-acknowledgements.markdown +3 -0
- package/ios/Pods/Target Support Files/Pods-VdocipherRnBridge/Pods-VdocipherRnBridge-acknowledgements.plist +29 -0
- package/ios/Pods/Target Support Files/Pods-VdocipherRnBridge/Pods-VdocipherRnBridge-dummy.m +5 -0
- package/ios/Pods/Target Support Files/Pods-VdocipherRnBridge/Pods-VdocipherRnBridge-umbrella.h +16 -0
- package/ios/Pods/Target Support Files/Pods-VdocipherRnBridge/Pods-VdocipherRnBridge.debug.xcconfig +8 -0
- package/ios/Pods/Target Support Files/Pods-VdocipherRnBridge/Pods-VdocipherRnBridge.modulemap +6 -0
- package/ios/Pods/Target Support Files/Pods-VdocipherRnBridge/Pods-VdocipherRnBridge.release.xcconfig +8 -0
- package/ios/RCTVdoPlayerUIView.h +19 -0
- package/ios/RCTVdoPlayerUIView.swift +74 -0
- package/ios/RCTVdoPlayerView.h +18 -0
- package/ios/RCTVdoPlayerView.swift +84 -0
- package/ios/TrackSelection.swift +64 -0
- package/ios/VdoCipherRNView.h +18 -0
- package/ios/VdoCipherRNView.swift +312 -0
- package/ios/VdoDownload.swift +103 -0
- package/ios/VdoEventEmitter.swift +157 -0
- package/ios/VdoPlaybackProperties.h +19 -0
- package/ios/VdoPlaybackProperties.swift +21 -0
- package/ios/VdocipherRnBridge.h +2 -10
- package/ios/VdocipherRnBridgeViewManager.m +99 -0
- package/ios/VdocipherRnBridgeViewManager.swift +90 -0
- package/package.json +3 -2
- package/react-native-vdocipher-rn-bridge.podspec +36 -0
- package/type.ts +23 -1
- package/ios/VdocipherRnBridge.m +0 -13
- package/ios/VdocipherRnBridge.xcodeproj/project.pbxproj +0 -259
- package/ios/VdocipherRnBridge.xcworkspace/contents.xcworkspacedata +0 -9
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
//
|
|
2
|
+
// VdoCipherRNView.swift
|
|
3
|
+
// react-native-vdocipher-rn-bridge
|
|
4
|
+
//
|
|
5
|
+
// Created by Manish Gupta on 29/05/23.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
import AVKit
|
|
10
|
+
import VdoFramework
|
|
11
|
+
|
|
12
|
+
class VdoCipherRNView: UIView {
|
|
13
|
+
|
|
14
|
+
@objc var player: AVPlayer?
|
|
15
|
+
@objc var asset: VdoAsset?
|
|
16
|
+
|
|
17
|
+
private var playWhenReady: Bool = true
|
|
18
|
+
private var progressTimer: Timer?
|
|
19
|
+
private var isLoaded = false
|
|
20
|
+
private var targetPlaybackSpeed: Float = 1.0
|
|
21
|
+
|
|
22
|
+
private var playerItemBufferEmptyObserver: NSKeyValueObservation?
|
|
23
|
+
private var playerItemBufferKeepUpObserver: NSKeyValueObservation?
|
|
24
|
+
private var playerItemBufferFullObserver: NSKeyValueObservation?
|
|
25
|
+
|
|
26
|
+
private var playerState: PlayerState = .unknown {
|
|
27
|
+
didSet{
|
|
28
|
+
if oldValue != playerState {
|
|
29
|
+
EventEmitter.sharedInstance.dispatch(name: .EVENT_PLAYER_STATE_CHANGED, params: [Keys.EVENT_PROP_PLAYER_STATE.rawValue : playerState.rawValue, Keys.EVENT_PROP_PLAY_WHEN_READY.rawValue : self.playWhenReady])
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
override init(frame: CGRect) {
|
|
35
|
+
super.init(frame: frame)
|
|
36
|
+
let userDefaults: UserDefaults? = UserDefaults.init(suiteName: "com.vdocipher.ios.rn.VdoFramework")
|
|
37
|
+
userDefaults?.set(["name": "react-native", "version": VdocipherRnBridge.vdocipherRnBridgeVersionString], forKey: "rnToolkitInfo")
|
|
38
|
+
VdoCipher.setPlaybackDelegate(delegate: self)
|
|
39
|
+
VdoCipher.setUIPlayerDelegate(self)
|
|
40
|
+
EventEmitter.sharedInstance.dispatch(name: EventName.EVENT_INIT_SUCCESS, params: [Keys.EVENT_PROP_RESTORED.rawValue : false])
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
required init?(coder: NSCoder) {
|
|
44
|
+
super.init(coder: coder)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
override func willMove(toSuperview newSuperview: UIView?) {
|
|
48
|
+
super.willMove(toSuperview: newSuperview)
|
|
49
|
+
guard newSuperview != nil else {
|
|
50
|
+
return
|
|
51
|
+
}
|
|
52
|
+
// print("added to a superView \(newSuperview) reactViewController is \(self.reactViewController())")
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
override func didMoveToSuperview() {
|
|
56
|
+
super.didMoveToSuperview()
|
|
57
|
+
if self.superview == nil {
|
|
58
|
+
player?.pause()
|
|
59
|
+
self.removeObservers()
|
|
60
|
+
player?.replaceCurrentItem(with: nil)
|
|
61
|
+
player = nil
|
|
62
|
+
} /* else {
|
|
63
|
+
// print("did move to a superView, reactViewController is \(self.reactViewController())")
|
|
64
|
+
} */
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
func addObserversToPlayer()
|
|
68
|
+
{
|
|
69
|
+
NotificationCenter.default.addObserver(self,
|
|
70
|
+
selector: #selector(videoDidEnd),
|
|
71
|
+
name: NSNotification.Name.AVPlayerItemDidPlayToEndTime,
|
|
72
|
+
object: nil)
|
|
73
|
+
|
|
74
|
+
playerItemBufferEmptyObserver = self.player?.currentItem?.observe(\AVPlayerItem.isPlaybackBufferEmpty, options: [.new]) { [weak self] (_, _) in
|
|
75
|
+
guard let self = self else { return }
|
|
76
|
+
self.playerState = .buffering
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
playerItemBufferKeepUpObserver = self.player?.currentItem?.observe(\AVPlayerItem.isPlaybackLikelyToKeepUp, options: [.new]) { [weak self] (_, _) in
|
|
80
|
+
guard let self = self else { return }
|
|
81
|
+
self.playerState = .ready
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
playerItemBufferFullObserver = self.player?.currentItem?.observe(\AVPlayerItem.isPlaybackBufferFull, options: [.new]) { [weak self] (_, _) in
|
|
85
|
+
guard let self = self else { return }
|
|
86
|
+
self.playerState = .ready
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
progressTimer = Timer.scheduledTimer(withTimeInterval: 0.5, repeats: true, block: {_ in
|
|
90
|
+
self.sendPlayerProgress()
|
|
91
|
+
})
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
private func sendPlayerProgress() {
|
|
95
|
+
let currentTime = Int(self.player?.currentItem?.currentTime().seconds.rounded( .down) ?? 0.0 ) * 1000
|
|
96
|
+
// print("Current time send as event emitter is \(currentTime)")
|
|
97
|
+
if currentTime > 0 {
|
|
98
|
+
EventEmitter.sharedInstance.dispatch(name: .EVENT_PROGRESS, params: [Keys.EVENT_PROP_CURRENT_TIME.rawValue : currentTime])
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
func setCaptionLanguage(lanCode: String?) -> Bool {
|
|
103
|
+
var isSuccess: Bool = false
|
|
104
|
+
guard let asset = self.asset else { return isSuccess } // return false
|
|
105
|
+
if lanCode == nil {
|
|
106
|
+
isSuccess = asset.setCaption(nil)
|
|
107
|
+
return isSuccess
|
|
108
|
+
} else {
|
|
109
|
+
if let caption = asset.captions?.first(where: { $0.lang == lanCode }) {
|
|
110
|
+
isSuccess = asset.setCaption(caption)
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return isSuccess
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
func removeObservers()
|
|
117
|
+
{
|
|
118
|
+
NotificationCenter.default.removeObserver(self,
|
|
119
|
+
name: NSNotification.Name.AVPlayerItemDidPlayToEndTime,
|
|
120
|
+
object: nil)
|
|
121
|
+
|
|
122
|
+
playerItemBufferEmptyObserver?.invalidate()
|
|
123
|
+
playerItemBufferEmptyObserver = nil
|
|
124
|
+
|
|
125
|
+
playerItemBufferKeepUpObserver?.invalidate()
|
|
126
|
+
playerItemBufferKeepUpObserver = nil
|
|
127
|
+
|
|
128
|
+
playerItemBufferFullObserver?.invalidate()
|
|
129
|
+
playerItemBufferFullObserver = nil
|
|
130
|
+
|
|
131
|
+
progressTimer?.invalidate()
|
|
132
|
+
progressTimer = nil
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
@objc func videoDidEnd(notification: NSNotification) {
|
|
136
|
+
if self.playerState == .ended {
|
|
137
|
+
return
|
|
138
|
+
}
|
|
139
|
+
self.sendPlayerProgress()
|
|
140
|
+
self.playerState = .ended
|
|
141
|
+
self.playWhenReady = false
|
|
142
|
+
EventEmitter.sharedInstance.dispatch(name: .EVENT_MEDIA_ENDED, params: nil)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
@objc func playerReadyToPlay() {
|
|
146
|
+
self.playerState = .ready
|
|
147
|
+
if self.playWhenReady == true {
|
|
148
|
+
self.player?.rate = targetPlaybackSpeed
|
|
149
|
+
} else {
|
|
150
|
+
self.player?.rate = 0
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
@objc func setEmbedInfo(_ embedInfo: [String: Any]) {
|
|
155
|
+
// print("Embed Info is \(embedInfo)")
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
@objc func setResizeMode(_ resizeMode: String) {
|
|
159
|
+
// print("Resize Mode called with value == \(resizeMode)")
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
@objc func setPlayWhenReady(_ playWhenReady: Bool) {
|
|
163
|
+
// print("playWhenReady called with value == \(playWhenReady)")
|
|
164
|
+
self.playWhenReady = playWhenReady
|
|
165
|
+
if playWhenReady == true {
|
|
166
|
+
if targetPlaybackSpeed == 0 {
|
|
167
|
+
targetPlaybackSpeed = 1.0
|
|
168
|
+
}
|
|
169
|
+
// Above Condition implies the playback was paused and play is triggered
|
|
170
|
+
// The condition is required since we need to keep the playbackSpeed in case user navigates to and fro this screen.
|
|
171
|
+
self.player?.rate = targetPlaybackSpeed
|
|
172
|
+
} else {
|
|
173
|
+
// Below on pause 'targetPlaybackSpeed' is set to 0 which implies when user navigates back to this screen playback shouldn't resume
|
|
174
|
+
self.targetPlaybackSpeed = 0
|
|
175
|
+
self.player?.rate = 0
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
@objc func setPlaybackSpeed(_ speed: Float) {
|
|
180
|
+
// print("playbackSpeed called with value == \(speed)")
|
|
181
|
+
self.targetPlaybackSpeed = speed
|
|
182
|
+
self.player?.rate = speed
|
|
183
|
+
EventEmitter.sharedInstance.dispatch(name: .EVENT_PLAYBACK_SPEED_CHANGED, params: [Keys.EVENT_PROP_PLAYBACK_SPEED.rawValue : speed])
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
@objc func setSeek(_ seekTime: Int) {
|
|
187
|
+
// print("seek called with value == \(seekTime)")
|
|
188
|
+
self.player?.seek(to: CMTime(value: CMTimeValue(seekTime), timescale: 1000))
|
|
189
|
+
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
@objc func setCaptionLanguage(_ caption: [String: Any]) {
|
|
193
|
+
// print("========= TrackSelection setCaptionLanguage called")
|
|
194
|
+
guard let asset = TrackSelection.asset,
|
|
195
|
+
let captions = asset.captions,
|
|
196
|
+
let selectedCaptionName = caption["name"] as? String,
|
|
197
|
+
let selectedCaptionObject = captions.first(where: {$0.captionName ?? "" == selectedCaptionName}) else {return}
|
|
198
|
+
if (asset.setCaption(selectedCaptionObject) == true) {
|
|
199
|
+
guard let selectedCaption = TrackSelection.asset?.getCurrentEnabledCaption(),
|
|
200
|
+
let name = selectedCaption.captionName,
|
|
201
|
+
let selectedCaptionMap = TrackSelection.captionLanguagesMap?.first(where: {$0["name"] as? String == name}) else {
|
|
202
|
+
return
|
|
203
|
+
}
|
|
204
|
+
EventEmitter.sharedInstance.dispatch(name: .EVENT_TRACKS_CHANGED, params: [Keys.EVENT_PROP_AVAILABLE_TRACKS.rawValue : TrackSelection.captionLanguagesMap ?? [], Keys.EVENT_PROP_SELECTED_TRACKS.rawValue: [selectedCaptionMap]])
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
@objc func setDisableCaptions(_ val: Int) {
|
|
209
|
+
// print("========= TrackSelection disableCaptions called")
|
|
210
|
+
if (TrackSelection.asset?.setCaption(nil) == true) {
|
|
211
|
+
EventEmitter.sharedInstance.dispatch(name: .EVENT_TRACKS_CHANGED, params: [Keys.EVENT_PROP_AVAILABLE_TRACKS.rawValue : TrackSelection.captionLanguagesMap ?? []])
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
func sendErrorEventWithDescription(_ errorDescription: ErrorDescription) {
|
|
216
|
+
if let errorInfo = getJSONEncodedEventDictionary(info: errorDescription) {
|
|
217
|
+
EventEmitter.sharedInstance.dispatch(name: .EVENT_LOAD_ERROR, params: [Keys.EVENT_PROP_ERROR_DESCRIPTION.rawValue : errorInfo])
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
func getJSONEncodedEventDictionary<T>(info eventInfo: T) -> [String: Any]? where T : Encodable {
|
|
222
|
+
let jsonEncoder = JSONEncoder()
|
|
223
|
+
guard let encoded = try? jsonEncoder.encode(eventInfo),
|
|
224
|
+
let info = try? JSONSerialization.jsonObject(with: encoded, options: .allowFragments) as? [String: Any] else {
|
|
225
|
+
EventEmitter.sharedInstance.dispatch(name: .EVENT_LOAD_ERROR,
|
|
226
|
+
params: [Keys.EVENT_PROP_ERROR_DESCRIPTION.rawValue : EventEmitter.sharedInstance.errorParsingFailDefaultErrInfo])
|
|
227
|
+
return nil
|
|
228
|
+
}
|
|
229
|
+
return info
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
extension VdoCipherRNView: AssetPlaybackDelegate {
|
|
234
|
+
func streamLoadError(error: VdoError) {
|
|
235
|
+
let errorDescription = ErrorDescription(errorCode: error.code, errorMsg: error.message, httpStatusCode: -1)
|
|
236
|
+
self.sendErrorEventWithDescription(errorDescription)
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
func streamPlaybackManager(playerReadyToPlay player: AVPlayer) {
|
|
240
|
+
self.playerReadyToPlay()
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
func streamPlaybackManager(playerCurrentItemDidChange player: AVPlayer) {
|
|
244
|
+
self.setUpPlayer(player)
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
func setUpPlayer(_ player: AVPlayer) {
|
|
248
|
+
if isLoaded == true {
|
|
249
|
+
return
|
|
250
|
+
}
|
|
251
|
+
isLoaded = true
|
|
252
|
+
self.player = player
|
|
253
|
+
self.removeObservers()
|
|
254
|
+
self.addObserversToPlayer()
|
|
255
|
+
|
|
256
|
+
guard let asset = asset else { return }
|
|
257
|
+
let mInfo = Media(mediaId: asset.videoId,
|
|
258
|
+
type: "streaming",
|
|
259
|
+
title: asset.title ?? "",
|
|
260
|
+
description: asset.description,
|
|
261
|
+
duration: (Int(asset.duration ?? 0.0) * 1000) )
|
|
262
|
+
guard let eventInfo = getJSONEncodedEventDictionary(info: mInfo) else { return }
|
|
263
|
+
EventEmitter.sharedInstance.dispatch(name: EventName.EVENT_LOADED,
|
|
264
|
+
params: [Keys.EVENT_PROP_MEDIA_INFO.rawValue : eventInfo])
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
extension VdoCipherRNView: VdoPlayerViewControllerDelegate {
|
|
269
|
+
func didTapEnterFullScreen(for id: String) {
|
|
270
|
+
EventEmitter.sharedInstance.dispatch(name: .EVENT_ENTER_FULLSCREEN, params: nil)
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
func didTapExitFullScreen(for id: String) {
|
|
274
|
+
EventEmitter.sharedInstance.dispatch(name: .EVENT_EXIT_FULLSCREEN, params: nil)
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
func didChangePlayerRate(for id: String, to speed: Float) {
|
|
278
|
+
self.targetPlaybackSpeed = speed
|
|
279
|
+
EventEmitter.sharedInstance.dispatch(name: .EVENT_PLAYBACK_SPEED_CHANGED, params: [Keys.EVENT_PROP_PLAYBACK_SPEED.rawValue : speed])
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
func didChangeCaption(for id: String, to name: String, code: String) {
|
|
283
|
+
guard let selectedCaptionMap = TrackSelection.captionLanguagesMap?.first(where: {$0["language"] as! String == code}) else {
|
|
284
|
+
return
|
|
285
|
+
}
|
|
286
|
+
EventEmitter.sharedInstance.dispatch(name: .EVENT_TRACKS_CHANGED, params: [Keys.EVENT_PROP_AVAILABLE_TRACKS.rawValue : TrackSelection.captionLanguagesMap ?? [], Keys.EVENT_PROP_SELECTED_TRACKS.rawValue: [selectedCaptionMap]])
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
extension VdoCipherRNView: UINavigationControllerDelegate {
|
|
291
|
+
|
|
292
|
+
func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {
|
|
293
|
+
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {
|
|
297
|
+
guard let parentController = self.reactViewController() else {return}
|
|
298
|
+
if viewController != parentController {
|
|
299
|
+
player?.pause()
|
|
300
|
+
} else if viewController == parentController {
|
|
301
|
+
player?.rate = targetPlaybackSpeed
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
private enum PlayerState : String
|
|
307
|
+
{
|
|
308
|
+
case buffering = "buffering",
|
|
309
|
+
ready = "ready",
|
|
310
|
+
ended = "ended",
|
|
311
|
+
unknown = "unknown"
|
|
312
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
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
|
+
var data = [String: Any] ()
|
|
29
|
+
if let p = params {
|
|
30
|
+
data["nativeEvent"] = p
|
|
31
|
+
}
|
|
32
|
+
// print("event data sent is \(data)")
|
|
33
|
+
DownloadEventEmitter.eventEmitter.sendEvent(withName: name.rawValue, body: data)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/// All Events which must be support by React Native.
|
|
38
|
+
lazy var allEvents: [String] = {
|
|
39
|
+
|
|
40
|
+
return DownloadEventName.allCases.map { $0.rawValue }
|
|
41
|
+
}()
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
enum DownloadEventName: String, CaseIterable {
|
|
46
|
+
case EVENT_QUEUED = "onQueued"
|
|
47
|
+
case EVENT_CHANGED = "onChanged"
|
|
48
|
+
case EVENT_COMPLETED = "onCompleted"
|
|
49
|
+
case EVENT_FAILED = "onFailed"
|
|
50
|
+
case EVENT_DELETED = "onDeleted"
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
@objc(VdoDownload)
|
|
54
|
+
class VdoDownload: RCTEventEmitter {
|
|
55
|
+
|
|
56
|
+
override init() {
|
|
57
|
+
super.init()
|
|
58
|
+
// print("\(type(of: self))).\(#function)")
|
|
59
|
+
DownloadEventEmitter.sharedInstance.registerEventEmitter(eventEmitter: self)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
var hasListener: Bool?
|
|
63
|
+
|
|
64
|
+
/// Base overide for RCTEventEmitter.
|
|
65
|
+
///
|
|
66
|
+
/// - Returns: all supported events
|
|
67
|
+
@objc open override func supportedEvents() -> [String] {
|
|
68
|
+
// print("\(type(of: self))).\(#function)")
|
|
69
|
+
return DownloadEventEmitter.sharedInstance.allEvents
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
@objc open override func startObserving() {
|
|
73
|
+
super.startObserving()
|
|
74
|
+
hasListener = true
|
|
75
|
+
// print("\(type(of: self))).\(#function)")
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
@objc open override func stopObserving() {
|
|
79
|
+
super.stopObserving()
|
|
80
|
+
hasListener = false
|
|
81
|
+
// print("\(type(of: self))).\(#function)")
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
open override class func requiresMainQueueSetup() -> Bool {
|
|
85
|
+
// print("\(type(of: self))).\(#function)")
|
|
86
|
+
return true
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
open override func addListener(_ eventName: String!) {
|
|
90
|
+
super.addListener(eventName)
|
|
91
|
+
// print("\(type(of: self))).\(#function) eventName: \(eventName)")
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
open override func removeListeners(_ count: Double) {
|
|
95
|
+
super.removeListeners(count)
|
|
96
|
+
// print("\(type(of: self))).\(#function) count: \(count)")
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
open override func invalidate() {
|
|
100
|
+
super.invalidate()
|
|
101
|
+
// print("\(type(of: self))).\(#function)")
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -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
|
+
}
|
package/ios/VdocipherRnBridge.h
CHANGED