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.
- package/CHANGELOG.md +14 -0
- package/VdoPlayerUIView.tsx +10 -10
- package/VdoPlayerView.tsx +170 -70
- package/android/build.gradle +3 -3
- package/android/src/main/java/com/vdocipher/rnbridge/ReactVdoPlayerUIView.java +13 -7
- package/android/src/main/java/com/vdocipher/rnbridge/VdoDownloadModule.java +67 -0
- package/downloadMonitor.ts +2 -2
- package/downloads.ts +41 -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 +36 -0
- package/ios/RCTVdoPlayerView.h +18 -0
- package/ios/RCTVdoPlayerView.swift +47 -0
- package/ios/TrackSelection.swift +64 -0
- package/ios/VdoCipherRNView.h +18 -0
- package/ios/VdoCipherRNView.swift +391 -0
- package/ios/VdoDownload.swift +453 -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 +106 -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 -0
- 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,47 @@
|
|
|
1
|
+
//
|
|
2
|
+
// RCTVdoPlayerView.swift
|
|
3
|
+
// react-native-vdocipher-rn-bridge
|
|
4
|
+
//
|
|
5
|
+
// Created by Manish Gupta on 25/05/23.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import React
|
|
9
|
+
import Foundation
|
|
10
|
+
import VdoFramework
|
|
11
|
+
import AVKit
|
|
12
|
+
|
|
13
|
+
@objc(RCTVdoPlayerView)
|
|
14
|
+
class RCTVdoPlayerView: VdoCipherRNView {
|
|
15
|
+
|
|
16
|
+
var playerLayer: AVPlayerLayer?
|
|
17
|
+
|
|
18
|
+
override func setEmbedInfo(_ embedInfo: [String: Any]) {
|
|
19
|
+
super.setEmbedInfo(embedInfo)
|
|
20
|
+
EventEmitter.sharedInstance.dispatch(name: EventName.EVENT_LOADING, params: nil)
|
|
21
|
+
DispatchQueue.main.asyncAfter(deadline: .now() + 0.33 , execute: {
|
|
22
|
+
self.reactViewController().navigationController?.delegate = self
|
|
23
|
+
})
|
|
24
|
+
if embedInfo["offline"] as? Bool == true {
|
|
25
|
+
self.parseOfflineCredentials(fromInfo: embedInfo)
|
|
26
|
+
} else {
|
|
27
|
+
self.parseOnlineCredentials(fromInfo: embedInfo)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
override func playerReadyToPlay() {
|
|
32
|
+
playerLayer = AVPlayerLayer(player: player)
|
|
33
|
+
playerLayer?.frame = self.bounds
|
|
34
|
+
playerLayer?.videoGravity = .resizeAspect
|
|
35
|
+
self.layer.sublayers?
|
|
36
|
+
.filter { $0 is AVPlayerLayer }
|
|
37
|
+
.forEach { $0.removeFromSuperlayer() }
|
|
38
|
+
self.layer.addSublayer(playerLayer!)
|
|
39
|
+
super.playerReadyToPlay()
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
override func layoutSubviews() {
|
|
43
|
+
super.layoutSubviews()
|
|
44
|
+
self.playerLayer?.frame = self.bounds
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
//
|
|
2
|
+
// TrackSelection.swift
|
|
3
|
+
// react-native-vdocipher-rn-bridge
|
|
4
|
+
//
|
|
5
|
+
// Created by Manish Gupta on 14/06/23.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
import Foundation
|
|
9
|
+
import VdoFramework
|
|
10
|
+
import React
|
|
11
|
+
|
|
12
|
+
@objc(TrackSelection)
|
|
13
|
+
class TrackSelection: NSObject {
|
|
14
|
+
|
|
15
|
+
/// Current Asset
|
|
16
|
+
static var asset: VdoAsset? {
|
|
17
|
+
didSet{
|
|
18
|
+
guard let captions = TrackSelection.asset?.captions else {
|
|
19
|
+
return
|
|
20
|
+
}
|
|
21
|
+
var captionLanguages = [[String: Any]] ()
|
|
22
|
+
var counter = 1
|
|
23
|
+
for caption in captions {
|
|
24
|
+
guard let lang = caption.lang,
|
|
25
|
+
let label = caption.label,
|
|
26
|
+
let name = caption.captionName else {continue}
|
|
27
|
+
captionLanguages.append(["id": counter,
|
|
28
|
+
"language": lang,
|
|
29
|
+
"label": label,
|
|
30
|
+
"name": name])
|
|
31
|
+
counter += 1
|
|
32
|
+
}
|
|
33
|
+
TrackSelection.captionLanguagesMap = captionLanguages
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
static var captionLanguagesMap: [[String: Any]]?
|
|
37
|
+
|
|
38
|
+
@objc func getCaptionLanguages(_ callback: RCTResponseSenderBlock) {
|
|
39
|
+
// print("========= TrackSelection getCaptionLanguages called")
|
|
40
|
+
guard let captionLanguagesMap = TrackSelection.captionLanguagesMap else {
|
|
41
|
+
callback(nil)
|
|
42
|
+
return
|
|
43
|
+
}
|
|
44
|
+
callback([captionLanguagesMap])
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@objc func getSelectedCaptionLanguage(_ callback: RCTResponseSenderBlock) {
|
|
48
|
+
// print("========= TrackSelection getSelectedCaptionLanguage called")
|
|
49
|
+
guard let selectedCaption = TrackSelection.asset?.getCurrentEnabledCaption(),
|
|
50
|
+
let name = selectedCaption.captionName,
|
|
51
|
+
let selectedCaptionMap = TrackSelection.captionLanguagesMap?.first(where: {$0["name"] as? String == name}) else {
|
|
52
|
+
callback([])
|
|
53
|
+
return
|
|
54
|
+
}
|
|
55
|
+
// print("Selected Caption Map is \(selectedCaptionMap)")
|
|
56
|
+
callback([selectedCaptionMap])
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
@objc func getDuration(_ callback: RCTResponseSenderBlock) {
|
|
60
|
+
// print("========= TrackSelection getDuration called")
|
|
61
|
+
guard let duration = TrackSelection.asset?.duration else {return}
|
|
62
|
+
callback([["duration": duration]])
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//
|
|
2
|
+
// VdoCipherRNView.h
|
|
3
|
+
// Pods
|
|
4
|
+
//
|
|
5
|
+
// Created by Manish Gupta on 31/05/23.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
#ifndef VdoCipherRNView_h
|
|
9
|
+
#define VdoCipherRNView_h
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
#endif /* VdoCipherRNView_h */
|
|
13
|
+
|
|
14
|
+
#import <VdoFramework/VdoFramework.h>
|
|
15
|
+
|
|
16
|
+
@interface VdoCipherRNView: UIView
|
|
17
|
+
|
|
18
|
+
@end
|
|
@@ -0,0 +1,391 @@
|
|
|
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
|
+
private var playbackType: PlaybackType = .streaming
|
|
22
|
+
|
|
23
|
+
private var playerItemBufferEmptyObserver: NSKeyValueObservation?
|
|
24
|
+
private var playerItemBufferKeepUpObserver: NSKeyValueObservation?
|
|
25
|
+
private var playerItemBufferFullObserver: NSKeyValueObservation?
|
|
26
|
+
|
|
27
|
+
private var playerState: PlayerState = .unknown {
|
|
28
|
+
didSet{
|
|
29
|
+
if oldValue != playerState {
|
|
30
|
+
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])
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
override init(frame: CGRect) {
|
|
36
|
+
super.init(frame: frame)
|
|
37
|
+
let userDefaults: UserDefaults? = UserDefaults.init(suiteName: "com.vdocipher.ios.rn.VdoFramework")
|
|
38
|
+
userDefaults?.set(["name": "react-native", "version": VdocipherRnBridge.vdocipherRnBridgeVersionString], forKey: "rnToolkitInfo")
|
|
39
|
+
VdoCipher.setPlaybackDelegate(delegate: self)
|
|
40
|
+
VdoCipher.setUIPlayerDelegate(self)
|
|
41
|
+
EventEmitter.sharedInstance.dispatch(name: EventName.EVENT_INIT_SUCCESS, params: [Keys.EVENT_PROP_RESTORED.rawValue : false])
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
required init?(coder: NSCoder) {
|
|
45
|
+
super.init(coder: coder)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
override func willMove(toSuperview newSuperview: UIView?) {
|
|
49
|
+
super.willMove(toSuperview: newSuperview)
|
|
50
|
+
guard newSuperview != nil else {
|
|
51
|
+
return
|
|
52
|
+
}
|
|
53
|
+
// print("added to a superView \(newSuperview) reactViewController is \(self.reactViewController())")
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
override func didMoveToSuperview() {
|
|
57
|
+
super.didMoveToSuperview()
|
|
58
|
+
if self.superview == nil {
|
|
59
|
+
player?.pause()
|
|
60
|
+
self.removeObservers()
|
|
61
|
+
player?.replaceCurrentItem(with: nil)
|
|
62
|
+
player = nil
|
|
63
|
+
} /* else {
|
|
64
|
+
// print("did move to a superView, reactViewController is \(self.reactViewController())")
|
|
65
|
+
} */
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
func addObserversToPlayer()
|
|
69
|
+
{
|
|
70
|
+
NotificationCenter.default.addObserver(self,
|
|
71
|
+
selector: #selector(videoDidEnd),
|
|
72
|
+
name: NSNotification.Name.AVPlayerItemDidPlayToEndTime,
|
|
73
|
+
object: nil)
|
|
74
|
+
|
|
75
|
+
playerItemBufferEmptyObserver = self.player?.currentItem?.observe(\AVPlayerItem.isPlaybackBufferEmpty, options: [.new]) { [weak self] (_, _) in
|
|
76
|
+
guard let self = self else { return }
|
|
77
|
+
if self.playbackType == .offline || self.playerState == .buffering {
|
|
78
|
+
return
|
|
79
|
+
}
|
|
80
|
+
self.playerState = .buffering
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
playerItemBufferKeepUpObserver = self.player?.currentItem?.observe(\AVPlayerItem.isPlaybackLikelyToKeepUp, options: [.new]) { [weak self] (_, _) in
|
|
84
|
+
guard let self = self else { return }
|
|
85
|
+
if self.playerState == .ready {
|
|
86
|
+
return
|
|
87
|
+
}
|
|
88
|
+
self.playerState = .ready
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
playerItemBufferFullObserver = self.player?.currentItem?.observe(\AVPlayerItem.isPlaybackBufferFull, options: [.new]) { [weak self] (_, _) in
|
|
92
|
+
guard let self = self else { return }
|
|
93
|
+
if self.playerState == .ready {
|
|
94
|
+
return
|
|
95
|
+
}
|
|
96
|
+
self.playerState = .ready
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
progressTimer = Timer.scheduledTimer(withTimeInterval: 0.5, repeats: true, block: {_ in
|
|
100
|
+
self.sendPlayerProgress()
|
|
101
|
+
})
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
private func sendPlayerProgress() {
|
|
105
|
+
let currentTime = Int(self.player?.currentItem?.currentTime().seconds.rounded( .down) ?? 0.0 ) * 1000
|
|
106
|
+
// print("Current time send as event emitter is \(currentTime)")
|
|
107
|
+
if currentTime > 0 {
|
|
108
|
+
EventEmitter.sharedInstance.dispatch(name: .EVENT_PROGRESS, params: [Keys.EVENT_PROP_CURRENT_TIME.rawValue : currentTime])
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
func setCaptionLanguage(lanCode: String?) -> Bool {
|
|
113
|
+
var isSuccess: Bool = false
|
|
114
|
+
guard let asset = self.asset else { return isSuccess } // return false
|
|
115
|
+
if lanCode == nil {
|
|
116
|
+
isSuccess = asset.setCaption(nil)
|
|
117
|
+
return isSuccess
|
|
118
|
+
} else {
|
|
119
|
+
if let caption = asset.captions?.first(where: { $0.lang == lanCode }) {
|
|
120
|
+
isSuccess = asset.setCaption(caption)
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return isSuccess
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
func removeObservers()
|
|
127
|
+
{
|
|
128
|
+
NotificationCenter.default.removeObserver(self,
|
|
129
|
+
name: NSNotification.Name.AVPlayerItemDidPlayToEndTime,
|
|
130
|
+
object: nil)
|
|
131
|
+
|
|
132
|
+
playerItemBufferEmptyObserver?.invalidate()
|
|
133
|
+
playerItemBufferEmptyObserver = nil
|
|
134
|
+
|
|
135
|
+
playerItemBufferKeepUpObserver?.invalidate()
|
|
136
|
+
playerItemBufferKeepUpObserver = nil
|
|
137
|
+
|
|
138
|
+
playerItemBufferFullObserver?.invalidate()
|
|
139
|
+
playerItemBufferFullObserver = nil
|
|
140
|
+
|
|
141
|
+
progressTimer?.invalidate()
|
|
142
|
+
progressTimer = nil
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
func parseOfflineCredentials(fromInfo embedInfo: [String: Any]) {
|
|
146
|
+
guard let mediaId = embedInfo["mediaId"] as? String else {
|
|
147
|
+
let errorDescription = ErrorDescription(errorCode: 4101, errorMsg: "Error: 4101 Invalid video parameters. Please contact the app developer.", httpStatusCode: -1)
|
|
148
|
+
self.sendErrorEventWithDescription(errorDescription)
|
|
149
|
+
return
|
|
150
|
+
}
|
|
151
|
+
self.playbackType = .offline
|
|
152
|
+
self.initiatePlayback(withInfo: embedInfo, videoId: mediaId)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
func parseOnlineCredentials(fromInfo embedInfo: [String: Any]) {
|
|
156
|
+
guard let playbackInfo = embedInfo["playbackInfo"] as? String,
|
|
157
|
+
let otp = embedInfo["otp"] as? String,
|
|
158
|
+
let decoded = Data(base64Encoded: playbackInfo),
|
|
159
|
+
let parsed = try? JSONDecoder().decode(PlaybackInfo.self, from: decoded) else {
|
|
160
|
+
let errorDescription = ErrorDescription(errorCode: 4101, errorMsg: "Error: 4101 Invalid video parameters. Please contact the app developer.", httpStatusCode: -1)
|
|
161
|
+
self.sendErrorEventWithDescription(errorDescription)
|
|
162
|
+
return
|
|
163
|
+
}
|
|
164
|
+
self.playbackType = .streaming
|
|
165
|
+
self.initiatePlayback(withInfo: embedInfo, videoId: parsed.videoId, onlineCredentials: Credentials(otp: otp, playbackInfo: playbackInfo))
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
private func initiatePlayback(withInfo embedInfo: [String: Any], videoId: String, onlineCredentials: Credentials? = nil) {
|
|
169
|
+
let customPlayerId = embedInfo["customPlayerId"] as? String
|
|
170
|
+
let preferredCaptionsLanguage = embedInfo["preferredCaptionsLanguage"] as? String
|
|
171
|
+
let enableAutoResume = embedInfo["enableAutoResume"] as? Bool
|
|
172
|
+
if enableAutoResume == false {
|
|
173
|
+
let userDefaults: UserDefaults? = UserDefaults.init(suiteName: "com.vdocipher.ios.VdoFramework")
|
|
174
|
+
if var assetsLastPlaybackTimeSet = userDefaults?.value(forKey: "assetsLastPlaybackTimeSet") as? [String: Double] {
|
|
175
|
+
assetsLastPlaybackTimeSet[videoId] = Double(0)
|
|
176
|
+
userDefaults?.set(assetsLastPlaybackTimeSet, forKey: "assetsLastPlaybackTimeSet")
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
VdoAsset.createAsset(videoId: videoId, playerId: customPlayerId, onLoad: { asset, err in
|
|
180
|
+
DispatchQueue.main.async {
|
|
181
|
+
guard let asset = asset else {
|
|
182
|
+
if let error = err {
|
|
183
|
+
let errorDescription = ErrorDescription(errorCode: error.code, errorMsg: error.message, httpStatusCode: -1)
|
|
184
|
+
self.sendErrorEventWithDescription(errorDescription)
|
|
185
|
+
}
|
|
186
|
+
return
|
|
187
|
+
}
|
|
188
|
+
self.asset = asset
|
|
189
|
+
TrackSelection.asset = asset
|
|
190
|
+
if preferredCaptionsLanguage?.isEmpty == false {
|
|
191
|
+
DispatchQueue.main.async {
|
|
192
|
+
_ = self.setCaptionLanguage(lanCode: preferredCaptionsLanguage)
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
if let onlineCredentials = onlineCredentials {
|
|
196
|
+
asset.playOnline(otp: onlineCredentials.otp, playbackInfo: onlineCredentials.playbackInfo)
|
|
197
|
+
} else {
|
|
198
|
+
asset.playOffline()
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
})
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
@objc func videoDidEnd(notification: NSNotification) {
|
|
206
|
+
if self.playerState == .ended {
|
|
207
|
+
return
|
|
208
|
+
}
|
|
209
|
+
self.sendPlayerProgress()
|
|
210
|
+
self.playerState = .ended
|
|
211
|
+
self.playWhenReady = false
|
|
212
|
+
EventEmitter.sharedInstance.dispatch(name: .EVENT_MEDIA_ENDED, params: nil)
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
@objc func playerReadyToPlay() {
|
|
216
|
+
self.playerState = .ready
|
|
217
|
+
if self.playWhenReady == true {
|
|
218
|
+
self.player?.rate = targetPlaybackSpeed
|
|
219
|
+
} else {
|
|
220
|
+
self.player?.rate = 0
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
@objc func setEmbedInfo(_ embedInfo: [String: Any]) {
|
|
225
|
+
// print("Embed Info is \(embedInfo)")
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
@objc func setResizeMode(_ resizeMode: String) {
|
|
229
|
+
// print("Resize Mode called with value == \(resizeMode)")
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
@objc func setPlayWhenReady(_ playWhenReady: Bool) {
|
|
233
|
+
// print("playWhenReady called with value == \(playWhenReady)")
|
|
234
|
+
self.playWhenReady = playWhenReady
|
|
235
|
+
if playWhenReady == true {
|
|
236
|
+
if targetPlaybackSpeed == 0 {
|
|
237
|
+
targetPlaybackSpeed = 1.0
|
|
238
|
+
}
|
|
239
|
+
// Above Condition implies the playback was paused and play is triggered
|
|
240
|
+
// The condition is required since we need to keep the playbackSpeed in case user navigates to and fro this screen.
|
|
241
|
+
self.player?.rate = targetPlaybackSpeed
|
|
242
|
+
} else {
|
|
243
|
+
// Below on pause 'targetPlaybackSpeed' is set to 0 which implies when user navigates back to this screen playback shouldn't resume
|
|
244
|
+
self.targetPlaybackSpeed = 0
|
|
245
|
+
self.player?.rate = 0
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
@objc func setPlaybackSpeed(_ speed: Float) {
|
|
250
|
+
// print("playbackSpeed called with value == \(speed)")
|
|
251
|
+
self.targetPlaybackSpeed = speed
|
|
252
|
+
self.player?.rate = speed
|
|
253
|
+
EventEmitter.sharedInstance.dispatch(name: .EVENT_PLAYBACK_SPEED_CHANGED, params: [Keys.EVENT_PROP_PLAYBACK_SPEED.rawValue : speed])
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
@objc func setSeek(_ seekTime: Int) {
|
|
257
|
+
// print("seek called with value == \(seekTime)")
|
|
258
|
+
self.player?.seek(to: CMTime(value: CMTimeValue(seekTime), timescale: 1000))
|
|
259
|
+
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
@objc func setCaptionLanguage(_ caption: [String: Any]) {
|
|
263
|
+
// print("========= TrackSelection setCaptionLanguage called")
|
|
264
|
+
guard let asset = TrackSelection.asset,
|
|
265
|
+
let captions = asset.captions,
|
|
266
|
+
let selectedCaptionName = caption["name"] as? String,
|
|
267
|
+
let selectedCaptionObject = captions.first(where: {$0.captionName ?? "" == selectedCaptionName}) else {return}
|
|
268
|
+
if (asset.setCaption(selectedCaptionObject) == true) {
|
|
269
|
+
guard let selectedCaption = TrackSelection.asset?.getCurrentEnabledCaption(),
|
|
270
|
+
let name = selectedCaption.captionName,
|
|
271
|
+
let selectedCaptionMap = TrackSelection.captionLanguagesMap?.first(where: {$0["name"] as? String == name}) else {
|
|
272
|
+
return
|
|
273
|
+
}
|
|
274
|
+
EventEmitter.sharedInstance.dispatch(name: .EVENT_TRACKS_CHANGED, params: [Keys.EVENT_PROP_AVAILABLE_TRACKS.rawValue : TrackSelection.captionLanguagesMap ?? [], Keys.EVENT_PROP_SELECTED_TRACKS.rawValue: [selectedCaptionMap]])
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
@objc func setDisableCaptions(_ val: Int) {
|
|
279
|
+
// print("========= TrackSelection disableCaptions called")
|
|
280
|
+
if (TrackSelection.asset?.setCaption(nil) == true) {
|
|
281
|
+
EventEmitter.sharedInstance.dispatch(name: .EVENT_TRACKS_CHANGED, params: [Keys.EVENT_PROP_AVAILABLE_TRACKS.rawValue : TrackSelection.captionLanguagesMap ?? []])
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
func sendErrorEventWithDescription(_ errorDescription: ErrorDescription) {
|
|
286
|
+
if let errorInfo = getJSONEncodedEventDictionary(info: errorDescription) {
|
|
287
|
+
EventEmitter.sharedInstance.dispatch(name: .EVENT_LOAD_ERROR, params: [Keys.EVENT_PROP_ERROR_DESCRIPTION.rawValue : errorInfo])
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
func getJSONEncodedEventDictionary<T>(info eventInfo: T) -> [String: Any]? where T : Encodable {
|
|
292
|
+
let jsonEncoder = JSONEncoder()
|
|
293
|
+
guard let encoded = try? jsonEncoder.encode(eventInfo),
|
|
294
|
+
let info = try? JSONSerialization.jsonObject(with: encoded, options: .allowFragments) as? [String: Any] else {
|
|
295
|
+
EventEmitter.sharedInstance.dispatch(name: .EVENT_LOAD_ERROR,
|
|
296
|
+
params: [Keys.EVENT_PROP_ERROR_DESCRIPTION.rawValue : EventEmitter.sharedInstance.errorParsingFailDefaultErrInfo])
|
|
297
|
+
return nil
|
|
298
|
+
}
|
|
299
|
+
return info
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
extension VdoCipherRNView: AssetPlaybackDelegate {
|
|
304
|
+
func streamLoadError(error: VdoError) {
|
|
305
|
+
let errorDescription = ErrorDescription(errorCode: error.code, errorMsg: error.message, httpStatusCode: -1)
|
|
306
|
+
self.sendErrorEventWithDescription(errorDescription)
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
func streamPlaybackManager(playerReadyToPlay player: AVPlayer) {
|
|
310
|
+
self.playerReadyToPlay()
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
func streamPlaybackManager(playerCurrentItemDidChange player: AVPlayer) {
|
|
314
|
+
self.setUpPlayer(player)
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
func setUpPlayer(_ player: AVPlayer) {
|
|
318
|
+
if isLoaded == true {
|
|
319
|
+
return
|
|
320
|
+
}
|
|
321
|
+
isLoaded = true
|
|
322
|
+
self.player = player
|
|
323
|
+
self.removeObservers()
|
|
324
|
+
self.addObserversToPlayer()
|
|
325
|
+
|
|
326
|
+
guard let asset = asset else { return }
|
|
327
|
+
let mInfo = Media(mediaId: asset.videoId,
|
|
328
|
+
type: playbackType.rawValue,
|
|
329
|
+
title: asset.title ?? "",
|
|
330
|
+
description: asset.description,
|
|
331
|
+
duration: (Int(asset.duration ?? 0.0) * 1000) )
|
|
332
|
+
guard let eventInfo = getJSONEncodedEventDictionary(info: mInfo) else { return }
|
|
333
|
+
EventEmitter.sharedInstance.dispatch(name: EventName.EVENT_LOADED,
|
|
334
|
+
params: [Keys.EVENT_PROP_MEDIA_INFO.rawValue : eventInfo])
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
extension VdoCipherRNView: VdoPlayerViewControllerDelegate {
|
|
339
|
+
func didTapEnterFullScreen(for id: String) {
|
|
340
|
+
EventEmitter.sharedInstance.dispatch(name: .EVENT_ENTER_FULLSCREEN, params: nil)
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
func didTapExitFullScreen(for id: String) {
|
|
344
|
+
EventEmitter.sharedInstance.dispatch(name: .EVENT_EXIT_FULLSCREEN, params: nil)
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
func didChangePlayerRate(for id: String, to speed: Float) {
|
|
348
|
+
self.targetPlaybackSpeed = speed
|
|
349
|
+
EventEmitter.sharedInstance.dispatch(name: .EVENT_PLAYBACK_SPEED_CHANGED, params: [Keys.EVENT_PROP_PLAYBACK_SPEED.rawValue : speed])
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
func didChangeCaption(for id: String, to name: String, code: String) {
|
|
353
|
+
guard let selectedCaptionMap = TrackSelection.captionLanguagesMap?.first(where: {$0["language"] as! String == code}) else {
|
|
354
|
+
return
|
|
355
|
+
}
|
|
356
|
+
EventEmitter.sharedInstance.dispatch(name: .EVENT_TRACKS_CHANGED, params: [Keys.EVENT_PROP_AVAILABLE_TRACKS.rawValue : TrackSelection.captionLanguagesMap ?? [], Keys.EVENT_PROP_SELECTED_TRACKS.rawValue: [selectedCaptionMap]])
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
extension VdoCipherRNView: UINavigationControllerDelegate {
|
|
361
|
+
|
|
362
|
+
func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {
|
|
363
|
+
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {
|
|
367
|
+
guard let parentController = self.reactViewController() else {return}
|
|
368
|
+
if viewController != parentController {
|
|
369
|
+
player?.pause()
|
|
370
|
+
} else if viewController == parentController {
|
|
371
|
+
player?.rate = targetPlaybackSpeed
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
private enum PlayerState : String {
|
|
377
|
+
case buffering = "buffering",
|
|
378
|
+
ready = "ready",
|
|
379
|
+
ended = "ended",
|
|
380
|
+
unknown = "unknown"
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
fileprivate struct Credentials {
|
|
384
|
+
let otp: String
|
|
385
|
+
let playbackInfo: String
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
private enum PlaybackType: String {
|
|
389
|
+
case streaming
|
|
390
|
+
case offline
|
|
391
|
+
}
|