@amityco/ts-sdk-react-native 6.24.2-d89a258.0 → 6.25.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.
- package/.env +26 -26
- package/dist/@types/core/events.d.ts +2 -0
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/core/model.d.ts +4 -2
- package/dist/@types/core/model.d.ts.map +1 -1
- package/dist/@types/core/payload.d.ts +2 -1
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/domains/stream.d.ts +19 -3
- package/dist/@types/domains/stream.d.ts.map +1 -1
- package/dist/client/api/index.d.ts +2 -0
- package/dist/client/api/index.d.ts.map +1 -1
- package/dist/client/api/registerPushNotification.d.ts +2 -0
- package/dist/client/api/registerPushNotification.d.ts.map +1 -0
- package/dist/client/api/unregisterPushNotification.d.ts +2 -0
- package/dist/client/api/unregisterPushNotification.d.ts.map +1 -0
- package/dist/core/events.d.ts +3 -3
- package/dist/core/events.d.ts.map +1 -1
- package/dist/core/model/idResolvers.d.ts.map +1 -1
- package/dist/core/model/index.d.ts.map +1 -1
- package/dist/index.cjs.js +144 -25
- package/dist/index.esm.js +144 -25
- package/dist/index.umd.js +3 -4
- package/dist/reactionRepository/events/onReactorAdded.d.ts.map +1 -1
- package/dist/reactionRepository/events/onReactorRemoved.d.ts.map +1 -1
- package/dist/streamRepository/api/createStream.d.ts +4 -4
- package/dist/streamRepository/api/createStream.d.ts.map +1 -1
- package/dist/streamRepository/api/deleteStream.d.ts +4 -4
- package/dist/streamRepository/api/deleteStream.d.ts.map +1 -1
- package/dist/streamRepository/api/disposeStream.d.ts +4 -4
- package/dist/streamRepository/api/disposeStream.d.ts.map +1 -1
- package/dist/streamRepository/api/queryStreams.d.ts +4 -4
- package/dist/streamRepository/api/queryStreams.d.ts.map +1 -1
- package/dist/streamRepository/api/updateStream.d.ts.map +1 -1
- package/dist/streamRepository/events/index.d.ts +2 -0
- package/dist/streamRepository/events/index.d.ts.map +1 -1
- package/dist/streamRepository/events/onStreamFlagged.d.ts +17 -0
- package/dist/streamRepository/events/onStreamFlagged.d.ts.map +1 -0
- package/dist/streamRepository/events/onStreamRecorded.d.ts +2 -2
- package/dist/streamRepository/events/onStreamRecorded.d.ts.map +1 -1
- package/dist/streamRepository/events/onStreamStarted.d.ts +2 -2
- package/dist/streamRepository/events/onStreamStarted.d.ts.map +1 -1
- package/dist/streamRepository/events/onStreamStopped.d.ts +2 -2
- package/dist/streamRepository/events/onStreamStopped.d.ts.map +1 -1
- package/dist/streamRepository/events/onStreamTerminated.d.ts +17 -0
- package/dist/streamRepository/events/onStreamTerminated.d.ts.map +1 -0
- package/dist/streamRepository/internalApi/queryStreams.d.ts +3 -3
- package/dist/streamRepository/internalApi/queryStreams.d.ts.map +1 -1
- package/dist/streamRepository/observers/getStreamById.d.ts +1 -0
- package/dist/streamRepository/observers/getStreamById.d.ts.map +1 -1
- package/dist/streamRepository/observers/getStreams/GetStreamsLiveCollectionController.d.ts +14 -0
- package/dist/streamRepository/observers/getStreams/GetStreamsLiveCollectionController.d.ts.map +1 -0
- package/dist/streamRepository/observers/getStreams/GetStreamsPageController.d.ts +14 -0
- package/dist/streamRepository/observers/getStreams/GetStreamsPageController.d.ts.map +1 -0
- package/dist/streamRepository/observers/getStreams/GetStreamsQueryStreamController.d.ts +15 -0
- package/dist/streamRepository/observers/getStreams/GetStreamsQueryStreamController.d.ts.map +1 -0
- package/dist/streamRepository/observers/getStreams/getStreams.d.ts +2 -0
- package/dist/streamRepository/observers/getStreams/getStreams.d.ts.map +1 -0
- package/dist/streamRepository/observers/getStreams/index.d.ts +2 -0
- package/dist/streamRepository/observers/getStreams/index.d.ts.map +1 -0
- package/dist/utils/linkedObject/index.d.ts +1 -0
- package/dist/utils/linkedObject/index.d.ts.map +1 -1
- package/dist/utils/linkedObject/streamLinkedObject.d.ts +2 -0
- package/dist/utils/linkedObject/streamLinkedObject.d.ts.map +1 -0
- package/package.json +3 -1
- package/rollup.config.js +6 -0
- package/src/@types/core/events.ts +5 -1
- package/src/@types/core/model.ts +4 -2
- package/src/@types/core/payload.ts +2 -1
- package/src/@types/domains/stream.ts +23 -3
- package/src/client/api/index.ts +3 -0
- package/src/client/api/registerPushNotification.ts +37 -0
- package/src/client/api/unregisterPushNotification.ts +26 -0
- package/src/core/model/idResolvers.ts +1 -0
- package/src/core/model/index.ts +1 -0
- package/src/reactionRepository/events/onReactorAdded.ts +6 -1
- package/src/reactionRepository/events/onReactorRemoved.ts +6 -1
- package/src/streamRepository/api/createStream.ts +8 -5
- package/src/streamRepository/api/deleteStream.ts +6 -4
- package/src/streamRepository/api/disposeStream.ts +5 -5
- package/src/streamRepository/api/queryStreams.ts +4 -4
- package/src/streamRepository/api/updateStream.ts +2 -1
- package/src/streamRepository/events/index.ts +2 -0
- package/src/streamRepository/events/onStreamFlagged.ts +37 -0
- package/src/streamRepository/events/onStreamRecorded.ts +4 -2
- package/src/streamRepository/events/onStreamStarted.ts +4 -2
- package/src/streamRepository/events/onStreamStopped.ts +4 -2
- package/src/streamRepository/events/onStreamTerminated.ts +37 -0
- package/src/streamRepository/internalApi/queryStreams.ts +3 -3
- package/src/streamRepository/observers/getStreamById.ts +18 -5
- package/src/streamRepository/observers/getStreams/GetStreamsLiveCollectionController.ts +114 -0
- package/src/streamRepository/observers/getStreams/GetStreamsPageController.ts +23 -0
- package/src/streamRepository/observers/getStreams/GetStreamsQueryStreamController.ts +83 -0
- package/src/streamRepository/observers/getStreams/getStreams.ts +32 -0
- package/src/streamRepository/observers/getStreams/index.ts +1 -0
- package/src/streamRepository/observers/tests/getStreamById.test.ts +1 -1
- package/src/utils/linkedObject/index.ts +2 -0
- package/src/utils/linkedObject/streamLinkedObject.ts +11 -0
|
@@ -47,7 +47,12 @@ export const onReactorAdded = (
|
|
|
47
47
|
callbackWrapper('message', payload.messages[0].messageId, payload.reactions[0]);
|
|
48
48
|
};
|
|
49
49
|
|
|
50
|
-
return createEventSubscriber(
|
|
50
|
+
return createEventSubscriber(
|
|
51
|
+
client,
|
|
52
|
+
'reaction/onReactorAdded',
|
|
53
|
+
'message.reactionAdded',
|
|
54
|
+
filter,
|
|
55
|
+
);
|
|
51
56
|
}
|
|
52
57
|
|
|
53
58
|
if (referenceType === 'post') {
|
|
@@ -47,7 +47,12 @@ export const onReactorRemoved = (
|
|
|
47
47
|
callbackWrapper('message', payload.messages[0].messageId, payload.reactions[0]);
|
|
48
48
|
};
|
|
49
49
|
|
|
50
|
-
return createEventSubscriber(
|
|
50
|
+
return createEventSubscriber(
|
|
51
|
+
client,
|
|
52
|
+
'reaction/onReactorRemoved',
|
|
53
|
+
'message.reactionRemoved',
|
|
54
|
+
filter,
|
|
55
|
+
);
|
|
51
56
|
}
|
|
52
57
|
|
|
53
58
|
if (referenceType === 'post') {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getActiveClient } from '~/client/api';
|
|
2
2
|
|
|
3
3
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
4
|
+
import { LinkedObject } from '~/utils/linkedObject';
|
|
4
5
|
|
|
5
6
|
/* begin_public_function
|
|
6
7
|
id: stream.create
|
|
@@ -11,16 +12,18 @@ import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
|
11
12
|
* const created = await createStream({ title: 'my stream', 'thumbnailFileId': fileId })
|
|
12
13
|
* ```
|
|
13
14
|
*
|
|
14
|
-
* Creates an {@link Amity.
|
|
15
|
+
* Creates an {@link Amity.InternalStream}
|
|
15
16
|
*
|
|
16
|
-
* @param bundle The data necessary to create a new {@link Amity.
|
|
17
|
-
* @returns The newly created {@link Amity.
|
|
17
|
+
* @param bundle The data necessary to create a new {@link Amity.InternalStream}
|
|
18
|
+
* @returns The newly created {@link Amity.InternalStream}
|
|
18
19
|
*
|
|
19
20
|
* @category Stream API
|
|
20
21
|
* @async
|
|
21
22
|
*/
|
|
22
23
|
export const createStream = async (
|
|
23
|
-
bundle: Pick<Amity.
|
|
24
|
+
bundle: Pick<Amity.InternalStream, 'title' | 'thumbnailFileId' | 'description'> & {
|
|
25
|
+
isSecure?: boolean;
|
|
26
|
+
},
|
|
24
27
|
): Promise<Amity.Cached<Amity.Stream>> => {
|
|
25
28
|
const client = getActiveClient();
|
|
26
29
|
client.log('stream/createStream', bundle);
|
|
@@ -33,7 +36,7 @@ export const createStream = async (
|
|
|
33
36
|
const { videoStreamings } = data;
|
|
34
37
|
|
|
35
38
|
return {
|
|
36
|
-
data: videoStreamings[0],
|
|
39
|
+
data: LinkedObject.stream(videoStreamings[0]),
|
|
37
40
|
cachedAt,
|
|
38
41
|
};
|
|
39
42
|
};
|
|
@@ -15,15 +15,17 @@ import { getStream } from './getStream';
|
|
|
15
15
|
* const success = await deleteStream(streamId)
|
|
16
16
|
* ```
|
|
17
17
|
*
|
|
18
|
-
* Deletes a {@link Amity.
|
|
18
|
+
* Deletes a {@link Amity.InternalStream}
|
|
19
19
|
*
|
|
20
|
-
* @param streamId The {@link Amity.
|
|
21
|
-
* @return A success boolean if the {@link Amity.
|
|
20
|
+
* @param streamId The {@link Amity.InternalStream} ID to delete
|
|
21
|
+
* @return A success boolean if the {@link Amity.InternalStream} was deleted
|
|
22
22
|
*
|
|
23
23
|
* @category Stream API
|
|
24
24
|
* @async
|
|
25
25
|
*/
|
|
26
|
-
export const deleteStream = async (
|
|
26
|
+
export const deleteStream = async (
|
|
27
|
+
streamId: Amity.InternalStream['streamId'],
|
|
28
|
+
): Promise<boolean> => {
|
|
27
29
|
const client = getActiveClient();
|
|
28
30
|
client.log('stream/deleteStream', streamId);
|
|
29
31
|
|
|
@@ -8,18 +8,18 @@ import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
|
8
8
|
* const stream = await disposeStream(streamId)
|
|
9
9
|
* ```
|
|
10
10
|
*
|
|
11
|
-
* Dispose a {@link Amity.
|
|
11
|
+
* Dispose a {@link Amity.InternalStream}.
|
|
12
12
|
* Streaming status will be updated to "ended" and streaming url will be invalidated
|
|
13
13
|
*
|
|
14
|
-
* @param streamId The {@link Amity.
|
|
15
|
-
* @returns the associated {@link Amity.
|
|
14
|
+
* @param streamId The {@link Amity.InternalStream} ID to dispose
|
|
15
|
+
* @returns the associated {@link Amity.InternalStream} object
|
|
16
16
|
*
|
|
17
17
|
* @category Stream API
|
|
18
18
|
* @async
|
|
19
19
|
*/
|
|
20
20
|
export const disposeStream = async (
|
|
21
|
-
streamId: Amity.
|
|
22
|
-
): Promise<Amity.Cached<Amity.
|
|
21
|
+
streamId: Amity.InternalStream['streamId'],
|
|
22
|
+
): Promise<Amity.Cached<Amity.InternalStream>> => {
|
|
23
23
|
const client = getActiveClient();
|
|
24
24
|
client.log('stream/disposeStream', streamId);
|
|
25
25
|
|
|
@@ -14,10 +14,10 @@ import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
|
14
14
|
* const streams = await getStreams()
|
|
15
15
|
* ```
|
|
16
16
|
*
|
|
17
|
-
* Queries a paginable list of {@link Amity.
|
|
17
|
+
* Queries a paginable list of {@link Amity.InternalStream} objects
|
|
18
18
|
*
|
|
19
19
|
* @param query The query parameters
|
|
20
|
-
* @returns A page of {@link Amity.
|
|
20
|
+
* @returns A page of {@link Amity.InternalStream} objects
|
|
21
21
|
*
|
|
22
22
|
* @category Stream API
|
|
23
23
|
* @async
|
|
@@ -27,9 +27,9 @@ export const queryStreams = async (query?: {
|
|
|
27
27
|
statuses?: Amity.StreamStatus[];
|
|
28
28
|
userPublicIds?: Amity.InternalUser['userId'][];
|
|
29
29
|
sortBy?: 'lastCreated' | 'firstCreated';
|
|
30
|
-
isDeleted?: Amity.
|
|
30
|
+
isDeleted?: Amity.InternalStream['isDeleted'];
|
|
31
31
|
page?: Amity.Page;
|
|
32
|
-
}): Promise<Amity.Cached<Amity.Paged<Amity.
|
|
32
|
+
}): Promise<Amity.Cached<Amity.Paged<Amity.InternalStream>>> => {
|
|
33
33
|
const client = getActiveClient();
|
|
34
34
|
client.log('stream/queryStreams', query);
|
|
35
35
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getActiveClient } from '~/client/api';
|
|
2
2
|
|
|
3
3
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
4
|
+
import { LinkedObject } from '~/utils/linkedObject';
|
|
4
5
|
|
|
5
6
|
/* begin_public_function
|
|
6
7
|
id: stream.update
|
|
@@ -38,7 +39,7 @@ export const updateStream = async (
|
|
|
38
39
|
const { videoStreamings } = data;
|
|
39
40
|
|
|
40
41
|
return {
|
|
41
|
-
data: videoStreamings.find(stream => stream.streamId === streamId)
|
|
42
|
+
data: LinkedObject.stream(videoStreamings.find(stream => stream.streamId === streamId)!),
|
|
42
43
|
cachedAt,
|
|
43
44
|
};
|
|
44
45
|
};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export { onStreamStarted } from './onStreamStarted';
|
|
2
2
|
export { onStreamStopped } from './onStreamStopped';
|
|
3
3
|
export { onStreamRecorded } from './onStreamRecorded';
|
|
4
|
+
export { onStreamFlagged } from './onStreamFlagged';
|
|
5
|
+
export { onStreamTerminated } from './onStreamTerminated';
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { getActiveClient } from '~/client/api';
|
|
2
|
+
import { createEventSubscriber } from '~/core/events';
|
|
3
|
+
|
|
4
|
+
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* ```js
|
|
8
|
+
* import { onStreamFlagged } from '@amityco/ts-sdk-react-native'
|
|
9
|
+
* const dispose = onStreamFlagged(stream => {
|
|
10
|
+
* // ...
|
|
11
|
+
* })
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* Fired when a {@link Amity.InternalStream} has started airing
|
|
15
|
+
*
|
|
16
|
+
* @param callback The function to call when the event was fired
|
|
17
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
18
|
+
*
|
|
19
|
+
* @category Stream Events
|
|
20
|
+
*/
|
|
21
|
+
export const onStreamFlagged = (
|
|
22
|
+
callback: Amity.Listener<Amity.InternalStream>,
|
|
23
|
+
): Amity.Unsubscriber => {
|
|
24
|
+
const client = getActiveClient();
|
|
25
|
+
|
|
26
|
+
const filter = (payload: Amity.StreamPayload) => {
|
|
27
|
+
ingestInCache(payload);
|
|
28
|
+
callback(payload.videoStreamings[0]);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
return createEventSubscriber(
|
|
32
|
+
client,
|
|
33
|
+
'stream/onStreamFlagged',
|
|
34
|
+
'v3.video-streaming.didFlag',
|
|
35
|
+
filter,
|
|
36
|
+
);
|
|
37
|
+
};
|
|
@@ -11,14 +11,16 @@ import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
|
11
11
|
* })
|
|
12
12
|
* ```
|
|
13
13
|
*
|
|
14
|
-
* Fired when the recordings of a {@link Amity.
|
|
14
|
+
* Fired when the recordings of a {@link Amity.InternalStream} are available
|
|
15
15
|
*
|
|
16
16
|
* @param callback The function to call when the event was fired
|
|
17
17
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
18
18
|
*
|
|
19
19
|
* @category Stream Events
|
|
20
20
|
*/
|
|
21
|
-
export const onStreamRecorded = (
|
|
21
|
+
export const onStreamRecorded = (
|
|
22
|
+
callback: Amity.Listener<Amity.InternalStream>,
|
|
23
|
+
): Amity.Unsubscriber => {
|
|
22
24
|
const client = getActiveClient();
|
|
23
25
|
|
|
24
26
|
const filter = (payload: Amity.StreamPayload) => {
|
|
@@ -11,14 +11,16 @@ import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
|
11
11
|
* })
|
|
12
12
|
* ```
|
|
13
13
|
*
|
|
14
|
-
* Fired when a {@link Amity.
|
|
14
|
+
* Fired when a {@link Amity.InternalStream} has started airing
|
|
15
15
|
*
|
|
16
16
|
* @param callback The function to call when the event was fired
|
|
17
17
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
18
18
|
*
|
|
19
19
|
* @category Stream Events
|
|
20
20
|
*/
|
|
21
|
-
export const onStreamStarted = (
|
|
21
|
+
export const onStreamStarted = (
|
|
22
|
+
callback: Amity.Listener<Amity.InternalStream>,
|
|
23
|
+
): Amity.Unsubscriber => {
|
|
22
24
|
const client = getActiveClient();
|
|
23
25
|
|
|
24
26
|
const filter = (payload: Amity.StreamPayload) => {
|
|
@@ -11,14 +11,16 @@ import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
|
11
11
|
* })
|
|
12
12
|
* ```
|
|
13
13
|
*
|
|
14
|
-
* Fired when a {@link Amity.
|
|
14
|
+
* Fired when a {@link Amity.InternalStream} has stopped airing
|
|
15
15
|
*
|
|
16
16
|
* @param callback The function to call when the event was fired
|
|
17
17
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
18
18
|
*
|
|
19
19
|
* @category Stream Events
|
|
20
20
|
*/
|
|
21
|
-
export const onStreamStopped = (
|
|
21
|
+
export const onStreamStopped = (
|
|
22
|
+
callback: Amity.Listener<Amity.InternalStream>,
|
|
23
|
+
): Amity.Unsubscriber => {
|
|
22
24
|
const client = getActiveClient();
|
|
23
25
|
|
|
24
26
|
const filter = (payload: Amity.StreamPayload) => {
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { getActiveClient } from '~/client/api';
|
|
2
|
+
import { createEventSubscriber } from '~/core/events';
|
|
3
|
+
|
|
4
|
+
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* ```js
|
|
8
|
+
* import { onStreamTerminated } from '@amityco/ts-sdk-react-native'
|
|
9
|
+
* const dispose = onStreamTerminated(stream => {
|
|
10
|
+
* // ...
|
|
11
|
+
* })
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* Fired when a {@link Amity.InternalStream} has started airing
|
|
15
|
+
*
|
|
16
|
+
* @param callback The function to call when the event was fired
|
|
17
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
18
|
+
*
|
|
19
|
+
* @category Stream Events
|
|
20
|
+
*/
|
|
21
|
+
export const onStreamTerminated = (
|
|
22
|
+
callback: Amity.Listener<Amity.InternalStream>,
|
|
23
|
+
): Amity.Unsubscriber => {
|
|
24
|
+
const client = getActiveClient();
|
|
25
|
+
|
|
26
|
+
const filter = (payload: Amity.StreamPayload) => {
|
|
27
|
+
ingestInCache(payload);
|
|
28
|
+
callback(payload.videoStreamings[0]);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
return createEventSubscriber(
|
|
32
|
+
client,
|
|
33
|
+
'stream/onStreamTerminated',
|
|
34
|
+
'v3.video-streaming.didTerminate',
|
|
35
|
+
filter,
|
|
36
|
+
);
|
|
37
|
+
};
|
|
@@ -11,17 +11,17 @@ import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
|
11
11
|
* const streams = await getStreams()
|
|
12
12
|
* ```
|
|
13
13
|
*
|
|
14
|
-
* Queries a paginable list of {@link Amity.
|
|
14
|
+
* Queries a paginable list of {@link Amity.InternalStream} objects
|
|
15
15
|
*
|
|
16
16
|
* @param query The query parameters
|
|
17
|
-
* @returns A page of {@link Amity.
|
|
17
|
+
* @returns A page of {@link Amity.InternalStream} objects
|
|
18
18
|
*
|
|
19
19
|
* @category Stream API
|
|
20
20
|
* @async
|
|
21
21
|
*/
|
|
22
22
|
export const queryStreams = async (
|
|
23
23
|
query?: Amity.QueryStreams,
|
|
24
|
-
): Promise<Amity.Cached<Amity.PageToken<Amity.
|
|
24
|
+
): Promise<Amity.Cached<Amity.PageToken<Amity.InternalStream>>> => {
|
|
25
25
|
const client = getActiveClient();
|
|
26
26
|
client.log('stream/queryStreams', query);
|
|
27
27
|
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
/* eslint-disable no-use-before-define */
|
|
2
2
|
|
|
3
|
-
import { onStreamRecorded, onStreamStarted, onStreamStopped } from '../events';
|
|
4
|
-
import { getStream as _getStream } from '../api/getStream';
|
|
5
3
|
import { liveObject } from '~/utils/liveObject';
|
|
6
4
|
import { getActiveClient } from '~/client';
|
|
7
5
|
import { pullFromCache } from '~/cache/api';
|
|
6
|
+
import { onStreamFlagged } from '~/streamRepository/events/onStreamFlagged';
|
|
7
|
+
import { onStreamTerminated } from '~/streamRepository/events/onStreamTerminated';
|
|
8
|
+
import { LinkedObject } from '~/utils/linkedObject';
|
|
9
|
+
import { getStream as _getStream } from '../api/getStream';
|
|
10
|
+
import { onStreamRecorded, onStreamStarted, onStreamStopped } from '../events';
|
|
8
11
|
|
|
9
12
|
/* begin_public_function
|
|
10
13
|
id: stream.get
|
|
@@ -19,6 +22,7 @@ import { pullFromCache } from '~/cache/api';
|
|
|
19
22
|
* Fetches a {@link Amity.Stream} object
|
|
20
23
|
*
|
|
21
24
|
* @param streamId the ID of the {@link Amity.Stream} to get
|
|
25
|
+
* @param callback
|
|
22
26
|
* @returns the associated {@link Amity.Stream} object
|
|
23
27
|
*
|
|
24
28
|
* @category Stream Live Object
|
|
@@ -28,10 +32,19 @@ export const getStreamById = (
|
|
|
28
32
|
streamId: Amity.Stream['streamId'],
|
|
29
33
|
callback: Amity.LiveObjectCallback<Amity.Stream>,
|
|
30
34
|
): Amity.Unsubscriber => {
|
|
31
|
-
|
|
35
|
+
const reactor: Amity.LiveObjectCallback<Amity.InternalStream> = (
|
|
36
|
+
snapshot: Amity.LiveObject<Amity.InternalStream>,
|
|
37
|
+
) => {
|
|
38
|
+
const { data } = snapshot;
|
|
39
|
+
callback({ ...snapshot, data: data ? LinkedObject.stream(snapshot.data) : data });
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
return liveObject(streamId, reactor, 'streamId', _getStream, [
|
|
32
43
|
onStreamRecorded,
|
|
33
44
|
onStreamStarted,
|
|
34
45
|
onStreamStopped,
|
|
46
|
+
onStreamFlagged,
|
|
47
|
+
onStreamTerminated,
|
|
35
48
|
]);
|
|
36
49
|
};
|
|
37
50
|
/* end_public_function */
|
|
@@ -57,12 +70,12 @@ getStreamById.locally = (
|
|
|
57
70
|
|
|
58
71
|
if (!client.cache) return;
|
|
59
72
|
|
|
60
|
-
const cached = pullFromCache<Amity.
|
|
73
|
+
const cached = pullFromCache<Amity.InternalStream>(['stream', 'get', streamId]);
|
|
61
74
|
|
|
62
75
|
if (!cached) return;
|
|
63
76
|
|
|
64
77
|
return {
|
|
65
|
-
data: cached.data,
|
|
78
|
+
data: LinkedObject.stream(cached.data),
|
|
66
79
|
cachedAt: cached.cachedAt,
|
|
67
80
|
};
|
|
68
81
|
};
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import hash from 'object-hash';
|
|
2
|
+
import { LiveCollectionController } from '~/core/liveCollection/LiveCollectionController';
|
|
3
|
+
import { pullFromCache, pushToCache } from '~/cache/api';
|
|
4
|
+
import { LinkedObject } from '~/utils/linkedObject';
|
|
5
|
+
import { filterByPropEquality, sortByFirstCreated, sortByLastCreated } from '~/core/query';
|
|
6
|
+
import {
|
|
7
|
+
onStreamFlagged,
|
|
8
|
+
onStreamRecorded,
|
|
9
|
+
onStreamStarted,
|
|
10
|
+
onStreamStopped,
|
|
11
|
+
onStreamTerminated,
|
|
12
|
+
} from '~/streamRepository/events';
|
|
13
|
+
import { GetStreamsPageController } from '~/streamRepository/observers/getStreams/GetStreamsPageController';
|
|
14
|
+
import { GetStreamsQueryStreamController } from '~/streamRepository/observers/getStreams/GetStreamsQueryStreamController';
|
|
15
|
+
|
|
16
|
+
export class GetStreamsLiveCollectionController extends LiveCollectionController<
|
|
17
|
+
'stream',
|
|
18
|
+
Amity.StreamLiveCollection,
|
|
19
|
+
Amity.Stream,
|
|
20
|
+
GetStreamsPageController
|
|
21
|
+
> {
|
|
22
|
+
private queryStreamController: GetStreamsQueryStreamController;
|
|
23
|
+
|
|
24
|
+
private query: Amity.StreamLiveCollection;
|
|
25
|
+
|
|
26
|
+
constructor(
|
|
27
|
+
query: Amity.StreamLiveCollection,
|
|
28
|
+
callback: Amity.LiveCollectionCallback<Amity.Stream>,
|
|
29
|
+
) {
|
|
30
|
+
const queryStreamId = hash(query);
|
|
31
|
+
const cacheKey = ['streams', 'collection', queryStreamId];
|
|
32
|
+
const paginationController = new GetStreamsPageController(query);
|
|
33
|
+
|
|
34
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
35
|
+
|
|
36
|
+
this.query = query;
|
|
37
|
+
|
|
38
|
+
this.queryStreamController = new GetStreamsQueryStreamController(
|
|
39
|
+
this.query,
|
|
40
|
+
this.cacheKey,
|
|
41
|
+
this.notifyChange.bind(this),
|
|
42
|
+
paginationController,
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
this.paginationController = paginationController;
|
|
46
|
+
this.callback = callback.bind(this);
|
|
47
|
+
this.loadPage({ initial: true });
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
notifyChange({ origin, loading, error }: Amity.LiveCollectionNotifyParams) {
|
|
51
|
+
const collection = pullFromCache<Amity.StreamLiveCollectionCache>(this.cacheKey)?.data;
|
|
52
|
+
if (!collection) return;
|
|
53
|
+
|
|
54
|
+
let data = collection.data
|
|
55
|
+
.map(streamId => pullFromCache<Amity.InternalStream>(['stream', 'get', streamId])!)
|
|
56
|
+
.filter(Boolean)
|
|
57
|
+
.map(stream => LinkedObject.stream(stream.data));
|
|
58
|
+
|
|
59
|
+
if (!this.shouldNotify(data) && origin === 'event') return;
|
|
60
|
+
|
|
61
|
+
data = this.applyFilter(data);
|
|
62
|
+
|
|
63
|
+
this.callback({
|
|
64
|
+
onNextPage: () =>
|
|
65
|
+
this.loadPage({ initial: false, direction: Amity.LiveCollectionPageDirection.NEXT }),
|
|
66
|
+
data,
|
|
67
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
68
|
+
loading,
|
|
69
|
+
error,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
startSubscription() {
|
|
74
|
+
return this.queryStreamController.subscribeRTE([
|
|
75
|
+
{ fn: onStreamRecorded, action: 'onStreamRecorded' },
|
|
76
|
+
{ fn: onStreamStarted, action: 'onStreamStarted' },
|
|
77
|
+
{ fn: onStreamStopped, action: 'onStreamStopped' },
|
|
78
|
+
{ fn: onStreamFlagged, action: 'onStreamFlagged' },
|
|
79
|
+
{ fn: onStreamTerminated, action: 'onStreamTerminated' },
|
|
80
|
+
]);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
protected setup() {
|
|
84
|
+
const collection = pullFromCache<Amity.StreamLiveCollectionCache>(this.cacheKey)?.data;
|
|
85
|
+
if (!collection) {
|
|
86
|
+
pushToCache(this.cacheKey, {
|
|
87
|
+
data: [],
|
|
88
|
+
params: {},
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
protected persistModel(response: Amity.StreamPayload) {
|
|
94
|
+
this.queryStreamController.saveToMainDB(response);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
protected persistQueryStream({
|
|
98
|
+
response,
|
|
99
|
+
direction,
|
|
100
|
+
refresh,
|
|
101
|
+
}: Amity.LiveCollectionPersistQueryStreamParams<'stream'>) {
|
|
102
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
private applyFilter = (data: Amity.InternalStream[]): Amity.InternalStream[] => {
|
|
106
|
+
let streams = filterByPropEquality(data, 'isDeleted', this.query.isDeleted);
|
|
107
|
+
|
|
108
|
+
streams = streams.sort(
|
|
109
|
+
this.query.sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated,
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
return streams;
|
|
113
|
+
};
|
|
114
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { PaginationController } from '~/core/liveCollection/PaginationController';
|
|
2
|
+
import { COLLECTION_DEFAULT_PAGINATION_LIMIT } from '~/utils/constants';
|
|
3
|
+
|
|
4
|
+
export class GetStreamsPageController extends PaginationController<
|
|
5
|
+
'stream',
|
|
6
|
+
Amity.StreamLiveCollection
|
|
7
|
+
> {
|
|
8
|
+
async getRequest(queryParams: Amity.StreamLiveCollection, token: string | undefined) {
|
|
9
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, ...params } = queryParams;
|
|
10
|
+
const options = token ? { token } : { limit };
|
|
11
|
+
|
|
12
|
+
const { data: queryResponse } = await this.http.get<
|
|
13
|
+
{ results: Amity.StreamPayload } & Amity.Pagination
|
|
14
|
+
>(`/api/v3/video-streaming`, {
|
|
15
|
+
params: {
|
|
16
|
+
...params,
|
|
17
|
+
options,
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
return { ...queryResponse.results, paging: queryResponse.paging };
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { QueryStreamController } from '~/core/liveCollection/QueryStreamController';
|
|
2
|
+
import { getActiveClient } from '~/client';
|
|
3
|
+
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
4
|
+
import { GetStreamsPageController } from '~/streamRepository/observers/getStreams/GetStreamsPageController';
|
|
5
|
+
import { getResolver } from '~/core/model';
|
|
6
|
+
import { pullFromCache, pushToCache } from '~/cache/api';
|
|
7
|
+
|
|
8
|
+
export class GetStreamsQueryStreamController extends QueryStreamController<
|
|
9
|
+
Amity.StreamPayload,
|
|
10
|
+
Amity.StreamLiveCollection
|
|
11
|
+
> {
|
|
12
|
+
private notifyChange: (params: Amity.LiveCollectionNotifyParams) => void;
|
|
13
|
+
|
|
14
|
+
private paginationController: GetStreamsPageController;
|
|
15
|
+
|
|
16
|
+
constructor(
|
|
17
|
+
query: Amity.StreamLiveCollection,
|
|
18
|
+
cacheKey: string[],
|
|
19
|
+
notifyChange: (params: Amity.LiveCollectionNotifyParams) => void,
|
|
20
|
+
paginationController: GetStreamsPageController,
|
|
21
|
+
) {
|
|
22
|
+
super(query, cacheKey);
|
|
23
|
+
this.notifyChange = notifyChange;
|
|
24
|
+
this.paginationController = paginationController;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// eslint-disable-next-line class-methods-use-this
|
|
28
|
+
saveToMainDB(response: Amity.StreamPayload) {
|
|
29
|
+
const client = getActiveClient();
|
|
30
|
+
const cachedAt = client.cache && Date.now();
|
|
31
|
+
|
|
32
|
+
if (client.cache) {
|
|
33
|
+
ingestInCache(response, { cachedAt });
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
appendToQueryStream(
|
|
38
|
+
response: Amity.StreamPayload & Partial<Amity.Pagination>,
|
|
39
|
+
direction: Amity.LiveCollectionPageDirection,
|
|
40
|
+
refresh = false,
|
|
41
|
+
) {
|
|
42
|
+
if (refresh) {
|
|
43
|
+
pushToCache(this.cacheKey, {
|
|
44
|
+
data: response.videoStreamings.map(getResolver('stream')),
|
|
45
|
+
query: this.query,
|
|
46
|
+
});
|
|
47
|
+
} else {
|
|
48
|
+
const collection = pullFromCache<Amity.StreamLiveCollectionCache>(this.cacheKey)?.data;
|
|
49
|
+
|
|
50
|
+
const messages = collection?.data ?? [];
|
|
51
|
+
|
|
52
|
+
pushToCache(this.cacheKey, {
|
|
53
|
+
...collection,
|
|
54
|
+
data:
|
|
55
|
+
direction === 'next'
|
|
56
|
+
? [...new Set([...messages, ...response.videoStreamings.map(getResolver('stream'))])]
|
|
57
|
+
: [...new Set([...response.videoStreamings.map(getResolver('stream')), ...messages])],
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
reactor(action: string) {
|
|
63
|
+
return (payload: Amity.InternalStream) => {
|
|
64
|
+
const collection = pullFromCache<Amity.StreamLiveCollectionCache>(this.cacheKey)?.data;
|
|
65
|
+
if (!collection) return;
|
|
66
|
+
|
|
67
|
+
collection.data = [...new Set([payload.streamId, ...collection.data])];
|
|
68
|
+
|
|
69
|
+
pushToCache(this.cacheKey, collection);
|
|
70
|
+
|
|
71
|
+
this.notifyChange({ origin: Amity.LiveDataOrigin.EVENT, loading: false });
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
subscribeRTE(
|
|
76
|
+
createSubscriber: {
|
|
77
|
+
fn: (reactor: Amity.Listener<Amity.InternalStream>) => Amity.Unsubscriber;
|
|
78
|
+
action: string;
|
|
79
|
+
}[],
|
|
80
|
+
) {
|
|
81
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { getActiveClient } from '~/client';
|
|
2
|
+
import { ENABLE_CACHE_MESSAGE } from '~/utils/constants';
|
|
3
|
+
import { dropFromCache } from '~/cache/api';
|
|
4
|
+
import { GetStreamsLiveCollectionController } from '~/streamRepository/observers/getStreams/GetStreamsLiveCollectionController';
|
|
5
|
+
|
|
6
|
+
export const getStreams = (
|
|
7
|
+
params: Amity.StreamLiveCollection,
|
|
8
|
+
callback: Amity.LiveCollectionCallback<Amity.Stream>,
|
|
9
|
+
config?: Amity.LiveCollectionConfig,
|
|
10
|
+
) => {
|
|
11
|
+
const { log, cache, userId } = getActiveClient();
|
|
12
|
+
|
|
13
|
+
if (!cache) {
|
|
14
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const timestamp = Date.now();
|
|
18
|
+
log(`getStreams(tmpid: ${timestamp}) > listen`);
|
|
19
|
+
|
|
20
|
+
const liveCollection = new GetStreamsLiveCollectionController(params, callback);
|
|
21
|
+
const disposers = liveCollection.startSubscription();
|
|
22
|
+
const cacheKey = liveCollection.getCacheKey();
|
|
23
|
+
|
|
24
|
+
disposers.push(() => {
|
|
25
|
+
dropFromCache(cacheKey);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
return () => {
|
|
29
|
+
log(`getStreams(tmpid: ${timestamp}) > dispose`);
|
|
30
|
+
disposers.forEach(fn => fn());
|
|
31
|
+
};
|
|
32
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './getStreams';
|
|
@@ -6,7 +6,7 @@ const STREAM_ID = streamResponse.data.videoStreamings[0].streamId;
|
|
|
6
6
|
|
|
7
7
|
const getSnapshot = (params?: Record<string, any>) => {
|
|
8
8
|
return {
|
|
9
|
-
data: undefined as undefined | Amity.
|
|
9
|
+
data: undefined as undefined | Amity.InternalStream,
|
|
10
10
|
loading: true,
|
|
11
11
|
error: undefined as any,
|
|
12
12
|
...params,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { storyLinkedObject } from '~/utils/linkedObject/storyLinkedObject';
|
|
2
|
+
import { streamLinkedObject } from '~/utils/linkedObject/streamLinkedObject';
|
|
2
3
|
import { categoryLinkedObject } from './categoryLinkedObject';
|
|
3
4
|
import { commentLinkedObject } from './commentLinkedObject';
|
|
4
5
|
import { userLinkedObject } from './userLinkedObject';
|
|
@@ -13,6 +14,7 @@ export const LinkedObject = {
|
|
|
13
14
|
post: postLinkedObject,
|
|
14
15
|
user: userLinkedObject,
|
|
15
16
|
category: categoryLinkedObject,
|
|
17
|
+
stream: streamLinkedObject,
|
|
16
18
|
story: storyLinkedObject,
|
|
17
19
|
storyTarget: storyTargetLinkedObject,
|
|
18
20
|
message: messageLinkedObject,
|