vdocipher-rn-bridge 1.22.6 → 2.0.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/VdoPlayerSupportView.tsx +12 -70
- package/VdoPlayerUIView.tsx +29 -90
- package/VdoPlayerView.tsx +36 -73
- package/android/build.gradle +23 -4
- package/android/src/main/AndroidManifest.xml +1 -2
- package/android/src/main/java/com/vdocipher/rnbridge/PlayerViewRegistry.java +34 -0
- package/android/src/main/java/com/vdocipher/rnbridge/ReactVdoPlayerUIView.java +7 -11
- package/android/src/main/java/com/vdocipher/rnbridge/{ReactVdoPlayerUIViewManager.java → ReactVdoPlayerUIViewManagerImpl.java} +66 -80
- package/android/src/main/java/com/vdocipher/rnbridge/ReactVdoPlayerView.java +8 -12
- package/android/src/main/java/com/vdocipher/rnbridge/{ReactVdoPlayerViewManager.java → ReactVdoPlayerViewManagerImpl.java} +61 -75
- package/android/src/main/java/com/vdocipher/rnbridge/TrackSelectionModuleImpl.java +64 -0
- package/android/src/main/java/com/vdocipher/rnbridge/Utils.java +27 -0
- package/android/src/main/java/com/vdocipher/rnbridge/{VdoDownloadModule.java → VdoDownloadModuleImpl.java} +23 -50
- package/android/src/main/java/com/vdocipher/rnbridge/VdoEventEmitter.java +51 -17
- package/android/src/main/java/com/vdocipher/rnbridge/VdoPlayerModuleImpl.java +28 -0
- package/android/src/main/java/com/vdocipher/rnbridge/{VdoPlayerSettingsModule.java → VdoPlayerSettingsModuleImpl.java} +3 -8
- package/android/src/main/java/com/vdocipher/rnbridge/{VdoPreCacheManagerModule.java → VdoPreCacheManagerModuleImpl.java} +3 -10
- package/android/src/main/java/com/vdocipher/rnbridge/{VdocipherRnBridgeModule.java → VdocipherRnBridgeModuleImpl.java} +5 -16
- package/android/src/main/java/com/vdocipher/rnbridge/VdocipherRnBridgePackage.java +13 -27
- package/android/src/newarch/java/com/vdocipher/rnbridge/ReactVdoPlayerUIViewManager.java +195 -0
- package/android/src/newarch/java/com/vdocipher/rnbridge/ReactVdoPlayerViewManager.java +174 -0
- package/android/src/newarch/java/com/vdocipher/rnbridge/TrackSelectionModule.java +61 -0
- package/android/src/newarch/java/com/vdocipher/rnbridge/VdoDownloadModule.java +129 -0
- package/android/src/newarch/java/com/vdocipher/rnbridge/VdoPlayerModule.java +29 -0
- package/android/src/newarch/java/com/vdocipher/rnbridge/VdoPlayerSettingsModule.java +42 -0
- package/android/src/newarch/java/com/vdocipher/rnbridge/VdoPreCacheManagerModule.java +43 -0
- package/android/src/newarch/java/com/vdocipher/rnbridge/VdocipherRnBridgeModule.java +44 -0
- package/android/src/oldarch/java/com/vdocipher/rnbridge/ReactVdoPlayerUIViewManager.java +114 -0
- package/android/src/oldarch/java/com/vdocipher/rnbridge/ReactVdoPlayerViewManager.java +109 -0
- package/android/src/oldarch/java/com/vdocipher/rnbridge/TrackSelectionModule.java +59 -0
- package/android/src/oldarch/java/com/vdocipher/rnbridge/VdoDownloadModule.java +132 -0
- package/android/src/oldarch/java/com/vdocipher/rnbridge/VdoPlayerModule.java +29 -0
- package/android/src/oldarch/java/com/vdocipher/rnbridge/VdoPlayerSettingsModule.java +40 -0
- package/android/src/oldarch/java/com/vdocipher/rnbridge/VdoPreCacheManagerModule.java +40 -0
- package/android/src/oldarch/java/com/vdocipher/rnbridge/VdocipherRnBridgeModule.java +40 -0
- package/downloads.ts +5 -5
- package/ios/AssetList.swift +27 -0
- package/ios/RCTVdoPlayerUIView.h +4 -4
- package/ios/RCTVdoPlayerUIView.swift +2 -1
- package/ios/RCTVdoPlayerUIViewComponentView.mm +127 -0
- package/ios/RCTVdoPlayerView.swift +1 -0
- package/ios/RCTVdoPlayerViewComponentView.mm +127 -0
- package/ios/VdoCipherRNView.h +16 -3
- package/ios/VdoCipherRNView.swift +45 -9
- package/ios/VdoDownload.swift +74 -76
- package/ios/VdoPlayerCommandDispatch.h +52 -0
- package/ios/VdoPreCacheManager.swift +1 -1
- package/ios/VdocipherRnBridgeViewManager.mm +234 -0
- package/ios/VdocipherRnBridgeViewManager.swift +4 -4
- package/package.json +46 -3
- package/react-native-vdocipher-rn-bridge.podspec +1 -1
- package/specs/NativeTrackSelection.ts +38 -0
- package/specs/NativeVdoDownload.ts +76 -0
- package/specs/NativeVdoEventEmitter.ts +12 -0
- package/specs/NativeVdoPlayer.ts +11 -0
- package/specs/NativeVdoPlayerSettings.ts +13 -0
- package/specs/NativeVdoPreCacheManager.ts +12 -0
- package/specs/NativeVdocipherRnBridge.ts +11 -0
- package/specs/RCTVdoPlayerUIViewNativeComponent.ts +93 -0
- package/specs/RCTVdoPlayerViewNativeComponent.ts +84 -0
- package/tsconfig.json +1 -1
- package/type.ts +84 -90
- package/android/src/main/java/com/vdocipher/rnbridge/TrackSelectionModule.java +0 -126
- package/android/src/main/java/com/vdocipher/rnbridge/VdoPlayerModule.java +0 -54
- package/ios/VdocipherRnBridgeViewManager.m +0 -126
package/ios/RCTVdoPlayerUIView.h
CHANGED
|
@@ -5,15 +5,15 @@
|
|
|
5
5
|
// Created by Manish Gupta on 22/05/23.
|
|
6
6
|
//
|
|
7
7
|
|
|
8
|
-
|
|
9
8
|
#import "VdoCipherRNView.h"
|
|
10
9
|
|
|
11
10
|
#ifndef RCTVdoPlayerUIView_h
|
|
12
11
|
#define RCTVdoPlayerUIView_h
|
|
13
12
|
|
|
14
|
-
|
|
15
|
-
#endif /* RCTVdoPlayerUIView_h */
|
|
16
|
-
|
|
17
13
|
@interface RCTVdoPlayerUIView : VdoCipherRNView
|
|
18
14
|
|
|
15
|
+
- (void)setFullscreen:(BOOL)val;
|
|
16
|
+
|
|
19
17
|
@end
|
|
18
|
+
|
|
19
|
+
#endif /* RCTVdoPlayerUIView_h */
|
|
@@ -16,8 +16,9 @@ class RCTVdoPlayerUIView: VdoCipherRNView {
|
|
|
16
16
|
var activityView: UIActivityIndicatorView?
|
|
17
17
|
|
|
18
18
|
override func setEmbedInfo(_ embedInfo: [String: Any]) {
|
|
19
|
+
guard shouldApplyEmbedInfo(embedInfo) else { return }
|
|
19
20
|
super.setEmbedInfo(embedInfo)
|
|
20
|
-
|
|
21
|
+
|
|
21
22
|
EventEmitter.sharedInstance.dispatch(name: EventName.EVENT_LOADING, params: nil)
|
|
22
23
|
if embedInfo["offline"] as? Bool == true {
|
|
23
24
|
self.parseOfflineCredentials(fromInfo: embedInfo)
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
#ifdef RCT_NEW_ARCH_ENABLED
|
|
2
|
+
|
|
3
|
+
#import <React/RCTViewComponentView.h>
|
|
4
|
+
#import <React/RCTFabricComponentsPlugins.h>
|
|
5
|
+
|
|
6
|
+
#include <react/renderer/components/VdocipherRnBridgeSpecs/ComponentDescriptors.h>
|
|
7
|
+
#include <react/renderer/components/VdocipherRnBridgeSpecs/EventEmitters.h>
|
|
8
|
+
#include <react/renderer/components/VdocipherRnBridgeSpecs/Props.h>
|
|
9
|
+
|
|
10
|
+
#import "RCTVdoPlayerUIView.h"
|
|
11
|
+
#import "VdoPlayerCommandDispatch.h"
|
|
12
|
+
|
|
13
|
+
using namespace facebook::react;
|
|
14
|
+
|
|
15
|
+
// ---------------------------------------------------------------------------
|
|
16
|
+
// Fabric component view for RCTVdoPlayerUIView (player with native controls).
|
|
17
|
+
// The existing RCTVdoPlayerUIView Swift class contains all playback logic and
|
|
18
|
+
// is used as the contentView — equivalent to Android's newarch ViewManager
|
|
19
|
+
// delegating to the shared Impl class.
|
|
20
|
+
// ---------------------------------------------------------------------------
|
|
21
|
+
|
|
22
|
+
@interface RCTVdoPlayerUIViewComponentView : RCTViewComponentView
|
|
23
|
+
@end
|
|
24
|
+
|
|
25
|
+
@implementation RCTVdoPlayerUIViewComponentView {
|
|
26
|
+
RCTVdoPlayerUIView *_view;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
+ (ComponentDescriptorProvider)componentDescriptorProvider {
|
|
30
|
+
return concreteComponentDescriptorProvider<VdoPlayerUIViewComponentDescriptor>();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
- (instancetype)initWithFrame:(CGRect)frame {
|
|
34
|
+
if (self = [super initWithFrame:frame]) {
|
|
35
|
+
static const auto defaultProps = std::make_shared<const VdoPlayerUIViewProps>();
|
|
36
|
+
_props = defaultProps;
|
|
37
|
+
_view = [[RCTVdoPlayerUIView alloc] initWithFrame:frame];
|
|
38
|
+
self.contentView = _view;
|
|
39
|
+
}
|
|
40
|
+
return self;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// MARK: - Props
|
|
44
|
+
|
|
45
|
+
- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps {
|
|
46
|
+
const auto &oldViewProps = *std::static_pointer_cast<const VdoPlayerUIViewProps>(_props);
|
|
47
|
+
const auto &newViewProps = *std::static_pointer_cast<const VdoPlayerUIViewProps>(props);
|
|
48
|
+
|
|
49
|
+
{
|
|
50
|
+
NSMutableDictionary *embedInfoDict = [NSMutableDictionary new];
|
|
51
|
+
auto const &ei = newViewProps.embedInfo;
|
|
52
|
+
|
|
53
|
+
auto addStr = ^(NSString *key, const std::string &val) {
|
|
54
|
+
if (!val.empty()) embedInfoDict[key] = [NSString stringWithUTF8String:val.c_str()];
|
|
55
|
+
};
|
|
56
|
+
auto addOptStr = ^(NSString *key, const std::optional<std::string> &val) {
|
|
57
|
+
if (val.has_value() && !val.value().empty())
|
|
58
|
+
embedInfoDict[key] = [NSString stringWithUTF8String:val.value().c_str()];
|
|
59
|
+
};
|
|
60
|
+
auto addOptBool = ^(NSString *key, const std::optional<bool> &val) {
|
|
61
|
+
if (val.has_value()) embedInfoDict[key] = @(val.value());
|
|
62
|
+
};
|
|
63
|
+
auto addOptInt = ^(NSString *key, const std::optional<int> &val) {
|
|
64
|
+
if (val.has_value() && val.value() != 0) embedInfoDict[key] = @(val.value());
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
addStr(@"otp", ei.otp);
|
|
68
|
+
addStr(@"playbackInfo", ei.playbackInfo);
|
|
69
|
+
addStr(@"token", ei.token);
|
|
70
|
+
addStr(@"mediaId", ei.mediaId);
|
|
71
|
+
addStr(@"mediaUrl", ei.mediaUrl);
|
|
72
|
+
addOptStr(@"licenseUrl", ei.licenseUrl);
|
|
73
|
+
embedInfoDict[@"offline"] = @(ei.offline);
|
|
74
|
+
addOptBool(@"forceLowestBitrate", ei.forceLowestBitrate);
|
|
75
|
+
addOptBool(@"forceHighestSupportedBitrate", ei.forceHighestSupportedBitrate);
|
|
76
|
+
addOptInt(@"maxVideoBitrateKbps", ei.maxVideoBitrateKbps);
|
|
77
|
+
addOptBool(@"enableAutoResume", ei.enableAutoResume);
|
|
78
|
+
addOptStr(@"preferredCaptionsLanguage", ei.preferredCaptionsLanguage);
|
|
79
|
+
addOptStr(@"playerConfig", ei.playerConfig);
|
|
80
|
+
addOptStr(@"customPlayerId", ei.customPlayerId);
|
|
81
|
+
addOptBool(@"setPictureInPictureSupport", ei.setPictureInPictureSupport);
|
|
82
|
+
addOptInt(@"resumeTimeMs", ei.resumeTimeMs);
|
|
83
|
+
embedInfoDict[@"allowAdbDebugging"] = @(ei.allowAdbDebugging);
|
|
84
|
+
addOptInt(@"clipStartInMs", ei.clipStartInMs);
|
|
85
|
+
addOptInt(@"clipEndInMs", ei.clipEndInMs);
|
|
86
|
+
addOptBool(@"clipped", ei.clipped);
|
|
87
|
+
addOptStr(@"clipMarkerColor", ei.clipMarkerColor);
|
|
88
|
+
|
|
89
|
+
// Dedup of unchanged embedInfo is handled natively in VdoCipherRNView.setEmbedInfo
|
|
90
|
+
// (covers both arches), so just forward it here.
|
|
91
|
+
if (embedInfoDict.count > 0) {
|
|
92
|
+
[_view setEmbedInfo:embedInfoDict];
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (newViewProps.resizeMode != oldViewProps.resizeMode && !newViewProps.resizeMode.empty()) {
|
|
97
|
+
[_view setResizeMode:[NSString stringWithUTF8String:newViewProps.resizeMode.c_str()]];
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (newViewProps.autoPlay != oldViewProps.autoPlay) {
|
|
101
|
+
[_view setAutoPlay:newViewProps.autoPlay];
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
[super updateProps:props oldProps:oldProps];
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// MARK: - Commands
|
|
108
|
+
|
|
109
|
+
- (void)handleCommand:(const NSString *)commandName args:(const NSArray *)args {
|
|
110
|
+
VdoHandleUIPlayerCommand(_view, commandName, args);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Fabric recycles this view instead of detaching it, so the Swift view's
|
|
114
|
+
// didMoveToSuperview(nil) teardown never runs. Tear down the player here.
|
|
115
|
+
- (void)prepareForRecycle {
|
|
116
|
+
[super prepareForRecycle];
|
|
117
|
+
[_view cleanup];
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
@end
|
|
121
|
+
|
|
122
|
+
// Called by the codegen-generated FabricComponents plugin to register this view.
|
|
123
|
+
Class<RCTComponentViewProtocol> RCTVdoPlayerUIViewCls(void) {
|
|
124
|
+
return RCTVdoPlayerUIViewComponentView.class;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
#endif // RCT_NEW_ARCH_ENABLED
|
|
@@ -16,6 +16,7 @@ class RCTVdoPlayerView: VdoCipherRNView {
|
|
|
16
16
|
var playerLayer: AVPlayerLayer?
|
|
17
17
|
|
|
18
18
|
override func setEmbedInfo(_ embedInfo: [String: Any]) {
|
|
19
|
+
guard shouldApplyEmbedInfo(embedInfo) else { return }
|
|
19
20
|
super.setEmbedInfo(embedInfo)
|
|
20
21
|
EventEmitter.sharedInstance.dispatch(name: EventName.EVENT_LOADING, params: nil)
|
|
21
22
|
if embedInfo["offline"] as? Bool == true {
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
#ifdef RCT_NEW_ARCH_ENABLED
|
|
2
|
+
|
|
3
|
+
#import <React/RCTViewComponentView.h>
|
|
4
|
+
#import <React/RCTFabricComponentsPlugins.h>
|
|
5
|
+
|
|
6
|
+
#include <react/renderer/components/VdocipherRnBridgeSpecs/ComponentDescriptors.h>
|
|
7
|
+
#include <react/renderer/components/VdocipherRnBridgeSpecs/EventEmitters.h>
|
|
8
|
+
#include <react/renderer/components/VdocipherRnBridgeSpecs/Props.h>
|
|
9
|
+
|
|
10
|
+
#import "RCTVdoPlayerView.h"
|
|
11
|
+
#import "VdoPlayerCommandDispatch.h"
|
|
12
|
+
|
|
13
|
+
using namespace facebook::react;
|
|
14
|
+
|
|
15
|
+
// ---------------------------------------------------------------------------
|
|
16
|
+
// Fabric component view for RCTVdoPlayerView (player without native controls).
|
|
17
|
+
// The existing RCTVdoPlayerView Swift class contains all playback logic and
|
|
18
|
+
// is used as the contentView — equivalent to Android's newarch ViewManager
|
|
19
|
+
// delegating to the shared Impl class.
|
|
20
|
+
// ---------------------------------------------------------------------------
|
|
21
|
+
|
|
22
|
+
@interface RCTVdoPlayerViewComponentView : RCTViewComponentView
|
|
23
|
+
@end
|
|
24
|
+
|
|
25
|
+
@implementation RCTVdoPlayerViewComponentView {
|
|
26
|
+
RCTVdoPlayerView *_view;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
+ (ComponentDescriptorProvider)componentDescriptorProvider {
|
|
30
|
+
return concreteComponentDescriptorProvider<VdoPlayerViewComponentDescriptor>();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
- (instancetype)initWithFrame:(CGRect)frame {
|
|
34
|
+
if (self = [super initWithFrame:frame]) {
|
|
35
|
+
static const auto defaultProps = std::make_shared<const VdoPlayerViewProps>();
|
|
36
|
+
_props = defaultProps;
|
|
37
|
+
_view = [[RCTVdoPlayerView alloc] initWithFrame:frame];
|
|
38
|
+
self.contentView = _view;
|
|
39
|
+
}
|
|
40
|
+
return self;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// MARK: - Props
|
|
44
|
+
|
|
45
|
+
- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps {
|
|
46
|
+
const auto &newViewProps = *std::static_pointer_cast<const VdoPlayerViewProps>(props);
|
|
47
|
+
const auto &oldViewProps = *std::static_pointer_cast<const VdoPlayerViewProps>(_props);
|
|
48
|
+
|
|
49
|
+
{
|
|
50
|
+
NSMutableDictionary *embedInfoDict = [NSMutableDictionary new];
|
|
51
|
+
auto const &ei = newViewProps.embedInfo;
|
|
52
|
+
|
|
53
|
+
auto addStr = ^(NSString *key, const std::string &val) {
|
|
54
|
+
if (!val.empty()) embedInfoDict[key] = [NSString stringWithUTF8String:val.c_str()];
|
|
55
|
+
};
|
|
56
|
+
auto addOptStr = ^(NSString *key, const std::optional<std::string> &val) {
|
|
57
|
+
if (val.has_value() && !val.value().empty())
|
|
58
|
+
embedInfoDict[key] = [NSString stringWithUTF8String:val.value().c_str()];
|
|
59
|
+
};
|
|
60
|
+
auto addOptBool = ^(NSString *key, const std::optional<bool> &val) {
|
|
61
|
+
if (val.has_value()) embedInfoDict[key] = @(val.value());
|
|
62
|
+
};
|
|
63
|
+
auto addOptInt = ^(NSString *key, const std::optional<int> &val) {
|
|
64
|
+
if (val.has_value() && val.value() != 0) embedInfoDict[key] = @(val.value());
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
addStr(@"otp", ei.otp);
|
|
68
|
+
addStr(@"playbackInfo", ei.playbackInfo);
|
|
69
|
+
addStr(@"token", ei.token);
|
|
70
|
+
addStr(@"mediaId", ei.mediaId);
|
|
71
|
+
addStr(@"mediaUrl", ei.mediaUrl);
|
|
72
|
+
addOptStr(@"licenseUrl", ei.licenseUrl);
|
|
73
|
+
embedInfoDict[@"offline"] = @(ei.offline);
|
|
74
|
+
addOptBool(@"forceLowestBitrate", ei.forceLowestBitrate);
|
|
75
|
+
addOptBool(@"forceHighestSupportedBitrate", ei.forceHighestSupportedBitrate);
|
|
76
|
+
addOptInt(@"maxVideoBitrateKbps", ei.maxVideoBitrateKbps);
|
|
77
|
+
addOptBool(@"enableAutoResume", ei.enableAutoResume);
|
|
78
|
+
addOptStr(@"preferredCaptionsLanguage", ei.preferredCaptionsLanguage);
|
|
79
|
+
addOptStr(@"playerConfig", ei.playerConfig);
|
|
80
|
+
addOptStr(@"customPlayerId", ei.customPlayerId);
|
|
81
|
+
addOptBool(@"setPictureInPictureSupport", ei.setPictureInPictureSupport);
|
|
82
|
+
addOptInt(@"resumeTimeMs", ei.resumeTimeMs);
|
|
83
|
+
embedInfoDict[@"allowAdbDebugging"] = @(ei.allowAdbDebugging);
|
|
84
|
+
addOptInt(@"clipStartInMs", ei.clipStartInMs);
|
|
85
|
+
addOptInt(@"clipEndInMs", ei.clipEndInMs);
|
|
86
|
+
addOptBool(@"clipped", ei.clipped);
|
|
87
|
+
addOptStr(@"clipMarkerColor", ei.clipMarkerColor);
|
|
88
|
+
|
|
89
|
+
// Dedup of unchanged embedInfo is handled natively in VdoCipherRNView.setEmbedInfo
|
|
90
|
+
// (covers both arches), so just forward it here.
|
|
91
|
+
if (embedInfoDict.count > 0) {
|
|
92
|
+
[_view setEmbedInfo:embedInfoDict];
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (newViewProps.resizeMode != oldViewProps.resizeMode && !newViewProps.resizeMode.empty()) {
|
|
97
|
+
[_view setResizeMode:[NSString stringWithUTF8String:newViewProps.resizeMode.c_str()]];
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (newViewProps.autoPlay != oldViewProps.autoPlay) {
|
|
101
|
+
[_view setAutoPlay:newViewProps.autoPlay];
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
[super updateProps:props oldProps:oldProps];
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// MARK: - Commands
|
|
108
|
+
|
|
109
|
+
- (void)handleCommand:(const NSString *)commandName args:(const NSArray *)args {
|
|
110
|
+
VdoHandlePlayerCommand(_view, commandName, args);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Fabric recycles this view instead of detaching it, so the Swift view's
|
|
114
|
+
// didMoveToSuperview(nil) teardown never runs. Tear down the player here.
|
|
115
|
+
- (void)prepareForRecycle {
|
|
116
|
+
[super prepareForRecycle];
|
|
117
|
+
[_view cleanup];
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
@end
|
|
121
|
+
|
|
122
|
+
// Called by the codegen-generated FabricComponents plugin to register this view.
|
|
123
|
+
Class<RCTComponentViewProtocol> RCTVdoPlayerViewCls(void) {
|
|
124
|
+
return RCTVdoPlayerViewComponentView.class;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
#endif // RCT_NEW_ARCH_ENABLED
|
package/ios/VdoCipherRNView.h
CHANGED
|
@@ -8,11 +8,24 @@
|
|
|
8
8
|
#ifndef VdoCipherRNView_h
|
|
9
9
|
#define VdoCipherRNView_h
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
#endif /* VdoCipherRNView_h */
|
|
13
|
-
|
|
11
|
+
#import <UIKit/UIKit.h>
|
|
14
12
|
#import <VdoFramework/VdoFramework.h>
|
|
15
13
|
|
|
16
14
|
@interface VdoCipherRNView: UIView
|
|
17
15
|
|
|
16
|
+
- (void)setEmbedInfo:(NSDictionary *)embedInfo;
|
|
17
|
+
- (void)setResizeMode:(NSString *)resizeMode;
|
|
18
|
+
- (void)setPlayWhenReady:(BOOL)playWhenReady;
|
|
19
|
+
- (void)setAutoPlay:(BOOL)autoPlay;
|
|
20
|
+
- (void)setPlaybackSpeed:(float)speed;
|
|
21
|
+
- (void)setSeek:(int)seekTime;
|
|
22
|
+
- (void)setCaptionLanguage:(NSString *)caption;
|
|
23
|
+
- (void)setDisableCaptions:(int)val;
|
|
24
|
+
- (void)setVideoQuality:(NSString *)videoQuality;
|
|
25
|
+
- (void)setAdaptiveVideo:(BOOL)val;
|
|
26
|
+
- (void)setScreenFocused:(BOOL)val;
|
|
27
|
+
- (void)cleanup;
|
|
28
|
+
|
|
18
29
|
@end
|
|
30
|
+
|
|
31
|
+
#endif /* VdoCipherRNView_h */
|
|
@@ -21,7 +21,8 @@ class VdoCipherRNView: UIView {
|
|
|
21
21
|
private var targetPlaybackSpeed: Float = 1.0
|
|
22
22
|
private var playbackType: PlaybackType = .streaming
|
|
23
23
|
private var resumeTime: CMTime?
|
|
24
|
-
|
|
24
|
+
private var lastEmbedInfo: [String: Any]?
|
|
25
|
+
|
|
25
26
|
private var playerItemBufferEmptyObserver: NSKeyValueObservation?
|
|
26
27
|
private var playerItemBufferKeepUpObserver: NSKeyValueObservation?
|
|
27
28
|
private var playerItemBufferFullObserver: NSKeyValueObservation?
|
|
@@ -59,11 +60,33 @@ class VdoCipherRNView: UIView {
|
|
|
59
60
|
override func didMoveToSuperview() {
|
|
60
61
|
super.didMoveToSuperview()
|
|
61
62
|
if self.superview == nil {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
cleanup()
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
@objc func cleanup() {
|
|
68
|
+
player?.pause()
|
|
69
|
+
self.removeObservers()
|
|
70
|
+
player?.replaceCurrentItem(with: nil)
|
|
71
|
+
player = nil
|
|
72
|
+
// Reset session state so a recycled-then-reused view (Fabric) starts fresh, like a new init().
|
|
73
|
+
asset = nil
|
|
74
|
+
preferredCaptionsLanguage = nil
|
|
75
|
+
playWhenReady = true
|
|
76
|
+
targetPlaybackSpeed = 1.0
|
|
77
|
+
playbackType = .streaming
|
|
78
|
+
resumeTime = nil
|
|
79
|
+
playerState = .unknown
|
|
80
|
+
isLoaded = false
|
|
81
|
+
lastEmbedInfo = nil
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
func shouldApplyEmbedInfo(_ embedInfo: [String: Any]) -> Bool {
|
|
85
|
+
if let last = lastEmbedInfo, (last as NSDictionary).isEqual(to: embedInfo) {
|
|
86
|
+
return false
|
|
66
87
|
}
|
|
88
|
+
lastEmbedInfo = embedInfo
|
|
89
|
+
return true
|
|
67
90
|
}
|
|
68
91
|
|
|
69
92
|
func addObserversToPlayer()
|
|
@@ -180,6 +203,9 @@ class VdoCipherRNView: UIView {
|
|
|
180
203
|
}
|
|
181
204
|
|
|
182
205
|
private func initiatePlayback(withInfo embedInfo: [String: Any], videoId: String, onlineCredentials: Credentials? = nil) {
|
|
206
|
+
VdoCipher.setPlaybackDelegate(delegate: self)
|
|
207
|
+
VdoCipher.setUIPlayerDelegate(self)
|
|
208
|
+
VdoCipher.enableAutoPlay = self.playWhenReady
|
|
183
209
|
let customPlayerId = embedInfo["customPlayerId"] as? String
|
|
184
210
|
let preferredCaptionsLanguage = embedInfo["preferredCaptionsLanguage"] as? String
|
|
185
211
|
let enableAutoResume = embedInfo["enableAutoResume"] as? Bool
|
|
@@ -193,7 +219,7 @@ class VdoCipherRNView: UIView {
|
|
|
193
219
|
userDefaults?.set(assetsLastPlaybackTimeSet, forKey: "assetsLastPlaybackTimeSet")
|
|
194
220
|
}
|
|
195
221
|
}
|
|
196
|
-
|
|
222
|
+
AssetList.shared.getAssetFor(videoId: videoId, playerId: customPlayerId, completionHandler: { asset, err in
|
|
197
223
|
DispatchQueue.main.async {
|
|
198
224
|
guard let asset = asset else {
|
|
199
225
|
if let error = err {
|
|
@@ -284,7 +310,13 @@ class VdoCipherRNView: UIView {
|
|
|
284
310
|
|
|
285
311
|
@objc func setResizeMode(_ resizeMode: String) {
|
|
286
312
|
}
|
|
287
|
-
|
|
313
|
+
|
|
314
|
+
@objc func setAutoPlay(_ autoPlay: Bool) {
|
|
315
|
+
guard !isLoaded else { return }
|
|
316
|
+
self.playWhenReady = autoPlay
|
|
317
|
+
VdoCipher.enableAutoPlay = autoPlay
|
|
318
|
+
}
|
|
319
|
+
|
|
288
320
|
@objc func setPlayWhenReady(_ playWhenReady: Bool) {
|
|
289
321
|
self.playWhenReady = playWhenReady
|
|
290
322
|
if playerState != .ready {
|
|
@@ -314,7 +346,9 @@ class VdoCipherRNView: UIView {
|
|
|
314
346
|
self.player?.seek(to: CMTime(value: CMTimeValue(seekTime), timescale: 1000))
|
|
315
347
|
}
|
|
316
348
|
|
|
317
|
-
@objc func setCaptionLanguage(_ caption:
|
|
349
|
+
@objc func setCaptionLanguage(_ caption: String) {
|
|
350
|
+
guard let data = caption.data(using: .utf8),
|
|
351
|
+
let caption = try? JSONSerialization.jsonObject(with: data) as? [String: Any] else { return }
|
|
318
352
|
guard let asset = TrackSelection.asset,
|
|
319
353
|
let captions = asset.captions,
|
|
320
354
|
let selectedCaptionName = caption["name"] as? String,
|
|
@@ -330,7 +364,9 @@ class VdoCipherRNView: UIView {
|
|
|
330
364
|
}
|
|
331
365
|
}
|
|
332
366
|
|
|
333
|
-
@objc func setVideoQuality(_ videoQuality:
|
|
367
|
+
@objc func setVideoQuality(_ videoQuality: String) {
|
|
368
|
+
guard let data = videoQuality.data(using: .utf8),
|
|
369
|
+
let videoQuality = try? JSONSerialization.jsonObject(with: data) as? [String: Any] else { return }
|
|
334
370
|
guard let asset = self.asset,
|
|
335
371
|
let index = videoQuality["id"] as? Int,
|
|
336
372
|
asset.getVideoQualities().count >= index else {return}
|