@100mslive/react-native-hms 1.10.3 → 1.10.4
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/android/local.properties +8 -1
- package/android/src/main/java/com/reactnativehmssdk/HMSDecoder.kt +3 -0
- package/android/src/main/java/com/reactnativehmssdk/HMSHLSPlayer.kt +94 -0
- package/android/src/main/java/com/reactnativehmssdk/HMSHLSPlayerManager.kt +32 -0
- package/ios/HMSDecoder.swift +12 -0
- package/ios/HMSHLSPlayerManager.m +6 -0
- package/ios/HMSHLSPlayerManager.swift +140 -1
- package/ios/Hmssdk.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- package/ios/Hmssdk.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- package/ios/Hmssdk.xcodeproj/project.xcworkspace/xcuserdata/jatinnagar.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/Hmssdk.xcodeproj/xcuserdata/jatinnagar.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
- package/lib/commonjs/classes/HMSEncoder.js +11 -1
- package/lib/commonjs/classes/HMSEncoder.js.map +1 -1
- package/lib/commonjs/classes/HMSHLSPlaylistType.js +12 -0
- package/lib/commonjs/classes/HMSHLSPlaylistType.js.map +1 -0
- package/lib/commonjs/classes/HMSHLSVariant.js +2 -0
- package/lib/commonjs/classes/HMSHLSVariant.js.map +1 -1
- package/lib/commonjs/classes/HMSNoiseCancellationPlugin.js +1 -0
- package/lib/commonjs/classes/HMSNoiseCancellationPlugin.js.map +1 -1
- package/lib/commonjs/components/HMSHLSPlayer/HMSHLSPlayer.js +98 -2
- package/lib/commonjs/components/HMSHLSPlayer/HMSHLSPlayer.js.map +1 -1
- package/lib/commonjs/components/HMSHLSPlayer/RCTHMSHLSPlayer.js.map +1 -1
- package/lib/commonjs/components/HMSHLSPlayer/hooks.js +16 -6
- package/lib/commonjs/components/HMSHLSPlayer/hooks.js.map +1 -1
- package/lib/commonjs/components/HMSHLSPlayer/index.js +15 -1
- package/lib/commonjs/components/HMSHLSPlayer/index.js.map +1 -1
- package/lib/commonjs/index.js +12 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/stores/hls-player-playback-slice.js +6 -0
- package/lib/commonjs/stores/hls-player-playback-slice.js.map +1 -1
- package/lib/commonjs/stores/hls-player-stats-store.js +27 -15
- package/lib/commonjs/stores/hls-player-stats-store.js.map +1 -1
- package/lib/commonjs/stores/types.js.map +1 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/module/classes/HMSEncoder.js +11 -1
- package/lib/module/classes/HMSEncoder.js.map +1 -1
- package/lib/module/classes/HMSHLSPlaylistType.js +6 -0
- package/lib/module/classes/HMSHLSPlaylistType.js.map +1 -0
- package/lib/module/classes/HMSHLSVariant.js +2 -0
- package/lib/module/classes/HMSHLSVariant.js.map +1 -1
- package/lib/module/classes/HMSNoiseCancellationPlugin.js +1 -0
- package/lib/module/classes/HMSNoiseCancellationPlugin.js.map +1 -1
- package/lib/module/components/HMSHLSPlayer/HMSHLSPlayer.js +101 -5
- package/lib/module/components/HMSHLSPlayer/HMSHLSPlayer.js.map +1 -1
- package/lib/module/components/HMSHLSPlayer/RCTHMSHLSPlayer.js.map +1 -1
- package/lib/module/components/HMSHLSPlayer/hooks.js +12 -4
- package/lib/module/components/HMSHLSPlayer/hooks.js.map +1 -1
- package/lib/module/components/HMSHLSPlayer/index.js +1 -1
- package/lib/module/components/HMSHLSPlayer/index.js.map +1 -1
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/stores/hls-player-playback-slice.js +6 -0
- package/lib/module/stores/hls-player-playback-slice.js.map +1 -1
- package/lib/module/stores/hls-player-stats-store.js +27 -15
- package/lib/module/stores/hls-player-stats-store.js.map +1 -1
- package/lib/module/stores/types.js.map +1 -1
- package/lib/module/types.js.map +1 -1
- package/lib/typescript/classes/HMSEncoder.d.ts +2 -0
- package/lib/typescript/classes/HMSHLSPlaylistType.d.ts +4 -0
- package/lib/typescript/classes/HMSHLSVariant.d.ts +3 -0
- package/lib/typescript/classes/HMSNoiseCancellationPlugin.d.ts +1 -0
- package/lib/typescript/components/HMSHLSPlayer/HMSHLSPlayer.d.ts +6 -0
- package/lib/typescript/components/HMSHLSPlayer/RCTHMSHLSPlayer.d.ts +5 -1
- package/lib/typescript/components/HMSHLSPlayer/hooks.d.ts +3 -0
- package/lib/typescript/components/HMSHLSPlayer/index.d.ts +1 -1
- package/lib/typescript/index.d.ts +1 -0
- package/lib/typescript/stores/hls-player-stats-store.d.ts +4 -3
- package/lib/typescript/stores/types.d.ts +7 -1
- package/lib/typescript/types.d.ts +9 -0
- package/package.json +1 -1
- package/sdk-versions.json +2 -2
- package/src/classes/HMSEncoder.ts +13 -0
- package/src/classes/HMSHLSPlaylistType.ts +4 -0
- package/src/classes/HMSHLSVariant.ts +5 -0
- package/src/classes/HMSNoiseCancellationPlugin.ts +1 -0
- package/src/components/HMSHLSPlayer/HMSHLSPlayer.tsx +158 -4
- package/src/components/HMSHLSPlayer/RCTHMSHLSPlayer.ts +12 -0
- package/src/components/HMSHLSPlayer/hooks.ts +16 -4
- package/src/components/HMSHLSPlayer/index.ts +2 -0
- package/src/index.ts +1 -0
- package/src/stores/hls-player-playback-slice.ts +8 -0
- package/src/stores/hls-player-stats-store.ts +28 -18
- package/src/stores/types.ts +9 -1
- package/src/types.ts +15 -0
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
import React, { useImperativeHandle, useRef } from 'react';
|
|
2
|
-
import {
|
|
1
|
+
import React, { useEffect, useImperativeHandle, useMemo, useRef } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
View,
|
|
4
|
+
StyleSheet,
|
|
5
|
+
UIManager,
|
|
6
|
+
findNodeHandle,
|
|
7
|
+
Platform,
|
|
8
|
+
} from 'react-native';
|
|
3
9
|
import type { StyleProp, ViewStyle } from 'react-native';
|
|
4
10
|
|
|
5
11
|
import {
|
|
@@ -9,23 +15,31 @@ import {
|
|
|
9
15
|
setHMSHLSPlayerResolution,
|
|
10
16
|
setHMSHLSPlayerStats,
|
|
11
17
|
setHMSHLSPlayerStatsError,
|
|
18
|
+
setHMSHLSPlayerSubtitles,
|
|
12
19
|
} from './hooks';
|
|
13
20
|
import {
|
|
14
21
|
RCTHMSHLSPlayer,
|
|
15
22
|
RCTHMSHLSPlayerViewManagerConfig,
|
|
16
23
|
} from './RCTHMSHLSPlayer';
|
|
17
24
|
import type {
|
|
25
|
+
HlsSPlayerCuesEventHandler,
|
|
18
26
|
HmsHlsPlaybackEventHandler,
|
|
19
27
|
HmsHlsStatsEventHandler,
|
|
20
28
|
RCTHMSHLSPlayerRef,
|
|
29
|
+
RequestedDataEventHandler,
|
|
21
30
|
} from './RCTHMSHLSPlayer';
|
|
22
31
|
import {
|
|
23
32
|
HMSHLSPlayerPlaybackEventTypes,
|
|
24
33
|
HMSHLSPlayerStatsEventTypes,
|
|
25
34
|
} from '../../types';
|
|
26
|
-
import type {
|
|
35
|
+
import type {
|
|
36
|
+
HLSPlayerDurationDetails,
|
|
37
|
+
HMSHLSPlayerPlaybackCueEventData,
|
|
38
|
+
} from '../../types';
|
|
27
39
|
import { HMSEncoder } from '../../classes/HMSEncoder';
|
|
28
40
|
import type { HMSHLSPlayerPlaybackCue } from '../../stores/types';
|
|
41
|
+
import { useHMSStore } from '../../stores/hms-store';
|
|
42
|
+
import { useHMSHLSPlayerStatsStore } from '../../stores/hls-player-stats-store';
|
|
29
43
|
|
|
30
44
|
export interface HMSHLSPlayerProps {
|
|
31
45
|
url?: string;
|
|
@@ -45,6 +59,11 @@ export interface HMSHLSPlayerRefProperties {
|
|
|
45
59
|
seekBackward: (seconds: number) => void;
|
|
46
60
|
seekToLivePosition: () => void;
|
|
47
61
|
setVolume: (level: number) => void;
|
|
62
|
+
isClosedCaptionSupported: () => Promise<boolean>;
|
|
63
|
+
isClosedCaptionEnabled: () => Promise<boolean>;
|
|
64
|
+
enableClosedCaption: () => void;
|
|
65
|
+
disableClosedCaption: () => void;
|
|
66
|
+
getPlayerDurationDetails: () => Promise<HLSPlayerDurationDetails>;
|
|
48
67
|
}
|
|
49
68
|
|
|
50
69
|
const _HMSHLSPlayer: React.ForwardRefRenderFunction<
|
|
@@ -55,6 +74,15 @@ const _HMSHLSPlayer: React.ForwardRefRenderFunction<
|
|
|
55
74
|
ref
|
|
56
75
|
) => {
|
|
57
76
|
const hmsHlsPlayerRef = useRef<RCTHMSHLSPlayerRef | null>(null);
|
|
77
|
+
const promiseAndIdsMap = useMemo(
|
|
78
|
+
() =>
|
|
79
|
+
new Map<
|
|
80
|
+
number,
|
|
81
|
+
{ resolve(value: unknown): void; reject(reason?: any): void }
|
|
82
|
+
>(),
|
|
83
|
+
[]
|
|
84
|
+
);
|
|
85
|
+
const currentRequestId = useRef(1);
|
|
58
86
|
|
|
59
87
|
useImperativeHandle(
|
|
60
88
|
ref,
|
|
@@ -177,8 +205,94 @@ const _HMSHLSPlayer: React.ForwardRefRenderFunction<
|
|
|
177
205
|
);
|
|
178
206
|
}
|
|
179
207
|
},
|
|
208
|
+
isClosedCaptionSupported: () => {
|
|
209
|
+
if (
|
|
210
|
+
hmsHlsPlayerRef.current &&
|
|
211
|
+
RCTHMSHLSPlayerViewManagerConfig.Commands.areClosedCaptionSupported
|
|
212
|
+
) {
|
|
213
|
+
const requestId = currentRequestId.current++;
|
|
214
|
+
const promise = new Promise<boolean>((resolve, reject) => {
|
|
215
|
+
promiseAndIdsMap.set(requestId, { resolve, reject });
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
UIManager.dispatchViewManagerCommand(
|
|
219
|
+
findNodeHandle(hmsHlsPlayerRef.current),
|
|
220
|
+
RCTHMSHLSPlayerViewManagerConfig.Commands.areClosedCaptionSupported,
|
|
221
|
+
[requestId]
|
|
222
|
+
);
|
|
223
|
+
return promise;
|
|
224
|
+
}
|
|
225
|
+
return Promise.resolve(false);
|
|
226
|
+
},
|
|
227
|
+
isClosedCaptionEnabled: () => {
|
|
228
|
+
if (
|
|
229
|
+
hmsHlsPlayerRef.current &&
|
|
230
|
+
RCTHMSHLSPlayerViewManagerConfig.Commands.isClosedCaptionEnabled
|
|
231
|
+
) {
|
|
232
|
+
const requestId = currentRequestId.current++;
|
|
233
|
+
const promise = new Promise<boolean>((resolve, reject) => {
|
|
234
|
+
promiseAndIdsMap.set(requestId, { resolve, reject });
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
UIManager.dispatchViewManagerCommand(
|
|
238
|
+
findNodeHandle(hmsHlsPlayerRef.current),
|
|
239
|
+
RCTHMSHLSPlayerViewManagerConfig.Commands.isClosedCaptionEnabled,
|
|
240
|
+
[requestId]
|
|
241
|
+
);
|
|
242
|
+
return promise;
|
|
243
|
+
}
|
|
244
|
+
return Promise.resolve(false);
|
|
245
|
+
},
|
|
246
|
+
enableClosedCaption: () => {
|
|
247
|
+
if (
|
|
248
|
+
hmsHlsPlayerRef.current &&
|
|
249
|
+
RCTHMSHLSPlayerViewManagerConfig.Commands.enableClosedCaption
|
|
250
|
+
) {
|
|
251
|
+
UIManager.dispatchViewManagerCommand(
|
|
252
|
+
findNodeHandle(hmsHlsPlayerRef.current),
|
|
253
|
+
RCTHMSHLSPlayerViewManagerConfig.Commands.enableClosedCaption,
|
|
254
|
+
undefined
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
},
|
|
258
|
+
disableClosedCaption: () => {
|
|
259
|
+
if (
|
|
260
|
+
hmsHlsPlayerRef.current &&
|
|
261
|
+
RCTHMSHLSPlayerViewManagerConfig.Commands.disableClosedCaption
|
|
262
|
+
) {
|
|
263
|
+
UIManager.dispatchViewManagerCommand(
|
|
264
|
+
findNodeHandle(hmsHlsPlayerRef.current),
|
|
265
|
+
RCTHMSHLSPlayerViewManagerConfig.Commands.disableClosedCaption,
|
|
266
|
+
undefined
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
},
|
|
270
|
+
getPlayerDurationDetails: () => {
|
|
271
|
+
if (
|
|
272
|
+
hmsHlsPlayerRef.current &&
|
|
273
|
+
RCTHMSHLSPlayerViewManagerConfig.Commands.getPlayerDurationDetails
|
|
274
|
+
) {
|
|
275
|
+
const requestId = currentRequestId.current++;
|
|
276
|
+
const promise = new Promise<HLSPlayerDurationDetails>(
|
|
277
|
+
(resolve, reject) => {
|
|
278
|
+
promiseAndIdsMap.set(requestId, { resolve, reject });
|
|
279
|
+
}
|
|
280
|
+
);
|
|
281
|
+
|
|
282
|
+
UIManager.dispatchViewManagerCommand(
|
|
283
|
+
findNodeHandle(hmsHlsPlayerRef.current),
|
|
284
|
+
RCTHMSHLSPlayerViewManagerConfig.Commands.getPlayerDurationDetails,
|
|
285
|
+
[requestId]
|
|
286
|
+
);
|
|
287
|
+
return promise;
|
|
288
|
+
}
|
|
289
|
+
return Promise.resolve({
|
|
290
|
+
streamDuration: undefined,
|
|
291
|
+
rollingWindowTime: undefined,
|
|
292
|
+
});
|
|
293
|
+
},
|
|
180
294
|
}),
|
|
181
|
-
[]
|
|
295
|
+
[currentRequestId, promiseAndIdsMap]
|
|
182
296
|
);
|
|
183
297
|
|
|
184
298
|
// Handle HLS Playback events
|
|
@@ -218,6 +332,42 @@ const _HMSHLSPlayer: React.ForwardRefRenderFunction<
|
|
|
218
332
|
}
|
|
219
333
|
};
|
|
220
334
|
|
|
335
|
+
// Handle HLS Player Cues events (e.g. usage - Closed Captions)
|
|
336
|
+
const handleHLSPlayerCuesEvent: HlsSPlayerCuesEventHandler = ({
|
|
337
|
+
nativeEvent,
|
|
338
|
+
}) => {
|
|
339
|
+
const { event, data } = nativeEvent;
|
|
340
|
+
|
|
341
|
+
if (event === 'ON_CLOSED_CAPTION_UPDATE') {
|
|
342
|
+
setHMSHLSPlayerSubtitles(data);
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
// Handle Requested data
|
|
347
|
+
const handleRequestedDataReturned: RequestedDataEventHandler = ({
|
|
348
|
+
nativeEvent,
|
|
349
|
+
}) => {
|
|
350
|
+
const { requestId, data } = nativeEvent;
|
|
351
|
+
const promiseMethods = promiseAndIdsMap.get(requestId);
|
|
352
|
+
|
|
353
|
+
if (!promiseMethods) {
|
|
354
|
+
console.warn(
|
|
355
|
+
'#function handleRequestedDataReturned',
|
|
356
|
+
"Didn't found promise methods by requestId: ",
|
|
357
|
+
requestId
|
|
358
|
+
);
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
promiseMethods.resolve(data);
|
|
362
|
+
};
|
|
363
|
+
|
|
364
|
+
useEffect(() => {
|
|
365
|
+
return () => {
|
|
366
|
+
useHMSStore.getState().resetPlaybackSlice();
|
|
367
|
+
useHMSHLSPlayerStatsStore.getState().reset();
|
|
368
|
+
};
|
|
369
|
+
}, []);
|
|
370
|
+
|
|
221
371
|
return (
|
|
222
372
|
<View style={[styles.container, containerStyle]}>
|
|
223
373
|
<View style={[styles.playerWrapper, style]}>
|
|
@@ -229,6 +379,10 @@ const _HMSHLSPlayer: React.ForwardRefRenderFunction<
|
|
|
229
379
|
enableControls={enableControls}
|
|
230
380
|
onHmsHlsPlaybackEvent={handleHLSPlaybackEvent}
|
|
231
381
|
onHmsHlsStatsEvent={handleHLSStatsEvent}
|
|
382
|
+
onHlsPlayerCuesEvent={
|
|
383
|
+
Platform.OS === 'android' ? handleHLSPlayerCuesEvent : undefined
|
|
384
|
+
}
|
|
385
|
+
onDataReturned={handleRequestedDataReturned}
|
|
232
386
|
/>
|
|
233
387
|
</View>
|
|
234
388
|
</View>
|
|
@@ -6,8 +6,10 @@ import type {
|
|
|
6
6
|
NativeMethods,
|
|
7
7
|
} from 'react-native';
|
|
8
8
|
import type {
|
|
9
|
+
HMSHLSPlayerCuesEvent,
|
|
9
10
|
HMSHLSPlayerPlaybackEvent,
|
|
10
11
|
HMSHLSPlayerStatsEvent,
|
|
12
|
+
RequestedDataEvent,
|
|
11
13
|
} from '../../types';
|
|
12
14
|
|
|
13
15
|
export type HmsHlsPlaybackEventHandler = (
|
|
@@ -18,6 +20,14 @@ export type HmsHlsStatsEventHandler = (
|
|
|
18
20
|
event: NativeSyntheticEvent<HMSHLSPlayerStatsEvent>
|
|
19
21
|
) => void;
|
|
20
22
|
|
|
23
|
+
export type HlsSPlayerCuesEventHandler = (
|
|
24
|
+
event: NativeSyntheticEvent<HMSHLSPlayerCuesEvent>
|
|
25
|
+
) => void;
|
|
26
|
+
|
|
27
|
+
export type RequestedDataEventHandler = (
|
|
28
|
+
event: NativeSyntheticEvent<RequestedDataEvent>
|
|
29
|
+
) => void;
|
|
30
|
+
|
|
21
31
|
export type RCTHMSHLSPlayerProps = {
|
|
22
32
|
url?: string;
|
|
23
33
|
style?: StyleProp<ViewStyle>;
|
|
@@ -25,6 +35,8 @@ export type RCTHMSHLSPlayerProps = {
|
|
|
25
35
|
enableControls?: boolean;
|
|
26
36
|
onHmsHlsPlaybackEvent?: HmsHlsPlaybackEventHandler;
|
|
27
37
|
onHmsHlsStatsEvent?: HmsHlsStatsEventHandler;
|
|
38
|
+
onDataReturned?: RequestedDataEventHandler;
|
|
39
|
+
onHlsPlayerCuesEvent?: HlsSPlayerCuesEventHandler;
|
|
28
40
|
};
|
|
29
41
|
|
|
30
42
|
export const RCTHMSHLSPlayer =
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useEffect } from 'react';
|
|
2
|
+
import { Platform } from 'react-native';
|
|
2
3
|
import type { DependencyList } from 'react';
|
|
3
4
|
import { shallow } from 'zustand/shallow';
|
|
4
5
|
|
|
@@ -39,10 +40,18 @@ export const useHMSHLSPlayerStat = <
|
|
|
39
40
|
return useHMSHLSPlayerStatsStore((state) => state.stats[stat]);
|
|
40
41
|
};
|
|
41
42
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
export const useHMSHLSPlayerSubtitles = () => {
|
|
44
|
+
return useHMSHLSPlayerStatsStore((state) => state.subtitles);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// The distance of current playback position from the live edge of HLS stream
|
|
48
|
+
export const useIsHLSStreamLive = (
|
|
49
|
+
liveOffsetMillis: number = Platform.select({ default: 10000, ios: 5000 })
|
|
50
|
+
) => {
|
|
51
|
+
return useHMSHLSPlayerStatsStore(
|
|
52
|
+
(state) => state.stats.distanceFromLive < liveOffsetMillis
|
|
53
|
+
);
|
|
54
|
+
};
|
|
46
55
|
|
|
47
56
|
// get latest state (without component rerender)
|
|
48
57
|
|
|
@@ -105,3 +114,6 @@ export const setHMSHLSPlayerStats =
|
|
|
105
114
|
|
|
106
115
|
export const setHMSHLSPlayerStatsError =
|
|
107
116
|
useHMSHLSPlayerStatsStore.getState().setError;
|
|
117
|
+
|
|
118
|
+
export const setHMSHLSPlayerSubtitles =
|
|
119
|
+
useHMSHLSPlayerStatsStore.getState().setSubtitles;
|
package/src/index.ts
CHANGED
|
@@ -83,6 +83,7 @@ export * from './classes/HMSCameraControl';
|
|
|
83
83
|
export * from './classes/HMSIOSAudioMode';
|
|
84
84
|
export * from './classes/HMSRecordingState';
|
|
85
85
|
export * from './classes/HMSStreamingState';
|
|
86
|
+
export * from './classes/HMSHLSPlaylistType';
|
|
86
87
|
export type {
|
|
87
88
|
HMSSessionStore,
|
|
88
89
|
JsonArray,
|
|
@@ -25,4 +25,12 @@ export const createHMSHLSPlayerPlaybackSlice: StateCreator<
|
|
|
25
25
|
|
|
26
26
|
resolution: undefined,
|
|
27
27
|
setResolution: (resolution) => set({ resolution }),
|
|
28
|
+
|
|
29
|
+
resetPlaybackSlice: () =>
|
|
30
|
+
set({
|
|
31
|
+
cue: undefined,
|
|
32
|
+
playbackState: HMSHLSPlayerPlaybackState.UNKNOWN,
|
|
33
|
+
error: undefined,
|
|
34
|
+
resolution: undefined,
|
|
35
|
+
}),
|
|
28
36
|
});
|
|
@@ -6,32 +6,42 @@ import type {
|
|
|
6
6
|
HMSHLSPlayerStatsStore,
|
|
7
7
|
} from './types';
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
// bandwidth
|
|
14
|
-
bandWidthEstimate: 0,
|
|
15
|
-
totalBytesLoaded: 0,
|
|
9
|
+
const INITIAL_STATS = {
|
|
10
|
+
// bandwidth
|
|
11
|
+
bandWidthEstimate: 0,
|
|
12
|
+
totalBytesLoaded: 0,
|
|
16
13
|
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
// bufferedDuration
|
|
15
|
+
bufferedDuration: 0,
|
|
19
16
|
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
// distanceFromLive
|
|
18
|
+
distanceFromLive: 0,
|
|
22
19
|
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
// frameInfo
|
|
21
|
+
droppedFrameCount: 0,
|
|
25
22
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
23
|
+
// videoInfo
|
|
24
|
+
averageBitrate: 0,
|
|
25
|
+
videoHeight: 0,
|
|
26
|
+
videoWidth: 0,
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const useHMSHLSPlayerStatsStore = create<HMSHLSPlayerStatsStore>()(
|
|
30
|
+
subscribeWithSelector((set) => ({
|
|
31
|
+
// Handle Stats
|
|
32
|
+
stats: INITIAL_STATS,
|
|
31
33
|
changeStats: (stats: HMSHLSPlayerStats) => set({ stats }),
|
|
32
34
|
|
|
33
35
|
// Handle Stats Error
|
|
34
36
|
error: undefined,
|
|
35
37
|
setError: (error: HMSHLSPlayerStatsError) => set({ error }),
|
|
38
|
+
|
|
39
|
+
// Handle Closed Caption
|
|
40
|
+
subtitles: null,
|
|
41
|
+
setSubtitles: (subtitles: string | null) => set({ subtitles }),
|
|
42
|
+
|
|
43
|
+
// Reset State
|
|
44
|
+
reset: () =>
|
|
45
|
+
set({ stats: INITIAL_STATS, error: undefined, subtitles: null }),
|
|
36
46
|
}))
|
|
37
47
|
);
|
package/src/stores/types.ts
CHANGED
|
@@ -11,7 +11,8 @@ import type {
|
|
|
11
11
|
} from '../types';
|
|
12
12
|
|
|
13
13
|
export type HMSStore = HMSHLSPlayerPlaybackSlice & HMSViewsSlice;
|
|
14
|
-
export type HMSHLSPlayerStatsStore = HMSHLSPlayerStatsSlice
|
|
14
|
+
export type HMSHLSPlayerStatsStore = HMSHLSPlayerStatsSlice &
|
|
15
|
+
HLSPlayerClosedCaptionsSlice;
|
|
15
16
|
export type HMSInteractivityStore = HMSPollsSlice;
|
|
16
17
|
|
|
17
18
|
//#region HMSViews Slice
|
|
@@ -57,6 +58,7 @@ export interface HMSHLSPlayerPlaybackSlice {
|
|
|
57
58
|
setPlaybackState(playbackState: HMSHLSPlayerPlaybackState): void;
|
|
58
59
|
setResolution(resolution: HMSHLSPlayerResolution): void;
|
|
59
60
|
setPlaybackError(error: HMSHLSPlayerPlaybackError): void;
|
|
61
|
+
resetPlaybackSlice(): void;
|
|
60
62
|
}
|
|
61
63
|
|
|
62
64
|
//#endregion HLS Player Playback Slice
|
|
@@ -73,6 +75,12 @@ export interface HMSHLSPlayerStatsSlice {
|
|
|
73
75
|
error: HMSHLSPlayerStatsError | undefined;
|
|
74
76
|
changeStats(stats: HMSHLSPlayerStats): void;
|
|
75
77
|
setError(error: HMSHLSPlayerStatsError): void;
|
|
78
|
+
reset(): void;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export interface HLSPlayerClosedCaptionsSlice {
|
|
82
|
+
subtitles: string | null;
|
|
83
|
+
setSubtitles(subtitles: string | null): void;
|
|
76
84
|
}
|
|
77
85
|
|
|
78
86
|
//#endregion HLS Player Stats Slice
|
package/src/types.ts
CHANGED
|
@@ -125,6 +125,21 @@ export type HMSHLSPlayerStatsEvent =
|
|
|
125
125
|
| HMSHLSPlayerStatsErrorEvent
|
|
126
126
|
| HMSHLSPlayerStatsUpdateEvent;
|
|
127
127
|
|
|
128
|
+
export type HMSHLSPlayerCuesEvent = HMSHLSPlayerEvent<
|
|
129
|
+
'ON_CLOSED_CAPTION_UPDATE',
|
|
130
|
+
string | null
|
|
131
|
+
>;
|
|
132
|
+
|
|
133
|
+
export type RequestedDataEvent = {
|
|
134
|
+
requestId: number;
|
|
135
|
+
data: any;
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
export type HLSPlayerDurationDetails = {
|
|
139
|
+
streamDuration?: number;
|
|
140
|
+
rollingWindowTime?: number;
|
|
141
|
+
};
|
|
142
|
+
|
|
128
143
|
// #endregion HMS HLSPlayer Stats Events
|
|
129
144
|
|
|
130
145
|
// #region Utility types
|