@amityco/ts-sdk 7.7.1-99f7166.0 → 7.7.1-b56aa2f.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.
Files changed (35) hide show
  1. package/dist/@types/core/events.d.ts +1 -1
  2. package/dist/@types/core/events.d.ts.map +1 -1
  3. package/dist/@types/core/payload.d.ts +1 -1
  4. package/dist/@types/core/payload.d.ts.map +1 -1
  5. package/dist/@types/domains/channel.d.ts +1 -0
  6. package/dist/@types/domains/channel.d.ts.map +1 -1
  7. package/dist/channelRepository/events/onChannelSetUserMuted.d.ts.map +1 -1
  8. package/dist/channelRepository/internalApi/getMyMembership.d.ts +11 -0
  9. package/dist/channelRepository/internalApi/getMyMembership.d.ts.map +1 -0
  10. package/dist/channelRepository/observers/getMyMembership.d.ts +2 -0
  11. package/dist/channelRepository/observers/getMyMembership.d.ts.map +1 -0
  12. package/dist/core/events.d.ts +3 -3
  13. package/dist/core/events.d.ts.map +1 -1
  14. package/dist/index.cjs.js +2642 -2548
  15. package/dist/index.esm.js +622 -528
  16. package/dist/index.umd.js +3 -3
  17. package/dist/liveStreamPlayer/utils/eventRegister.d.ts +2 -1
  18. package/dist/liveStreamPlayer/utils/eventRegister.d.ts.map +1 -1
  19. package/dist/streamRepository/events/index.d.ts +2 -0
  20. package/dist/streamRepository/events/index.d.ts.map +1 -1
  21. package/dist/utils/linkedObject/channelLinkedObject.d.ts.map +1 -1
  22. package/package.json +1 -1
  23. package/src/@types/core/events.ts +1 -1
  24. package/src/@types/core/payload.ts +1 -1
  25. package/src/@types/domains/channel.ts +3 -0
  26. package/src/channelRepository/api/createChannel.ts +1 -1
  27. package/src/channelRepository/events/onChannelSetUserMuted.ts +11 -13
  28. package/src/channelRepository/internalApi/getMyMembership.ts +37 -0
  29. package/src/channelRepository/observers/getMyMembership.ts +98 -0
  30. package/src/core/events.ts +3 -1
  31. package/src/liveStreamPlayer/api/getPlayer.ts +1 -1
  32. package/src/liveStreamPlayer/utils/eventRegister.ts +16 -1
  33. package/src/streamRepository/events/index.ts +2 -0
  34. package/src/utils/linkedObject/channelLinkedObject.ts +3 -0
  35. package/src/utils/linkedObject/postLinkedObject.ts +2 -2
@@ -7,7 +7,8 @@ export declare class EventRegister {
7
7
  _controller: AbortController;
8
8
  _sessionId: null | string;
9
9
  _observer: MutationObserver;
10
- constructor(player: HTMLVideoElement, resolution: string);
10
+ _SDKUnsubscribers: Amity.Unsubscriber[];
11
+ constructor(player: HTMLVideoElement, resolution: string, streamId: string);
11
12
  _resetStartTime(): void;
12
13
  _shouldUpdateCollector(): boolean;
13
14
  _sendUsageToCollector(): void;
@@ -1 +1 @@
1
- {"version":3,"file":"eventRegister.d.ts","sourceRoot":"","sources":["../../../src/liveStreamPlayer/utils/eventRegister.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAkB7D,qBAAa,aAAa;IACxB,MAAM,EAAE,gBAAgB,CAAC;IAEzB,UAAU,EAAE,IAAI,GAAG,MAAM,CAAC;IAE1B,eAAe,EAAE,UAAU,CAAC,OAAO,iBAAiB,CAAC,CAAC;IAEtD,UAAU,EAAE,IAAI,GAAG,MAAM,CAAC;IAE1B,WAAW,EAAE,eAAe,CAAC;IAE7B,UAAU,EAAE,IAAI,GAAG,MAAM,CAAC;IAE1B,SAAS,EAAE,gBAAgB,CAAC;gBAEhB,MAAM,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM;IA2BxD,eAAe;IAIf,sBAAsB;IAatB,qBAAqB;IAsBrB,cAAc;IA4Dd,iBAAiB;CAMlB"}
1
+ {"version":3,"file":"eventRegister.d.ts","sourceRoot":"","sources":["../../../src/liveStreamPlayer/utils/eventRegister.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAmB7D,qBAAa,aAAa;IACxB,MAAM,EAAE,gBAAgB,CAAC;IAEzB,UAAU,EAAE,IAAI,GAAG,MAAM,CAAC;IAE1B,eAAe,EAAE,UAAU,CAAC,OAAO,iBAAiB,CAAC,CAAC;IAEtD,UAAU,EAAE,IAAI,GAAG,MAAM,CAAC;IAE1B,WAAW,EAAE,eAAe,CAAC;IAE7B,UAAU,EAAE,IAAI,GAAG,MAAM,CAAC;IAE1B,SAAS,EAAE,gBAAgB,CAAC;IAE5B,iBAAiB,EAAE,KAAK,CAAC,YAAY,EAAE,CAAM;gBAEjC,MAAM,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;IAuC1E,eAAe;IAIf,sBAAsB;IAatB,qBAAqB;IAsBrB,cAAc;IA4Dd,iBAAiB;CAMlB"}
@@ -3,4 +3,6 @@ export { onStreamStopped } from './onStreamStopped';
3
3
  export { onStreamRecorded } from './onStreamRecorded';
4
4
  export { onStreamFlagged } from './onStreamFlagged';
5
5
  export { onStreamTerminated } from './onStreamTerminated';
6
+ export { onStreamViewerBanned } from './onStreamViewerBanned';
7
+ export { onStreamViewerUnbanned } from './onStreamViewerUnbanned';
6
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/streamRepository/events/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/streamRepository/events/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"channelLinkedObject.d.ts","sourceRoot":"","sources":["../../../src/utils/linkedObject/channelLinkedObject.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,mBAAmB,YAAa,MAAM,eAAe,KAAG,MAAM,OAqB1E,CAAC"}
1
+ {"version":3,"file":"channelLinkedObject.d.ts","sourceRoot":"","sources":["../../../src/utils/linkedObject/channelLinkedObject.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,mBAAmB,YAAa,MAAM,eAAe,KAAG,MAAM,OAuB1E,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amityco/ts-sdk",
3
- "version": "7.7.1-99f7166.0",
3
+ "version": "7.7.1-b56aa2f.0",
4
4
  "license": "CC-BY-ND-4.0",
5
5
  "author": "amity.co <developers@amity.co> (https://amity.co)",
6
6
  "description": "Amity Social Cloud Typescript SDK",
@@ -64,7 +64,7 @@ declare global {
64
64
  'channel.updated': Amity.ChannelPayload;
65
65
  'channel.deleted': Amity.ChannelPayload;
66
66
  'channel.setMuted': Amity.ChannelSetMutedPayload;
67
- 'channel.setUserMuted': Amity.ChannelSetUserMutedPayload;
67
+ 'channel.setMutedUsers': Amity.ChannelSetUserMutedPayload;
68
68
  } & MqttChannelUserEvents;
69
69
 
70
70
  type MqttSubChannelEvents = {
@@ -619,6 +619,6 @@ declare global {
619
619
  type StreamViewerBanPayload = RawStreamViewerBan[];
620
620
  type StreamViewerUnbanPayload = RawStreamViewerBan[];
621
621
 
622
- type ChannelSetUserMutedPayload = RawChannelSetUserMuted[];
622
+ type ChannelSetUserMutedPayload = RawChannelSetUserMuted;
623
623
  }
624
624
  }
@@ -100,6 +100,9 @@ declare global {
100
100
  messagePreview?: Amity.MessagePreview | null;
101
101
  markAsRead: () => Promise<boolean>;
102
102
  previewMembers: Amity.Membership<'channel'>[];
103
+ myMembership: (
104
+ callback: Amity.LiveObjectCallback<Amity.Membership<'channel'> | undefined>,
105
+ ) => Amity.Unsubscriber;
103
106
  };
104
107
 
105
108
  type QueryChannels = {
@@ -2,7 +2,7 @@ import { getActiveClient } from '~/client/api/activeClient';
2
2
 
3
3
  import { ingestInCache } from '~/cache/api/ingestInCache';
4
4
 
5
- import { prepareChannelPayload } from '../utils/prepareChannelPayload';
5
+ import { prepareChannelPayload } from '../utils';
6
6
  import { constructChannelObject } from '../utils/constructChannelObject';
7
7
 
8
8
  /* begin_public_function
@@ -26,27 +26,25 @@ export const onChannelSetUserMuted = (
26
26
  if (callbacks.length === 0) {
27
27
  const client = getActiveClient();
28
28
 
29
- const filter = async (payloads: Amity.ChannelSetUserMutedPayload) => {
30
- payloads.forEach(payload => {
31
- payload.userIds.forEach(userId =>
32
- // If muteTimeout > now => user is muted
33
- // Otherwise => user is unmuted
34
- upsertInCache(['channelUsers', 'get', `${payload.channelId}#${userId}`], {
35
- isMuted: Date.parse(payload.muteTimeout) > Date.now(),
36
- }),
37
- );
38
- });
29
+ const filter = async (payload: Amity.ChannelSetUserMutedPayload) => {
30
+ payload.userIds.forEach(userId =>
31
+ // If muteTimeout > now => user is muted
32
+ // Otherwise => user is unmuted
33
+ upsertInCache(['channelUsers', 'get', `${payload.channelId}#${userId}`], {
34
+ isMuted: Date.parse(payload.muteTimeout) > Date.now(),
35
+ }),
36
+ );
39
37
 
40
38
  const channel = pullFromCache<Amity.StaticInternalChannel>([
41
39
  'channel',
42
40
  'get',
43
- payloads[0].channelId,
41
+ payload.channelId,
44
42
  ])?.data;
45
43
 
46
44
  const channelUser = pullFromCache<Amity.Membership<'channel'>>([
47
45
  'channelUsers',
48
46
  'get',
49
- `${payloads[0].channelId}#${payloads[0].userIds[0]}`,
47
+ `${payload.channelId}#${payload.userIds[0]}`,
50
48
  ])?.data;
51
49
 
52
50
  if (channel && channelUser) {
@@ -57,7 +55,7 @@ export const onChannelSetUserMuted = (
57
55
  mainDisposer = createEventSubscriber(
58
56
  client,
59
57
  'onChannelUserMute',
60
- 'channel.setUserMuted',
58
+ 'channel.setMutedUsers',
61
59
  filter,
62
60
  );
63
61
  }
@@ -0,0 +1,37 @@
1
+ import { pullFromCache } from '~/cache/api/pullFromCache';
2
+ import { getActiveClient } from '~/client/api/activeClient';
3
+ import { ASCApiError } from '~/core/errors';
4
+
5
+ /**
6
+ *
7
+ * get current user's membership data
8
+ *
9
+ * @returns the {@link Amity.Membership<'channel'>} objects
10
+ *
11
+ * @category Channel API
12
+ * @async
13
+ */
14
+
15
+ export const getMyMembership = (channelId: string): Amity.Cached<Amity.Membership<'channel'>> => {
16
+ const client = getActiveClient();
17
+ client.log('channel/getMyMembership.locally');
18
+
19
+ const cacheChannelUser = pullFromCache<Amity.Membership<'channel'>>([
20
+ 'channelUsers',
21
+ 'get',
22
+ `${channelId}#${client.userId}`,
23
+ ]);
24
+
25
+ if (!cacheChannelUser) {
26
+ throw new ASCApiError(
27
+ 'Item not found!',
28
+ Amity.ServerError.ITEM_NOT_FOUND,
29
+ Amity.ErrorLevel.ERROR,
30
+ );
31
+ }
32
+
33
+ return {
34
+ data: cacheChannelUser.data,
35
+ cachedAt: cacheChannelUser.cachedAt,
36
+ };
37
+ };
@@ -0,0 +1,98 @@
1
+ import { getActiveUser } from '~/client/api/activeUser';
2
+ import { getMyMembership as _getMyMembership } from '../internalApi/getMyMembership';
3
+ import { ASCApiError, ASCError } from '~/core/errors';
4
+ import { getActiveClient } from '~/client/api/activeClient';
5
+ import { isEqual } from '~/utils/isEqual';
6
+ import { createQuery, runQuery } from '~/core/query';
7
+ import {
8
+ UNSYNCED_OBJECT_CACHED_AT_MESSAGE,
9
+ UNSYNCED_OBJECT_CACHED_AT_VALUE,
10
+ } from '~/utils/constants';
11
+ import { channelMemberLinkedObject } from '~/utils/linkedObject/channelMemberLinkedObject';
12
+ import { onChannelMemberBanned, onChannelMemberUnbanned } from '../events';
13
+ import { onChannelSetUserMuted } from '../events/onChannelSetUserMuted';
14
+
15
+ export const getMyMembership = (
16
+ channelId: string,
17
+ callback: Amity.LiveObjectCallback<Amity.Membership<'channel'> | undefined>,
18
+ ): Amity.Unsubscriber => {
19
+ const { _id: userId } = getActiveUser();
20
+
21
+ if (!userId)
22
+ throw new ASCError(
23
+ 'The _id has not been defined in ActiveUser',
24
+ Amity.ClientError.UNKNOWN_ERROR,
25
+ Amity.ErrorLevel.ERROR,
26
+ );
27
+
28
+ const { log, cache } = getActiveClient();
29
+
30
+ if (!cache) {
31
+ console.log('This observable object need the cache data!');
32
+ }
33
+
34
+ const timestamp = Date.now();
35
+ log(`liveMymembership(tmpid: ${timestamp}) > listen`);
36
+
37
+ const disposers: Amity.Unsubscriber[] = [];
38
+
39
+ let isUnsyncedModel = false; // for messages
40
+
41
+ let model: Amity.Membership<'channel'> | undefined;
42
+
43
+ const dispatcher = (data: Amity.LiveObject<Amity.Membership<'channel'> | undefined>) => {
44
+ callback({
45
+ ...data,
46
+ data: data.data ? channelMemberLinkedObject(data.data) : data.data,
47
+ });
48
+ };
49
+
50
+ const realtimeRouter = (_: Amity.StaticInternalChannel, __: Amity.RawMembership<'channel'>) => {
51
+ const { data } = _getMyMembership(channelId);
52
+
53
+ if (isEqual(model, data)) return;
54
+
55
+ dispatcher({
56
+ loading: false,
57
+ data,
58
+ });
59
+ };
60
+
61
+ const onFetch = () => {
62
+ const query = createQuery(async () => _getMyMembership(channelId));
63
+
64
+ runQuery(query, ({ error, data, loading, origin, cachedAt }) => {
65
+ if (cachedAt === UNSYNCED_OBJECT_CACHED_AT_VALUE) {
66
+ dispatcher({
67
+ data,
68
+ origin,
69
+ loading: false,
70
+ error: new ASCApiError(
71
+ UNSYNCED_OBJECT_CACHED_AT_MESSAGE,
72
+ Amity.ClientError.DISALOOW_UNSYNCED_OBJECT,
73
+ Amity.ErrorLevel.ERROR,
74
+ ),
75
+ });
76
+
77
+ isUnsyncedModel = true;
78
+ disposers.forEach(fn => fn());
79
+ } else if (!isUnsyncedModel) {
80
+ dispatcher({ loading, data, origin, error });
81
+ }
82
+
83
+ if (error) {
84
+ disposers.forEach(fn => fn());
85
+ }
86
+ });
87
+ };
88
+
89
+ disposers.push(onChannelMemberBanned(realtimeRouter));
90
+ disposers.push(onChannelMemberUnbanned(realtimeRouter));
91
+ disposers.push(onChannelSetUserMuted(realtimeRouter));
92
+
93
+ onFetch();
94
+
95
+ return () => {
96
+ disposers.forEach(fn => fn());
97
+ };
98
+ };
@@ -32,7 +32,9 @@ const MQTT_EVENTS = [
32
32
  'video-streaming.didFlag',
33
33
  'video-streaming.didTerminate',
34
34
 
35
- // 'user.didGlobalBan' remove due to message event,
35
+ 'video-streaming.viewerDidBan',
36
+ 'video-streaming.viewerDidUnban',
37
+
36
38
  'liveReaction.created',
37
39
  ] as const;
38
40
 
@@ -60,7 +60,7 @@ export const getPlayer = async (parameters: { streamId: string }): Promise<HTMLV
60
60
  video.src = recording.mp4.url;
61
61
  }
62
62
 
63
- new EventRegister(video, resolution).registerEvents();
63
+ new EventRegister(video, resolution, streamId).registerEvents();
64
64
 
65
65
  return video;
66
66
  };
@@ -1,5 +1,6 @@
1
1
  import uuid from 'react-native-uuid';
2
2
  import { getUsageCollector } from '../api/getUsageCollector';
3
+ import { onStreamViewerBanned } from '~/streamRepository/events';
3
4
 
4
5
  const SECOND = 1000;
5
6
  /*
@@ -32,7 +33,9 @@ export class EventRegister {
32
33
 
33
34
  _observer: MutationObserver;
34
35
 
35
- constructor(player: HTMLVideoElement, resolution: string) {
36
+ _SDKUnsubscribers: Amity.Unsubscriber[] = [];
37
+
38
+ constructor(player: HTMLVideoElement, resolution: string, streamId: string) {
36
39
  this.player = player;
37
40
  this.resolution = resolution;
38
41
  this._startTime = null;
@@ -53,10 +56,22 @@ export class EventRegister {
53
56
  mutation.removedNodes.forEach(node => {
54
57
  if (node === player) {
55
58
  this._unregisterEvents();
59
+ this._SDKUnsubscribers.forEach(fn => fn?.());
56
60
  }
57
61
  });
58
62
  });
59
63
  });
64
+
65
+ this._SDKUnsubscribers.push(
66
+ onStreamViewerBanned(stream => {
67
+ // if still has stream.watcherUrl, the current user has not banned.
68
+ if (stream.watcherUrl) return;
69
+ this.player.pause();
70
+ this.player.removeAttribute('src');
71
+ this.player.load();
72
+ this.player.remove();
73
+ }),
74
+ );
60
75
  }
61
76
 
62
77
  _resetStartTime() {
@@ -3,3 +3,5 @@ export { onStreamStopped } from './onStreamStopped';
3
3
  export { onStreamRecorded } from './onStreamRecorded';
4
4
  export { onStreamFlagged } from './onStreamFlagged';
5
5
  export { onStreamTerminated } from './onStreamTerminated';
6
+ export { onStreamViewerBanned } from './onStreamViewerBanned';
7
+ export { onStreamViewerUnbanned } from './onStreamViewerUnbanned';
@@ -2,6 +2,7 @@ import { markAsRead } from '~/channelRepository/internalApi/markAsRead';
2
2
  import { shallowClone } from '../shallowClone';
3
3
  import { queryCache } from '~/cache/api';
4
4
  import { channelMemberLinkedObject } from './channelMemberLinkedObject';
5
+ import { getMyMembership } from '~/channelRepository/observers/getMyMembership';
5
6
 
6
7
  export const channelLinkedObject = (channel: Amity.InternalChannel): Amity.Channel => {
7
8
  let previewMembers: Amity.Membership<'channel'>[] = [];
@@ -23,5 +24,7 @@ export const channelLinkedObject = (channel: Amity.InternalChannel): Amity.Chann
23
24
  return shallowClone(channel, {
24
25
  markAsRead: () => markAsRead(channel.channelInternalId),
25
26
  previewMembers,
27
+ myMembership: (callback: Amity.LiveObjectCallback<Amity.Membership<'channel'> | undefined>) =>
28
+ getMyMembership(channel.channelId, callback),
26
29
  });
27
30
  };
@@ -76,7 +76,7 @@ export const postLinkedObject = (post: Amity.InternalPost): Amity.Post => {
76
76
  ? pullFromCache<Amity.File<'file'>>(['file', 'get', post?.data?.fileId])?.data
77
77
  : undefined;
78
78
  },
79
-
79
+
80
80
  getLivestreamInfo(): Amity.Stream | undefined {
81
81
  if (!isAmityLivestreamPost(post)) return;
82
82
  const cache = pullFromCache<Amity.InternalStream>([
@@ -95,7 +95,7 @@ export const postLinkedObject = (post: Amity.InternalPost): Amity.Post => {
95
95
  if (!cache) return;
96
96
  return cache;
97
97
  },
98
-
98
+
99
99
  getClipInfo(): Amity.File<'clip'> | undefined {
100
100
  return isAmityClipPost(post)
101
101
  ? pullFromCache<Amity.File<'clip'>>(['file', 'get', post?.data?.fileId])?.data