@amityco/ts-sdk-react-native
Version:
Amity Social Cloud Typescript SDK
46 lines (38 loc) • 1.3 kB
text/typescript
import { getActiveClient } from '~/client/api';
import { createEventSubscriber } from '~/core/events';
import { mergeInCache, pullFromCache } from '~/cache/api';
import { getStream } from '../internalApi/getStream';
/**
* ```js
* import { onStreamViewerUnbanned } from '@amityco/ts-sdk'
* const dispose = onStreamViewerBanned(stream => {
* // ...
* })
* ```
*
* Fired when a user in channel linked to stream has been unbanned
*
* @param callback The function to call when the event was fired
* @returns an {@link Amity.Unsubscriber} function to stop listening
*
* @category Stream Events
*/
export const onStreamViewerUnbanned = (
callback: Amity.Listener<Amity.InternalStream>,
): Amity.Unsubscriber => {
const client = getActiveClient();
const filter = async (payloads: Amity.StreamViewerUnbanPayload) => {
// Get new stream object to restore stream watcherUrl in cache
const { list } = payloads;
await Promise.all(list.map(({ streamId }) => getStream(streamId)));
const stream = pullFromCache<Amity.InternalStream>(['stream', 'get', list[0].streamId])?.data;
if (!stream) return;
callback(stream);
};
return createEventSubscriber(
client,
'stream/onStreamViewerDidUnban',
'video-streaming.viewerDidUnban',
filter,
);
};