@applicaster/zapp-react-native-utils 13.0.17-alpha.2239590470 → 13.0.17-rc.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.
|
@@ -5,6 +5,7 @@ import { createLogger, utilsLogger } from "../../../logger";
|
|
|
5
5
|
import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
|
|
6
6
|
import {
|
|
7
7
|
findPluginByIdentifier,
|
|
8
|
+
loadFeedEntry,
|
|
8
9
|
loadFeedAndPrefetchThumbnailImage,
|
|
9
10
|
parseTimeToSeconds,
|
|
10
11
|
retrieveFeedUrl,
|
|
@@ -41,6 +42,19 @@ export type ChapterMarkerEvent = {
|
|
|
41
42
|
actions: ActionChapter[];
|
|
42
43
|
};
|
|
43
44
|
|
|
45
|
+
export type LiveMetadataEvent = {
|
|
46
|
+
programId: string;
|
|
47
|
+
assetId: string;
|
|
48
|
+
title: string;
|
|
49
|
+
programStartTime: string;
|
|
50
|
+
programEndTime: string;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export type LiveMetadataConfig = {
|
|
54
|
+
updateUrl: string;
|
|
55
|
+
updateInterval: number;
|
|
56
|
+
};
|
|
57
|
+
|
|
44
58
|
export type TitleSummaryEvent = {
|
|
45
59
|
title: string | number;
|
|
46
60
|
summary: string | number;
|
|
@@ -65,11 +79,13 @@ export type PlayNextState = PlayNextConfig & {
|
|
|
65
79
|
export class OverlaysObserver {
|
|
66
80
|
readonly chapterSubject: BehaviorSubject<ChapterMarkerEvent>;
|
|
67
81
|
private playNextSubject: BehaviorSubject<PlayNextState>;
|
|
82
|
+
private liveMetadataSubject: BehaviorSubject<LiveMetadataEvent>;
|
|
68
83
|
private titleSummarySubject: BehaviorSubject<TitleSummaryEvent>;
|
|
69
84
|
private feedUrl: string;
|
|
70
85
|
private reloadData: () => void;
|
|
71
86
|
private updateTitleAndDescription: (data: any) => void;
|
|
72
87
|
private feedDataInterval: any;
|
|
88
|
+
private liveMetadataUpdateInterval: any;
|
|
73
89
|
private releasePlayerObserver?: () => void;
|
|
74
90
|
readonly entry: ZappEntry;
|
|
75
91
|
private chapterMarkerEvents: ChapterMarkerEvent[];
|
|
@@ -81,13 +97,17 @@ export class OverlaysObserver {
|
|
|
81
97
|
this.chapterSubject = new BehaviorSubject(null);
|
|
82
98
|
this.playNextSubject = new BehaviorSubject(null);
|
|
83
99
|
|
|
100
|
+
this.player = player;
|
|
101
|
+
this.entry = player.getEntry();
|
|
102
|
+
|
|
84
103
|
this.titleSummarySubject = new BehaviorSubject<TitleSummaryEvent>({
|
|
85
|
-
title:
|
|
86
|
-
summary:
|
|
104
|
+
title: this.entry?.title || "",
|
|
105
|
+
summary: this.entry?.summary || "",
|
|
87
106
|
});
|
|
88
107
|
|
|
89
|
-
this.
|
|
90
|
-
|
|
108
|
+
this.liveMetadataSubject = new BehaviorSubject<LiveMetadataEvent>(
|
|
109
|
+
this.entry?.extensions?.liveMetadata || null
|
|
110
|
+
);
|
|
91
111
|
|
|
92
112
|
this.chapterMarkerEvents = this.prepareChapterMarkers();
|
|
93
113
|
this.releasePlayerObserver = this.subscribeToPlayerEvents();
|
|
@@ -95,7 +115,9 @@ export class OverlaysObserver {
|
|
|
95
115
|
this.reloadData = () => {};
|
|
96
116
|
this.updateTitleAndDescription = () => {};
|
|
97
117
|
this.feedDataInterval = null;
|
|
118
|
+
this.liveMetadataUpdateInterval = null;
|
|
98
119
|
void this.preparePlayNext();
|
|
120
|
+
void this.prepareLiveMetadata();
|
|
99
121
|
}
|
|
100
122
|
|
|
101
123
|
private setupFeedDataInterval(interval: number) {
|
|
@@ -113,6 +135,13 @@ export class OverlaysObserver {
|
|
|
113
135
|
}
|
|
114
136
|
}
|
|
115
137
|
|
|
138
|
+
public clearLiveMetadataUpdateInterval() {
|
|
139
|
+
if (this.liveMetadataUpdateInterval) {
|
|
140
|
+
clearInterval(this.liveMetadataUpdateInterval);
|
|
141
|
+
this.liveMetadataUpdateInterval = null;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
116
145
|
public setFeedDataHandlers(
|
|
117
146
|
feedUrl: string,
|
|
118
147
|
reloadData: () => void,
|
|
@@ -212,6 +241,48 @@ export class OverlaysObserver {
|
|
|
212
241
|
}
|
|
213
242
|
};
|
|
214
243
|
|
|
244
|
+
prepareLiveMetadata = async () => {
|
|
245
|
+
if (!this.player?.isLive?.()) {
|
|
246
|
+
log_debug("prepareLiveMetadata: Player is not live. Skipping...");
|
|
247
|
+
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
const config: LiveMetadataConfig =
|
|
252
|
+
this.entry?.extensions?.liveMetadataConfig;
|
|
253
|
+
|
|
254
|
+
if (!config?.updateUrl || !config?.updateInterval) {
|
|
255
|
+
log_debug(
|
|
256
|
+
"prepareLiveMetadata: Live metadata configuration is not available. Skipping...",
|
|
257
|
+
{ config }
|
|
258
|
+
);
|
|
259
|
+
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
const reloadData = async () => {
|
|
264
|
+
try {
|
|
265
|
+
const entry = await loadFeedEntry(config.updateUrl, this.entry);
|
|
266
|
+
|
|
267
|
+
this.onLiveMetadataUpdated(entry?.extensions?.liveMetadata || null);
|
|
268
|
+
} catch (error) {
|
|
269
|
+
log_error("prepareLiveMetadata: Metadata fetching failed", {
|
|
270
|
+
error,
|
|
271
|
+
config,
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
log_debug("prepareLiveMetadata: Setting up live metadata observer update", {
|
|
277
|
+
config,
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
const interval = Number(config?.updateInterval) || 60;
|
|
281
|
+
|
|
282
|
+
this.clearLiveMetadataUpdateInterval();
|
|
283
|
+
this.liveMetadataUpdateInterval = setInterval(reloadData, interval * 1000);
|
|
284
|
+
};
|
|
285
|
+
|
|
215
286
|
// TODO: Hack for video end, will be replaced with playlist prev/next in the future
|
|
216
287
|
getPlayNextEntry = () =>
|
|
217
288
|
!this.isCanceledByUser ? this.playNextConfig?.entry : null;
|
|
@@ -332,9 +403,11 @@ export class OverlaysObserver {
|
|
|
332
403
|
onPlayerClose = () => {
|
|
333
404
|
this.chapterSubject.complete();
|
|
334
405
|
this.playNextSubject.complete();
|
|
406
|
+
this.liveMetadataSubject.complete();
|
|
335
407
|
this.titleSummarySubject.complete();
|
|
336
408
|
this.releasePlayerObserver?.();
|
|
337
409
|
this.clearFeedDataInterval();
|
|
410
|
+
this.clearLiveMetadataUpdateInterval();
|
|
338
411
|
this.releasePlayerObserver = null;
|
|
339
412
|
};
|
|
340
413
|
|
|
@@ -367,4 +440,21 @@ export class OverlaysObserver {
|
|
|
367
440
|
(prev, curr) => prev?.triggerTime === curr?.triggerTime
|
|
368
441
|
)
|
|
369
442
|
);
|
|
443
|
+
|
|
444
|
+
private onLiveMetadataUpdated = (liveMetadataEvent: LiveMetadataEvent) => {
|
|
445
|
+
this.liveMetadataSubject.next(liveMetadataEvent);
|
|
446
|
+
};
|
|
447
|
+
|
|
448
|
+
public getLiveMetadataObservable = (): Observable<LiveMetadataEvent> => {
|
|
449
|
+
return this.liveMetadataSubject.pipe(
|
|
450
|
+
distinctUntilChanged(
|
|
451
|
+
(prev, curr) =>
|
|
452
|
+
prev?.programId === curr?.programId && prev?.assetId === curr?.assetId
|
|
453
|
+
)
|
|
454
|
+
);
|
|
455
|
+
};
|
|
456
|
+
|
|
457
|
+
public getLiveMetadataValue = (): LiveMetadataEvent => {
|
|
458
|
+
return this.liveMetadataSubject.value;
|
|
459
|
+
};
|
|
370
460
|
}
|
|
@@ -92,22 +92,26 @@ export const prefetchImage = (playableItem: ZappEntry, config: any = {}) => {
|
|
|
92
92
|
}
|
|
93
93
|
};
|
|
94
94
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
95
|
+
/**
|
|
96
|
+
* Loads a feed entry from the given feed URL using the provided Zapp entry as context.
|
|
97
|
+
*
|
|
98
|
+
* @param {string} feedUrl - The URL of the feed to load the entry from.
|
|
99
|
+
* @param {ZappEntry} entry - The Zapp entry to use as context for the request.
|
|
100
|
+
* @returns {Promise<ZappEntry>} A promise that resolves to the loaded Zapp entry.
|
|
101
|
+
* @throws {Error} If the feed loading fails or no entry is found in the response.
|
|
102
|
+
*/
|
|
103
|
+
export const loadFeedEntry = async (feedUrl: string, entry: ZappEntry) => {
|
|
100
104
|
const requestBuilder = new RequestBuilder()
|
|
101
105
|
.setEntryContext(entry)
|
|
102
106
|
.setScreenContext({} as ZappRiver)
|
|
103
|
-
.setUrl(
|
|
107
|
+
.setUrl(feedUrl);
|
|
104
108
|
|
|
105
109
|
const responseObject = await requestBuilder.call<ZappEntry>();
|
|
106
110
|
const responseHelper = new PipesClientResponseHelper(responseObject);
|
|
107
111
|
|
|
108
112
|
if (responseHelper.error) {
|
|
109
113
|
log_error(
|
|
110
|
-
`
|
|
114
|
+
`loadFeedEntry: loading failed with error: ${responseHelper.error.message}. Observer will not be executed`,
|
|
111
115
|
{
|
|
112
116
|
response: responseHelper.getLogsData(),
|
|
113
117
|
}
|
|
@@ -116,29 +120,37 @@ export const loadFeedAndPrefetchThumbnailImage = async (
|
|
|
116
120
|
throw responseHelper.error;
|
|
117
121
|
} else {
|
|
118
122
|
log_info(
|
|
119
|
-
`
|
|
123
|
+
`loadFeedEntry: Feed was successfully loaded for url: ${feedUrl}`,
|
|
120
124
|
responseHelper.getLogsData()
|
|
121
125
|
);
|
|
122
126
|
|
|
123
|
-
const
|
|
127
|
+
const entry = responseHelper.responseData?.entry[0];
|
|
124
128
|
|
|
125
|
-
if (!
|
|
126
|
-
|
|
127
|
-
"
|
|
128
|
-
responseHelper.getLogsData()
|
|
129
|
-
);
|
|
129
|
+
if (!entry) {
|
|
130
|
+
const error =
|
|
131
|
+
"loadFeedEntry: Can not retrieve entry, feed was loaded but no entry was found";
|
|
130
132
|
|
|
131
|
-
|
|
132
|
-
"Can not retrieve play next entry, feed was loaded but no entry was found"
|
|
133
|
-
);
|
|
134
|
-
}
|
|
133
|
+
log_error(error, responseHelper.getLogsData());
|
|
135
134
|
|
|
136
|
-
|
|
135
|
+
throw new Error(error);
|
|
136
|
+
}
|
|
137
137
|
|
|
138
|
-
return
|
|
138
|
+
return entry;
|
|
139
139
|
}
|
|
140
140
|
};
|
|
141
141
|
|
|
142
|
+
export const loadFeedAndPrefetchThumbnailImage = async (
|
|
143
|
+
playNextFeedUrl: string,
|
|
144
|
+
entry: ZappEntry,
|
|
145
|
+
playNextPlugin
|
|
146
|
+
) => {
|
|
147
|
+
const playNextEntry = await loadFeedEntry(playNextFeedUrl, entry);
|
|
148
|
+
|
|
149
|
+
prefetchImage(playNextEntry, playNextPlugin?.configuration);
|
|
150
|
+
|
|
151
|
+
return playNextEntry;
|
|
152
|
+
};
|
|
153
|
+
|
|
142
154
|
export const findPluginByIdentifier = (
|
|
143
155
|
identifier: string,
|
|
144
156
|
plugins: ZappPlugin[]
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applicaster/zapp-react-native-utils",
|
|
3
|
-
"version": "13.0.17-
|
|
3
|
+
"version": "13.0.17-rc.0",
|
|
4
4
|
"description": "Applicaster Zapp React Native utilities package",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"homepage": "https://github.com/applicaster/quickbrick#readme",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@applicaster/applicaster-types": "13.0.17-
|
|
30
|
+
"@applicaster/applicaster-types": "13.0.17-rc.0",
|
|
31
31
|
"buffer": "^5.2.1",
|
|
32
32
|
"camelize": "^1.0.0",
|
|
33
33
|
"dayjs": "^1.11.10",
|