@applicaster/zapp-react-native-utils 16.0.0-rc.59 → 16.0.0-rc.60

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.
@@ -0,0 +1,76 @@
1
+ import {
2
+ createConfigValueGetter,
3
+ resolvePlayerContentText,
4
+ VIDEO_PLAYER_CONTENT_DATA_KEYS,
5
+ AUDIO_PLAYER_CONTENT_DATA_KEYS,
6
+ } from "./contentDataKeys";
7
+ import type { PlayerContentDataKeys } from "./contentDataKeys";
8
+
9
+ /**
10
+ * Resolves the player's Title/Subtitle text as raw values (string | number |
11
+ * null). Called by `Player.getContent()`, which publishes the result on the
12
+ * player's content channel; every consumer - the mobile/TV transport
13
+ * controls, `ProgramInfo`, the TV audio player, the Chromecast controller and
14
+ * the native bridge - reads it from there rather than resolving for itself.
15
+ *
16
+ * `dataKeys` selects which Studio-configured key set backs the resolution:
17
+ * omit it for the default (mobile) `PLAYER_CONTENT_DATA_KEYS` set, or pass
18
+ * an explicit set (e.g. `VIDEO_PLAYER_CONTENT_DATA_KEYS`) for platforms/content
19
+ * types that keep separate Studio configuration for this text. Getting the
20
+ * key set backwards would make one platform read another platform's
21
+ * configuration, so every caller must be explicit about which set it wants.
22
+ *
23
+ * Keeping this in one place is what stops the dot-path / key-set resolution
24
+ * logic (`resolvePlayerContentText`) from being duplicated per caller.
25
+ */
26
+ export const resolvePlayerTitleSubtitle = ({
27
+ entry,
28
+ pluginConfiguration,
29
+ dataKeys,
30
+ }: {
31
+ entry: Option<ZappEntry>;
32
+ pluginConfiguration: Option<Record<string, any>>;
33
+ dataKeys?: PlayerContentDataKeys;
34
+ }): {
35
+ title: Option<string | number>;
36
+ summary: Option<string | number>;
37
+ } => {
38
+ const value = createConfigValueGetter(pluginConfiguration);
39
+
40
+ const title =
41
+ resolvePlayerContentText({ entry, field: "title", value, dataKeys }) ??
42
+ null;
43
+
44
+ const summary =
45
+ resolvePlayerContentText({
46
+ entry,
47
+ field: "subtitle",
48
+ value,
49
+ dataKeys,
50
+ }) ?? null;
51
+
52
+ return { title, summary };
53
+ };
54
+
55
+ /**
56
+ * Picks which Studio-configured key set backs a Title/Subtitle resolution,
57
+ * from the full three-way choice: TV audio, TV video, or mobile. Each of
58
+ * those ships separate Studio configuration for this text; getting this
59
+ * backwards would make one platform (or content type) read another's
60
+ * configuration.
61
+ */
62
+ export const getPlayerContentDataKeys = ({
63
+ isTV,
64
+ isAudioContent,
65
+ }: {
66
+ isTV: boolean;
67
+ isAudioContent: boolean;
68
+ }): PlayerContentDataKeys | undefined => {
69
+ if (!isTV) {
70
+ return undefined;
71
+ }
72
+
73
+ return isAudioContent
74
+ ? AUDIO_PLAYER_CONTENT_DATA_KEYS
75
+ : VIDEO_PLAYER_CONTENT_DATA_KEYS;
76
+ };
@@ -1,56 +0,0 @@
1
- import { useEffect, useState } from "react";
2
- import { OverlaysObserver } from "./OverlayObserver/OverlaysObserver";
3
- import { useFeedLoader } from "../../reactHooks";
4
- import { usePlayer } from "./usePlayer";
5
-
6
- const getLiveUrl = (url: string) => {
7
- // Use the replace method with a regular expression to replace all instances of subClass with livePage
8
- return url.replace(new RegExp("subClass", "g"), "livePage");
9
- };
10
-
11
- export const useTitleSummaryOverlay = (
12
- entry,
13
- isLive = false,
14
- interval: number
15
- ) => {
16
- // TODO: Have generic place for live url from configuration. Currently its hardcoded for client.
17
- const feedUrl = getLiveUrl(entry?.extensions?.live?.channel_src ?? "");
18
- const player = usePlayer();
19
- const [title, setTitle] = useState<string | number>(entry?.title || "");
20
- const [summary, setSummary] = useState<string | number>(entry?.summary || "");
21
-
22
- // Hook to load feed data
23
- const { data: feedData, reloadData } = useFeedLoader({ feedUrl });
24
-
25
- useEffect(() => {
26
- if (player && feedUrl && isLive) {
27
- const observer = new OverlaysObserver({ player });
28
-
29
- observer.setFeedDataHandlers(feedUrl, reloadData, interval, (entry) => {
30
- setTitle(entry?.title || "");
31
- setSummary(entry?.summary || "");
32
- });
33
-
34
- const subscription = observer
35
- .getTitleSummaryObservable()
36
- .subscribe(({ title, summary }) => {
37
- setTitle(title);
38
- setSummary(summary);
39
- });
40
-
41
- return () => {
42
- subscription.unsubscribe();
43
- observer.clearFeedDataInterval();
44
- };
45
- }
46
- }, [player, feedUrl, reloadData, isLive]);
47
-
48
- useEffect(() => {
49
- if (isLive && feedData?.entry?.[0]) {
50
- setTitle(feedData.entry[0].title || "");
51
- setSummary(feedData.entry[0].summary || "");
52
- }
53
- }, [feedData]);
54
-
55
- return { title, summary };
56
- };