@streamscloud/embeddable 6.3.2 → 6.3.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.
|
@@ -3,6 +3,7 @@ import type { IPlayerItemsProvider } from '../../ui/player';
|
|
|
3
3
|
export declare class InternalShortVideoPlayerProvider implements IPlayerItemsProvider<ShortVideoViewerModel> {
|
|
4
4
|
initialData: IPlayerItemsProvider<ShortVideoViewerModel>['initialData'];
|
|
5
5
|
private ids;
|
|
6
|
+
private idOrder;
|
|
6
7
|
private initialId?;
|
|
7
8
|
private graphql;
|
|
8
9
|
private dataLoader;
|
|
@@ -4,21 +4,25 @@ import { CursorDataLoader } from '../../core/data-loaders';
|
|
|
4
4
|
import { createLocalGQLClient } from '../../core/graphql';
|
|
5
5
|
import { mapToShortVideoViewerModel } from '../short-video-viewer';
|
|
6
6
|
import { GetShortVideosDocument } from './operations.generated';
|
|
7
|
+
const CHUNK_SIZE = 20;
|
|
7
8
|
export class InternalShortVideoPlayerProvider {
|
|
8
9
|
initialData;
|
|
9
10
|
ids;
|
|
11
|
+
idOrder = new Map();
|
|
10
12
|
initialId;
|
|
11
13
|
graphql;
|
|
12
14
|
dataLoader = new CursorDataLoader({
|
|
13
15
|
loadPage: async (continuationToken) => {
|
|
16
|
+
const startIdIndex = continuationToken.value ? parseInt(continuationToken.value, 10) : 0;
|
|
17
|
+
const endIdIndex = Math.min(startIdIndex + CHUNK_SIZE, this.ids.length);
|
|
18
|
+
const idsChunk = this.ids.slice(startIdIndex, endIdIndex);
|
|
14
19
|
try {
|
|
15
20
|
const payload = await this.graphql
|
|
16
21
|
.query(GetShortVideosDocument, {
|
|
17
22
|
input: {
|
|
18
|
-
limit:
|
|
19
|
-
continuationToken,
|
|
23
|
+
limit: idsChunk.length,
|
|
20
24
|
filter: {
|
|
21
|
-
ids:
|
|
25
|
+
ids: idsChunk
|
|
22
26
|
}
|
|
23
27
|
},
|
|
24
28
|
image_scale: ImageScale.OriginalEncoded
|
|
@@ -28,9 +32,14 @@ export class InternalShortVideoPlayerProvider {
|
|
|
28
32
|
if (!data) {
|
|
29
33
|
return null;
|
|
30
34
|
}
|
|
35
|
+
const items = data.items.map(mapToShortVideoViewerModel).sort((a, b) => {
|
|
36
|
+
const ia = this.idOrder.get(a.id) ?? Number.MAX_SAFE_INTEGER;
|
|
37
|
+
const ib = this.idOrder.get(b.id) ?? Number.MAX_SAFE_INTEGER;
|
|
38
|
+
return ia - ib;
|
|
39
|
+
});
|
|
31
40
|
return {
|
|
32
|
-
items
|
|
33
|
-
continuationToken: ContinuationToken.fromPayload(
|
|
41
|
+
items,
|
|
42
|
+
continuationToken: ContinuationToken.fromPayload(endIdIndex < this.ids.length ? endIdIndex.toString() : null)
|
|
34
43
|
};
|
|
35
44
|
}
|
|
36
45
|
catch {
|
|
@@ -42,6 +51,7 @@ export class InternalShortVideoPlayerProvider {
|
|
|
42
51
|
const { ids, graphqlOrigin, initiator, initialId } = input;
|
|
43
52
|
this.graphql = createLocalGQLClient(graphqlOrigin, initiator ? { 'x-initiator': initiator } : undefined);
|
|
44
53
|
this.ids = ids;
|
|
54
|
+
ids.forEach((id, idx) => this.idOrder.set(id, idx));
|
|
45
55
|
this.initialId = initialId;
|
|
46
56
|
this.initialData = { prefetchedItems: [], startIndex: 0 };
|
|
47
57
|
}
|