react-native-tpstreams 1.0.1 → 1.0.2
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.
|
@@ -21,7 +21,7 @@ Pod::Spec.new do |s|
|
|
|
21
21
|
'DEFINES_MODULE' => 'YES',
|
|
22
22
|
'CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES' => 'YES'
|
|
23
23
|
}
|
|
24
|
-
s.dependency "TPStreamsSDK" , "1.2.
|
|
24
|
+
s.dependency "TPStreamsSDK" , "1.2.8"
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
# Ensure the module is not built as a framework to avoid bridging header conflicts
|
|
@@ -11,15 +11,26 @@ private enum PlayerConstants {
|
|
|
11
11
|
static let statusUnknown = "Unknown"
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
protocol TokenRequestDelegate: AnyObject {
|
|
15
|
+
func requestToken(for assetId: String, completion: @escaping (String?) -> Void)
|
|
16
|
+
}
|
|
17
|
+
|
|
14
18
|
@objc(TPStreamsDownload)
|
|
15
19
|
class TPStreamsDownloadModule: RCTEventEmitter, TPStreamsDownloadDelegate {
|
|
16
20
|
|
|
17
21
|
private let downloadManager = TPStreamsDownloadManager.shared
|
|
18
22
|
private var isListening = false
|
|
23
|
+
private var tokenDelegate: TokenRequestDelegate?
|
|
24
|
+
static var shared: TPStreamsDownloadModule?
|
|
19
25
|
|
|
20
26
|
override init() {
|
|
21
27
|
super.init()
|
|
22
28
|
downloadManager.setTPStreamsDownloadDelegate(tpStreamsDownloadDelegate: self)
|
|
29
|
+
TPStreamsDownloadModule.shared = self
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
func setAccessTokenDelegate(_ delegate: TokenRequestDelegate) {
|
|
33
|
+
self.tokenDelegate = delegate
|
|
23
34
|
}
|
|
24
35
|
|
|
25
36
|
@objc
|
|
@@ -86,6 +97,14 @@ class TPStreamsDownloadModule: RCTEventEmitter, TPStreamsDownloadDelegate {
|
|
|
86
97
|
notifyDownloadsChange()
|
|
87
98
|
}
|
|
88
99
|
}
|
|
100
|
+
|
|
101
|
+
func onRequestNewAccessToken(assetId: String, completion: @escaping (String?) -> Void) {
|
|
102
|
+
if let delegate = tokenDelegate {
|
|
103
|
+
delegate.requestToken(for: assetId, completion: completion)
|
|
104
|
+
} else {
|
|
105
|
+
completion(nil)
|
|
106
|
+
}
|
|
107
|
+
}
|
|
89
108
|
|
|
90
109
|
private func notifyDownloadsChange() {
|
|
91
110
|
DispatchQueue.main.async { [weak self] in
|
|
@@ -13,10 +13,15 @@ class TPStreamsModule: NSObject {
|
|
|
13
13
|
DispatchQueue.main.async {
|
|
14
14
|
TPStreamsSDK.initialize(withOrgCode: organizationId as String)
|
|
15
15
|
self.isInitialized = true
|
|
16
|
+
self.initializeDownloadModule()
|
|
16
17
|
}
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
20
|
|
|
21
|
+
private func initializeDownloadModule() {
|
|
22
|
+
let _ = TPStreamsDownloadModule()
|
|
23
|
+
}
|
|
24
|
+
|
|
20
25
|
@objc
|
|
21
26
|
static func requiresMainQueueSetup() -> Bool {
|
|
22
27
|
return true
|
|
@@ -31,6 +31,8 @@ class TPStreamsRNPlayerView: UIView {
|
|
|
31
31
|
@objc var onIsLoadingChanged: RCTDirectEventBlock?
|
|
32
32
|
@objc var onError: RCTDirectEventBlock?
|
|
33
33
|
@objc var onAccessTokenExpired: RCTDirectEventBlock?
|
|
34
|
+
|
|
35
|
+
private var pendingTokenCompletion: ((String?) -> Void)?
|
|
34
36
|
|
|
35
37
|
override init(frame: CGRect) {
|
|
36
38
|
super.init(frame: frame)
|
|
@@ -73,7 +75,7 @@ class TPStreamsRNPlayerView: UIView {
|
|
|
73
75
|
setupScheduled = false
|
|
74
76
|
return
|
|
75
77
|
}
|
|
76
|
-
|
|
78
|
+
setupTokenDelegate()
|
|
77
79
|
configurePlayerView()
|
|
78
80
|
observePlayerChanges()
|
|
79
81
|
setupScheduled = false
|
|
@@ -81,14 +83,19 @@ class TPStreamsRNPlayerView: UIView {
|
|
|
81
83
|
|
|
82
84
|
private func cleanupPlayer() {
|
|
83
85
|
removeObservers()
|
|
86
|
+
player?.pause()
|
|
87
|
+
|
|
84
88
|
playerViewController?.view.removeFromSuperview()
|
|
85
89
|
playerViewController?.removeFromParent()
|
|
86
90
|
playerViewController = nil
|
|
91
|
+
|
|
92
|
+
player?.replaceCurrentItem(with: nil)
|
|
87
93
|
player = nil
|
|
88
94
|
}
|
|
89
95
|
|
|
90
96
|
private func removeObservers() {
|
|
91
97
|
playerStatusObserver?.invalidate()
|
|
98
|
+
playerStatusObserver = nil
|
|
92
99
|
}
|
|
93
100
|
|
|
94
101
|
private func createOfflinePlayer() -> TPAVPlayer? {
|
|
@@ -173,6 +180,10 @@ class TPStreamsRNPlayerView: UIView {
|
|
|
173
180
|
}
|
|
174
181
|
}
|
|
175
182
|
|
|
183
|
+
private func setupTokenDelegate() {
|
|
184
|
+
TPStreamsDownloadModule.shared?.setAccessTokenDelegate(self)
|
|
185
|
+
}
|
|
186
|
+
|
|
176
187
|
private func parseMetadataJSON(from jsonString: NSString?) -> [String: String]? {
|
|
177
188
|
guard let metadataString = jsonString as String? else { return nil }
|
|
178
189
|
|
|
@@ -230,11 +241,29 @@ class TPStreamsRNPlayerView: UIView {
|
|
|
230
241
|
}
|
|
231
242
|
|
|
232
243
|
@objc func setNewAccessToken(_ newToken: String) {
|
|
233
|
-
|
|
234
|
-
|
|
244
|
+
pendingTokenCompletion?(newToken)
|
|
245
|
+
pendingTokenCompletion = nil
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
override func willMove(toSuperview newSuperview: UIView?) {
|
|
249
|
+
if newSuperview == nil {
|
|
250
|
+
cleanupPlayer()
|
|
251
|
+
}
|
|
252
|
+
super.willMove(toSuperview: newSuperview)
|
|
235
253
|
}
|
|
236
254
|
|
|
237
255
|
deinit {
|
|
238
|
-
|
|
256
|
+
cleanupPlayer()
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
extension TPStreamsRNPlayerView: TokenRequestDelegate {
|
|
261
|
+
func requestToken(for assetId: String, completion: @escaping (String?) -> Void) {
|
|
262
|
+
guard let onAccessTokenExpired = onAccessTokenExpired else {
|
|
263
|
+
completion(nil)
|
|
264
|
+
return
|
|
265
|
+
}
|
|
266
|
+
pendingTokenCompletion = completion
|
|
267
|
+
onAccessTokenExpired(["videoId": assetId])
|
|
239
268
|
}
|
|
240
269
|
}
|
|
@@ -34,5 +34,6 @@ RCT_EXTERN_METHOD(getCurrentPosition:(nonnull NSNumber *)node)
|
|
|
34
34
|
RCT_EXTERN_METHOD(getDuration:(nonnull NSNumber *)node)
|
|
35
35
|
RCT_EXTERN_METHOD(isPlaying:(nonnull NSNumber *)node)
|
|
36
36
|
RCT_EXTERN_METHOD(getPlaybackSpeed:(nonnull NSNumber *)node)
|
|
37
|
+
RCT_EXTERN_METHOD(setNewAccessToken:(nonnull NSNumber *)node newToken:(nonnull NSString *)newToken)
|
|
37
38
|
|
|
38
39
|
@end
|