bitmovin-player-react-native 0.1.0 → 0.2.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/README.md +163 -1
- package/RNBitmovinPlayer.podspec +3 -3
- package/android/src/main/java/com/bitmovin/player/reactnative/DrmModule.kt +191 -0
- package/android/src/main/java/com/bitmovin/player/reactnative/PlayerModule.kt +116 -101
- package/android/src/main/java/com/bitmovin/player/reactnative/RNPlayerView.kt +69 -38
- package/android/src/main/java/com/bitmovin/player/reactnative/RNPlayerViewManager.kt +10 -26
- package/android/src/main/java/com/bitmovin/player/reactnative/RNPlayerViewPackage.kt +3 -0
- package/android/src/main/java/com/bitmovin/player/reactnative/Registry.kt +11 -0
- package/android/src/main/java/com/bitmovin/player/reactnative/SourceModule.kt +178 -0
- package/android/src/main/java/com/bitmovin/player/reactnative/UuidModule.kt +20 -0
- package/android/src/main/java/com/bitmovin/player/reactnative/converter/JsonConverter.kt +128 -1
- package/android/src/main/java/com/bitmovin/player/reactnative/extensions/Events.kt +11 -2
- package/ios/DrmModule.m +16 -0
- package/ios/DrmModule.swift +442 -0
- package/ios/Event+JSON.swift +31 -0
- package/ios/PlayerModule.m +21 -25
- package/ios/PlayerModule.swift +122 -120
- package/ios/RCTConvert+BitmovinPlayer.swift +131 -12
- package/ios/RNPlayerView+PlayerListener.swift +12 -0
- package/ios/RNPlayerView.swift +5 -3
- package/ios/RNPlayerViewManager.m +3 -1
- package/ios/RNPlayerViewManager.swift +4 -21
- package/ios/Registry.swift +5 -0
- package/ios/SourceModule.m +30 -0
- package/ios/SourceModule.swift +187 -0
- package/ios/UuidModule.m +9 -0
- package/ios/UuidModule.swift +23 -0
- package/lib/index.d.ts +670 -235
- package/lib/index.js +257 -106
- package/lib/index.mjs +260 -112
- package/package.json +5 -4
- package/src/components/PlayerView/events.ts +24 -18
- package/src/components/PlayerView/index.tsx +29 -26
- package/src/drm/fairplayConfig.ts +90 -0
- package/src/drm/index.ts +178 -0
- package/src/drm/widevineConfig.ts +37 -0
- package/src/events.ts +67 -6
- package/src/hooks/useProxy.ts +19 -15
- package/src/index.ts +5 -3
- package/src/nativeInstance.ts +64 -0
- package/src/player.ts +51 -42
- package/src/source.ts +88 -8
- package/src/subtitleTrack.ts +60 -0
- package/src/utils.ts +15 -0
package/src/source.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
import { NativeModules } from 'react-native';
|
|
2
|
+
import { Drm, DrmConfig } from './drm';
|
|
3
|
+
import NativeInstance, { NativeInstanceConfig } from './nativeInstance';
|
|
4
|
+
import { SideLoadedSubtitleTrack } from './subtitleTrack';
|
|
5
|
+
|
|
6
|
+
const SourceModule = NativeModules.SourceModule;
|
|
7
|
+
|
|
1
8
|
/**
|
|
2
9
|
* Types of media that can be handled by the player.
|
|
3
10
|
*/
|
|
@@ -41,7 +48,7 @@ export enum LoadingState {
|
|
|
41
48
|
/**
|
|
42
49
|
* Represents a source configuration that be loaded into a player instance.
|
|
43
50
|
*/
|
|
44
|
-
export interface SourceConfig {
|
|
51
|
+
export interface SourceConfig extends NativeInstanceConfig {
|
|
45
52
|
/**
|
|
46
53
|
* The url for this source configuration.
|
|
47
54
|
*/
|
|
@@ -63,33 +70,106 @@ export interface SourceConfig {
|
|
|
63
70
|
* Useful, for example, for audio-only streams.
|
|
64
71
|
*/
|
|
65
72
|
isPosterPersistent?: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* The DRM config for the source.
|
|
75
|
+
*/
|
|
76
|
+
drmConfig?: DrmConfig;
|
|
77
|
+
/**
|
|
78
|
+
* External subtitle tracks to be added into the player.
|
|
79
|
+
*/
|
|
80
|
+
subtitleTracks?: SideLoadedSubtitleTrack[];
|
|
66
81
|
}
|
|
67
82
|
|
|
68
83
|
/**
|
|
69
84
|
* Represents audio and video content that can be loaded into a player.
|
|
70
85
|
*/
|
|
71
|
-
export
|
|
86
|
+
export class Source extends NativeInstance<SourceConfig> {
|
|
87
|
+
/**
|
|
88
|
+
* The native DRM config reference of this source.
|
|
89
|
+
*/
|
|
90
|
+
drm?: Drm;
|
|
91
|
+
/**
|
|
92
|
+
* Whether the native `Source` object has been created.
|
|
93
|
+
*/
|
|
94
|
+
isInitialized = false;
|
|
95
|
+
/**
|
|
96
|
+
* Whether the native `Source` object has been disposed.
|
|
97
|
+
*/
|
|
98
|
+
isDestroyed = false;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Allocates the native `Source` instance and its resources natively.
|
|
102
|
+
*/
|
|
103
|
+
initialize = () => {
|
|
104
|
+
if (!this.isInitialized) {
|
|
105
|
+
if (this.config?.drmConfig) {
|
|
106
|
+
this.drm = new Drm(this.config.drmConfig);
|
|
107
|
+
this.drm.initialize();
|
|
108
|
+
SourceModule.initWithDrmConfig(
|
|
109
|
+
this.nativeId,
|
|
110
|
+
this.drm.nativeId,
|
|
111
|
+
this.config
|
|
112
|
+
);
|
|
113
|
+
} else {
|
|
114
|
+
SourceModule.initWithConfig(this.nativeId, this.config);
|
|
115
|
+
}
|
|
116
|
+
this.isInitialized = true;
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Destroys the native `Source` and releases all of its allocated resources.
|
|
122
|
+
*/
|
|
123
|
+
destroy = () => {
|
|
124
|
+
if (!this.isDestroyed) {
|
|
125
|
+
SourceModule.destroy(this.nativeId);
|
|
126
|
+
this.drm?.destroy();
|
|
127
|
+
this.isDestroyed = true;
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
|
|
72
131
|
/**
|
|
73
132
|
* The duration of the source in seconds if it’s a VoD or `INFINITY` if it’s a live stream.
|
|
74
133
|
* Default value is `0` if the duration is not available or not known.
|
|
75
134
|
*/
|
|
76
|
-
duration: number
|
|
135
|
+
duration = async (): Promise<number> => {
|
|
136
|
+
return SourceModule.duration(this.nativeId);
|
|
137
|
+
};
|
|
138
|
+
|
|
77
139
|
/**
|
|
78
140
|
* Whether the source is currently active in a player (i.e. playing back or paused).
|
|
79
141
|
* Only one source can be active in the same player instance at any time.
|
|
80
142
|
*/
|
|
81
|
-
isActive: boolean
|
|
143
|
+
isActive = async (): Promise<boolean> => {
|
|
144
|
+
return SourceModule.isActive(this.nativeId);
|
|
145
|
+
};
|
|
146
|
+
|
|
82
147
|
/**
|
|
83
148
|
* Whether the source is currently attached to a player instance.
|
|
84
149
|
*/
|
|
85
|
-
isAttachedToPlayer: boolean
|
|
150
|
+
isAttachedToPlayer = async (): Promise<boolean> => {
|
|
151
|
+
return SourceModule.isAttachedToPlayer(this.nativeId);
|
|
152
|
+
};
|
|
153
|
+
|
|
86
154
|
/**
|
|
87
155
|
* Metadata for the currently loaded source.
|
|
88
|
-
* Setting the metadata value for a source is not supported yet.
|
|
89
156
|
*/
|
|
90
|
-
metadata
|
|
157
|
+
metadata = async (): Promise<Record<string, any> | null> => {
|
|
158
|
+
return SourceModule.getMetadata(this.nativeId);
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Set metadata for the currently loaded source.
|
|
163
|
+
* Setting the metadata to `null` clears the metadata object in native source.
|
|
164
|
+
*/
|
|
165
|
+
setMetadata = (metadata: Record<string, any> | null): void => {
|
|
166
|
+
SourceModule.setMetadata(this.nativeId, metadata);
|
|
167
|
+
};
|
|
168
|
+
|
|
91
169
|
/**
|
|
92
170
|
* The current `LoadingState` of the source.
|
|
93
171
|
*/
|
|
94
|
-
loadingState
|
|
172
|
+
loadingState = async (): Promise<LoadingState> => {
|
|
173
|
+
return SourceModule.loadingState(this.nativeId);
|
|
174
|
+
};
|
|
95
175
|
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { MakeRequired } from './utils';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Supported subtitle/caption file formats.
|
|
5
|
+
*/
|
|
6
|
+
export enum SubtitleFormat {
|
|
7
|
+
CEA = 'cea',
|
|
8
|
+
TTML = 'ttml',
|
|
9
|
+
VTT = 'vtt',
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Represents a custom subtitle track source that can be added to `SourceConfig.subtitleTracks`.
|
|
14
|
+
*/
|
|
15
|
+
export interface SubtitleTrack {
|
|
16
|
+
/**
|
|
17
|
+
* The URL to the timed file, e.g. WebVTT file.
|
|
18
|
+
*/
|
|
19
|
+
url?: string;
|
|
20
|
+
/**
|
|
21
|
+
* The label for this track.
|
|
22
|
+
*/
|
|
23
|
+
label?: string;
|
|
24
|
+
/**
|
|
25
|
+
* The unique identifier for this track. If no value is provided, a random UUIDv4 will be generated for it.
|
|
26
|
+
*/
|
|
27
|
+
identifier?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Specifies the file format to be used by this track.
|
|
30
|
+
*/
|
|
31
|
+
format?: SubtitleFormat;
|
|
32
|
+
/**
|
|
33
|
+
* If set to true, this track would be considered as default. Default is `false`.
|
|
34
|
+
*/
|
|
35
|
+
isDefault?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Tells if a subtitle track is forced. If set to `true` it means that the player should automatically
|
|
38
|
+
* select and switch this subtitle according to the selected audio language. Forced subtitles do
|
|
39
|
+
* not appear in `Player.getAvailableSubtitles`.
|
|
40
|
+
*
|
|
41
|
+
* Default is `false`.
|
|
42
|
+
*/
|
|
43
|
+
isForced?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* The IETF BCP 47 language tag associated with this track, e.g. `pt`, `en`, `es` etc.
|
|
46
|
+
*/
|
|
47
|
+
language?: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Helper type that represents an entry in `SourceConfig.subtitleTracks` list.
|
|
52
|
+
*
|
|
53
|
+
* Since `SubtitleTrack` has all of its properties as optionals for total compatibility with
|
|
54
|
+
* values that may be sent from native code, this type serves as a reinforcer of what properties
|
|
55
|
+
* should be required during the registration of an external subtitle track from JS.
|
|
56
|
+
*/
|
|
57
|
+
export type SideLoadedSubtitleTrack = MakeRequired<
|
|
58
|
+
SubtitleTrack,
|
|
59
|
+
'url' | 'label' | 'language' | 'format'
|
|
60
|
+
>;
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility type that maps the specified optional props from the target `Type` to be
|
|
3
|
+
* required props. Note all the other props stay unaffected.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* type MyType = {
|
|
7
|
+
* a?: string;
|
|
8
|
+
* b?: number;
|
|
9
|
+
* c?: boolean;
|
|
10
|
+
* };
|
|
11
|
+
*
|
|
12
|
+
* type MyRequiredType = MakeRequired<MyType, 'a' | 'c'> // => { a: string; b?: number; c: boolean; }
|
|
13
|
+
*/
|
|
14
|
+
export type MakeRequired<Type, Key extends keyof Type> = Omit<Type, Key> &
|
|
15
|
+
Required<Pick<Type, Key>>;
|