@100mslive/hms-video-store 0.2.82 → 0.2.83

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 (92) hide show
  1. package/dist/common/ui-logger.d.ts +13 -13
  2. package/dist/core/IHMSActions.d.ts +266 -264
  3. package/dist/core/IHMSNotifications.d.ts +14 -15
  4. package/dist/core/IHMSStore.d.ts +54 -56
  5. package/dist/core/hmsSDKStore/HMSNotifications.d.ts +25 -25
  6. package/dist/core/hmsSDKStore/HMSPlaylist.d.ts +21 -21
  7. package/dist/core/hmsSDKStore/HMSReactiveStore.d.ts +79 -79
  8. package/dist/core/hmsSDKStore/HMSSDKActions.d.ts +157 -157
  9. package/dist/core/hmsSDKStore/adapter.d.ts +49 -49
  10. package/dist/core/hmsSDKStore/common/mapping.d.ts +7 -7
  11. package/dist/core/hmsSDKStore/internalTypes.d.ts +4 -4
  12. package/dist/core/hmsSDKStore/sdkTypes.d.ts +3 -2
  13. package/dist/core/hmsSDKStore/sdkUtils/ActionBatcher.d.ts +19 -19
  14. package/dist/core/hmsSDKStore/sdkUtils/sdkUtils.d.ts +2 -2
  15. package/dist/core/hmsSDKStore/sdkUtils/storeMergeUtils.d.ts +14 -14
  16. package/dist/core/index.d.ts +9 -7
  17. package/dist/core/schema/device-change.d.ts +13 -13
  18. package/dist/core/schema/error.d.ts +13 -13
  19. package/dist/core/schema/index.d.ts +11 -11
  20. package/dist/core/schema/message.d.ts +31 -31
  21. package/dist/core/schema/notification.d.ts +40 -40
  22. package/dist/core/schema/peer.d.ts +67 -67
  23. package/dist/core/schema/playlist.d.ts +127 -109
  24. package/dist/core/schema/requests.d.ts +31 -31
  25. package/dist/core/schema/role.d.ts +3 -3
  26. package/dist/core/schema/room.d.ts +23 -23
  27. package/dist/core/schema/schema.d.ts +29 -29
  28. package/dist/core/schema/settings.d.ts +5 -5
  29. package/dist/core/selectors/derivedSelectors.d.ts +29 -29
  30. package/dist/core/selectors/index.d.ts +5 -5
  31. package/dist/core/selectors/playlistselectors.d.ts +3 -3
  32. package/dist/core/selectors/selectorUtils.d.ts +18 -18
  33. package/dist/core/selectors/selectors.d.ts +185 -191
  34. package/dist/core/selectors/selectorsByID.d.ts +127 -128
  35. package/dist/core/selectors/selectorsByReference.d.ts +3 -3
  36. package/dist/hms-video-store.cjs.js +1 -0
  37. package/dist/hms-video-store.esm.js +1 -5376
  38. package/dist/index.d.ts +1 -1
  39. package/package.json +21 -84
  40. package/dist/hms-video-store.cjs.development.js +0 -5468
  41. package/dist/hms-video-store.cjs.development.js.map +0 -1
  42. package/dist/hms-video-store.cjs.production.min.js +0 -2
  43. package/dist/hms-video-store.cjs.production.min.js.map +0 -1
  44. package/dist/hms-video-store.esm.js.map +0 -1
  45. package/dist/index.js +0 -8
  46. package/dist/test/fakeStore.d.ts +0 -23
  47. package/dist/test/fixtures.d.ts +0 -3
  48. package/src/common/ui-logger.ts +0 -88
  49. package/src/core/IHMSActions.ts +0 -318
  50. package/src/core/IHMSNotifications.ts +0 -16
  51. package/src/core/IHMSStore.ts +0 -60
  52. package/src/core/hmsSDKStore/HMSNotifications.ts +0 -194
  53. package/src/core/hmsSDKStore/HMSPlaylist.ts +0 -78
  54. package/src/core/hmsSDKStore/HMSReactiveStore.ts +0 -271
  55. package/src/core/hmsSDKStore/HMSSDKActions.ts +0 -1156
  56. package/src/core/hmsSDKStore/adapter.ts +0 -244
  57. package/src/core/hmsSDKStore/common/mapping.ts +0 -32
  58. package/src/core/hmsSDKStore/internalTypes.ts +0 -8
  59. package/src/core/hmsSDKStore/sdkTypes.ts +0 -55
  60. package/src/core/hmsSDKStore/sdkUtils/ActionBatcher.ts +0 -63
  61. package/src/core/hmsSDKStore/sdkUtils/sdkUtils.ts +0 -5
  62. package/src/core/hmsSDKStore/sdkUtils/storeMergeUtils.ts +0 -98
  63. package/src/core/index.ts +0 -18
  64. package/src/core/schema/device-change.ts +0 -14
  65. package/src/core/schema/error.ts +0 -13
  66. package/src/core/schema/index.ts +0 -11
  67. package/src/core/schema/message.ts +0 -35
  68. package/src/core/schema/notification.ts +0 -41
  69. package/src/core/schema/peer.ts +0 -78
  70. package/src/core/schema/playlist.ts +0 -114
  71. package/src/core/schema/requests.ts +0 -36
  72. package/src/core/schema/role.ts +0 -5
  73. package/src/core/schema/room.ts +0 -26
  74. package/src/core/schema/schema.ts +0 -94
  75. package/src/core/schema/settings.ts +0 -5
  76. package/src/core/selectors/derivedSelectors.ts +0 -81
  77. package/src/core/selectors/index.ts +0 -5
  78. package/src/core/selectors/playlistselectors.ts +0 -67
  79. package/src/core/selectors/selectorUtils.ts +0 -63
  80. package/src/core/selectors/selectors.ts +0 -400
  81. package/src/core/selectors/selectorsByID.ts +0 -401
  82. package/src/core/selectors/selectorsByReference.ts +0 -45
  83. package/src/index.ts +0 -1
  84. package/src/test/fakeStore.ts +0 -272
  85. package/src/test/fixtures.ts +0 -22
  86. package/src/test/integration/.gitkeep +0 -0
  87. package/src/test/unit/HMSNotifications.test.ts +0 -123
  88. package/src/test/unit/reactiveStore.test.ts +0 -129
  89. package/src/test/unit/roleSelectors.test.ts +0 -85
  90. package/src/test/unit/selectors.test.ts +0 -316
  91. package/src/test/unit/selectorsByReference.test.ts +0 -27
  92. package/src/test/unit/storeMergeUtils.test.ts +0 -168
@@ -1,244 +0,0 @@
1
- import {
2
- HMSLocalAudioTrack as SDKHMSLocalAudioTrack,
3
- HMSLocalVideoTrack as SDKHMSLocalVideoTrack,
4
- HMSRemoteAudioTrack as SDKHMSRemoteAudioTrack,
5
- HMSRemoteVideoTrack as SDKHMSRemoteVideoTrack,
6
- HMSRoleChangeRequest as SDKHMSRoleChangeRequest,
7
- HMSTrack as SDKHMSTrack,
8
- } from '@100mslive/hms-video';
9
- import {
10
- HMSDeviceChangeEvent,
11
- HMSException,
12
- HMSMessage,
13
- HMSPeer,
14
- HMSPeerID,
15
- HMSPlaylistItem,
16
- HMSPlaylistType,
17
- HMSRole,
18
- HMSRoleChangeStoreRequest,
19
- HMSRoleName,
20
- HMSRoom,
21
- HMSTrack,
22
- } from '../schema';
23
-
24
- import * as sdkTypes from './sdkTypes';
25
- import { areArraysEqual } from './sdkUtils/storeMergeUtils';
26
-
27
- export class SDKToHMS {
28
- static convertPeer(sdkPeer: sdkTypes.HMSPeer): Partial<HMSPeer> & Pick<HMSPeer, 'id'> {
29
- return {
30
- id: sdkPeer.peerId,
31
- name: sdkPeer.name,
32
- roleName: sdkPeer.role?.name,
33
- isLocal: sdkPeer.isLocal,
34
- videoTrack: sdkPeer.videoTrack?.trackId,
35
- audioTrack: sdkPeer.audioTrack?.trackId,
36
- auxiliaryTracks: sdkPeer.auxiliaryTracks.map(track => track.trackId),
37
- customerUserId: sdkPeer.customerUserId,
38
- customerDescription: sdkPeer.metadata,
39
- metadata: sdkPeer.metadata,
40
- };
41
- }
42
-
43
- static convertTrack(sdkTrack: SDKHMSTrack, peerId?: HMSPeerID): HMSTrack {
44
- const track: HMSTrack = {
45
- id: sdkTrack.trackId,
46
- source: sdkTrack.source,
47
- type: sdkTrack.type,
48
- enabled: sdkTrack.enabled,
49
- displayEnabled: sdkTrack.enabled,
50
- peerId: sdkTrack.peerId || peerId,
51
- };
52
- this.enrichTrack(track, sdkTrack);
53
- return track;
54
- }
55
-
56
- static enrichTrack(track: HMSTrack, sdkTrack: SDKHMSTrack) {
57
- const mediaSettings = sdkTrack.getMediaTrackSettings();
58
- if (track.source === 'screen' && track.type === 'video') {
59
- // @ts-ignore
60
- track.displaySurface = mediaSettings.displaySurface;
61
- }
62
- track.height = mediaSettings.height;
63
- track.width = mediaSettings.width;
64
- if (sdkTrack instanceof SDKHMSRemoteAudioTrack) {
65
- track.volume = sdkTrack.getVolume() || 0;
66
- }
67
- SDKToHMS.updateDeviceID(track, sdkTrack);
68
- SDKToHMS.enrichVideoTrack(track, sdkTrack);
69
- SDKToHMS.enrichPluginsDetails(track, sdkTrack);
70
- }
71
-
72
- static updateDeviceID(track: HMSTrack, sdkTrack: SDKHMSTrack) {
73
- if (sdkTrack instanceof SDKHMSLocalVideoTrack || sdkTrack instanceof SDKHMSLocalAudioTrack) {
74
- track.deviceID = sdkTrack.settings.deviceId;
75
- } else {
76
- track.deviceID = sdkTrack.getMediaTrackSettings()?.deviceId;
77
- }
78
- }
79
-
80
- static enrichVideoTrack(track: HMSTrack, sdkTrack: SDKHMSTrack) {
81
- if (sdkTrack instanceof SDKHMSRemoteVideoTrack) {
82
- track.layer = sdkTrack.getSimulcastLayer();
83
- track.degraded = sdkTrack.degraded;
84
- if (!areArraysEqual(sdkTrack.getSimulcastDefinitions(), track.layerDefinitions)) {
85
- track.layerDefinitions = sdkTrack.getSimulcastDefinitions();
86
- }
87
- }
88
- }
89
-
90
- static enrichPluginsDetails(track: HMSTrack, sdkTrack: SDKHMSTrack) {
91
- if (sdkTrack instanceof SDKHMSLocalVideoTrack || sdkTrack instanceof SDKHMSLocalAudioTrack) {
92
- if (!areArraysEqual(sdkTrack.getPlugins(), track.plugins)) {
93
- track.plugins = sdkTrack.getPlugins();
94
- }
95
- }
96
- }
97
-
98
- static convertRoom(sdkRoom: sdkTypes.HMSRoom): Partial<HMSRoom> {
99
- return {
100
- id: sdkRoom.id,
101
- name: sdkRoom.name,
102
- localPeer: sdkRoom.localPeer?.peerId ?? '',
103
- hasWaitingRoom: sdkRoom.hasWaitingRoom,
104
- shareableLink: sdkRoom.shareableLink,
105
- recording: {
106
- browser: {
107
- running: !!sdkRoom.recording?.browser.running,
108
- },
109
- server: { running: !!sdkRoom.recording?.server.running },
110
- },
111
- rtmp: { running: !!sdkRoom.rtmp?.running },
112
- };
113
- }
114
-
115
- static convertMessage(
116
- sdkMessage: sdkTypes.HMSMessage,
117
- ): Partial<HMSMessage> & Pick<HMSMessage, 'sender'> {
118
- return {
119
- sender: sdkMessage.sender.peerId,
120
- senderName: sdkMessage.sender.name,
121
- senderRole: sdkMessage.sender.role?.name,
122
- senderUserId: sdkMessage.sender.customerUserId,
123
- recipientPeer: sdkMessage.recipientPeer?.peerId,
124
- recipientRoles: sdkMessage.recipientRoles?.map(role => role.name),
125
- time: sdkMessage.time,
126
- type: sdkMessage.type,
127
- message: sdkMessage.message,
128
- };
129
- }
130
-
131
- static convertRoles(sdkRoles: HMSRole[]): Record<HMSRoleName, HMSRole> {
132
- const roles: Record<HMSRoleName, HMSRole> = {};
133
- if (sdkRoles) {
134
- sdkRoles.forEach(role => {
135
- roles[role.name] = role;
136
- });
137
- }
138
- return roles;
139
- }
140
-
141
- static convertRoleChangeRequest(req: SDKHMSRoleChangeRequest): HMSRoleChangeStoreRequest {
142
- return {
143
- requestedBy: req.requestedBy.peerId,
144
- roleName: req.role.name,
145
- token: req.token,
146
- };
147
- }
148
-
149
- static convertException(sdkException: sdkTypes.HMSException): HMSException {
150
- return {
151
- code: sdkException.code,
152
- action: sdkException.action,
153
- name: sdkException.name,
154
- message: sdkException.message,
155
- description: sdkException.description,
156
- isTerminal: sdkException.isTerminal,
157
- nativeError: sdkException.nativeError,
158
- timestamp: new Date(),
159
- };
160
- }
161
-
162
- static convertDeviceChangeUpdate(
163
- sdkDeviceChangeEvent: sdkTypes.HMSDeviceChangeEvent,
164
- ): HMSDeviceChangeEvent {
165
- const convertedData: HMSDeviceChangeEvent = {
166
- devices: sdkDeviceChangeEvent.devices,
167
- selection: sdkDeviceChangeEvent.selection,
168
- type: sdkDeviceChangeEvent.type,
169
- };
170
- if (sdkDeviceChangeEvent.error) {
171
- convertedData.error = this.convertException(sdkDeviceChangeEvent.error);
172
- }
173
- return convertedData;
174
- }
175
-
176
- static convertPlaylist(playlistManager: sdkTypes.HMSPlaylistManager) {
177
- const audioPlaylist = this.getConvertedPlaylistType(playlistManager, HMSPlaylistType.audio);
178
- const videoPlaylist = this.getConvertedPlaylistType(playlistManager, HMSPlaylistType.video);
179
- return { audio: audioPlaylist, video: videoPlaylist };
180
- }
181
-
182
- static convertPlaylistItem<T>(
183
- playlistManager: sdkTypes.HMSPlaylistManager,
184
- playlistItem: sdkTypes.HMSPlaylistItem<T>,
185
- ): HMSPlaylistItem<T> {
186
- const type = playlistItem.type;
187
- const currentSelection = playlistManager.getCurrentSelection(type);
188
- const isPlaying = playlistManager.isPlaying(type);
189
- const isSelected = playlistItem.url === currentSelection?.url;
190
-
191
- return {
192
- ...playlistItem,
193
- type: playlistItem.type as HMSPlaylistType,
194
- selected: isSelected,
195
- playing: isSelected && isPlaying,
196
- };
197
- }
198
-
199
- private static getConvertedPlaylistType(
200
- playlistManager: sdkTypes.HMSPlaylistManager,
201
- type: HMSPlaylistType,
202
- ) {
203
- const convertedPlaylist: Record<string, HMSPlaylistItem<any>> = {};
204
- const currentSelection = playlistManager.getCurrentSelection(type);
205
- const progress = playlistManager.getCurrentProgress(type);
206
- const volume = playlistManager.getVolume(type);
207
- const list = playlistManager.getList(type);
208
- const currentIndex = playlistManager.getCurrentIndex(type);
209
-
210
- playlistManager.getList(type).forEach(playlistItem => {
211
- convertedPlaylist[playlistItem.id] = SDKToHMS.convertPlaylistItem(
212
- playlistManager,
213
- playlistItem,
214
- );
215
- });
216
- return {
217
- list: convertedPlaylist,
218
- selection: {
219
- id: currentSelection?.id,
220
- hasPrevious: currentIndex > 0,
221
- hasNext: currentIndex < list.length - 1,
222
- },
223
- progress,
224
- volume,
225
- currentTime: playlistManager.getCurrentTime(type),
226
- playbackRate: playlistManager.getPlaybackRate(type),
227
- };
228
- }
229
-
230
- static convertRecordingRTMPState(
231
- recording: sdkTypes.HMSRecording | undefined,
232
- rtmp: sdkTypes.HMSRTMP | undefined,
233
- ): { recording: sdkTypes.HMSRecording; rtmp: sdkTypes.HMSRTMP } {
234
- return {
235
- recording: {
236
- browser: {
237
- running: !!recording?.browser?.running,
238
- },
239
- server: { running: !!recording?.server?.running },
240
- },
241
- rtmp: { running: !!rtmp?.running },
242
- };
243
- }
244
- }
@@ -1,32 +0,0 @@
1
- import * as sdkTypes from '../sdkTypes';
2
- import { HMSNotificationTypes } from '../../schema';
3
-
4
- interface notifcationMap {
5
- [key: number]: string;
6
- }
7
-
8
- export const PEER_NOTIFICATION_TYPES: notifcationMap = {
9
- [sdkTypes.HMSPeerUpdate.PEER_JOINED]: HMSNotificationTypes.PEER_JOINED,
10
- [sdkTypes.HMSPeerUpdate.PEER_LEFT]: HMSNotificationTypes.PEER_LEFT,
11
- [sdkTypes.HMSPeerUpdate.ROLE_UPDATED]: HMSNotificationTypes.ROLE_UPDATED,
12
- [sdkTypes.HMSPeerUpdate.AUDIO_TOGGLED]: 'PEER_AUDIO_UPDATED',
13
- [sdkTypes.HMSPeerUpdate.VIDEO_TOGGLED]: 'PEER_VIDEO_UPDATED',
14
- [sdkTypes.HMSPeerUpdate.NAME_UPDATED]: HMSNotificationTypes.NAME_UPDATED,
15
- [sdkTypes.HMSPeerUpdate.METADATA_UPDATED]: HMSNotificationTypes.METADATA_UPDATED,
16
- };
17
-
18
- export const TRACK_NOTIFICATION_TYPES: notifcationMap = {
19
- [sdkTypes.HMSTrackUpdate.TRACK_ADDED]: HMSNotificationTypes.TRACK_ADDED,
20
- [sdkTypes.HMSTrackUpdate.TRACK_REMOVED]: HMSNotificationTypes.TRACK_REMOVED,
21
- [sdkTypes.HMSTrackUpdate.TRACK_MUTED]: HMSNotificationTypes.TRACK_MUTED,
22
- [sdkTypes.HMSTrackUpdate.TRACK_UNMUTED]: HMSNotificationTypes.TRACK_UNMUTED,
23
- [sdkTypes.HMSTrackUpdate.TRACK_DEGRADED]: HMSNotificationTypes.TRACK_DEGRADED,
24
- [sdkTypes.HMSTrackUpdate.TRACK_RESTORED]: HMSNotificationTypes.TRACK_RESTORED,
25
- };
26
-
27
- export const ACTION_TYPES: notifcationMap = {
28
- [sdkTypes.HMSPeerUpdate.PEER_JOINED]: 'peerJoined',
29
- [sdkTypes.HMSPeerUpdate.PEER_LEFT]: 'peerLeft',
30
- [sdkTypes.HMSPeerUpdate.NAME_UPDATED]: 'peerNameUpdated',
31
- [sdkTypes.HMSPeerUpdate.METADATA_UPDATED]: 'peerMetadataUpdated',
32
- };
@@ -1,8 +0,0 @@
1
- import { PartialState, State } from 'zustand/vanilla';
2
-
3
- export type NamedSetState<T extends State> = {
4
- <K1 extends keyof T, K2 extends keyof T = K1, K3 extends keyof T = K2, K4 extends keyof T = K3>(
5
- partial: PartialState<T, K1, K2, K3, K4>,
6
- name?: string,
7
- ): void;
8
- };
@@ -1,55 +0,0 @@
1
- import {
2
- HMSException,
3
- HMSSimulcastLayer,
4
- HMSPeerUpdate,
5
- HMSRoomUpdate,
6
- HMSTrackUpdate,
7
- HMSAudioTrackSettings,
8
- HMSVideoTrackSettings,
9
- HMSPeer,
10
- HMSRoom,
11
- HMSMessage,
12
- HMSConfig,
13
- HMSSpeaker,
14
- HMSRole,
15
- HMSLocalPeer,
16
- HMSRemotePeer,
17
- SimulcastLayerDefinition,
18
- DeviceMap,
19
- HMSLogLevel,
20
- HMSDeviceChangeEvent,
21
- HMSPlaylistItem,
22
- HMSPlaylistManager,
23
- HMSPlaylistProgressEvent,
24
- RTMPRecordingConfig,
25
- HMSRecording,
26
- HMSRTMP,
27
- } from '@100mslive/hms-video';
28
-
29
- export {
30
- HMSPeer,
31
- HMSRoom,
32
- HMSMessage,
33
- HMSSpeaker,
34
- HMSConfig,
35
- HMSAudioTrackSettings,
36
- HMSVideoTrackSettings,
37
- HMSException,
38
- HMSSimulcastLayer,
39
- HMSRoomUpdate,
40
- HMSPeerUpdate,
41
- HMSTrackUpdate,
42
- HMSRole,
43
- HMSLocalPeer,
44
- HMSRemotePeer,
45
- HMSLogLevel,
46
- SimulcastLayerDefinition,
47
- DeviceMap,
48
- HMSDeviceChangeEvent,
49
- HMSPlaylistItem,
50
- HMSPlaylistManager,
51
- HMSPlaylistProgressEvent,
52
- RTMPRecordingConfig,
53
- HMSRecording,
54
- HMSRTMP,
55
- };
@@ -1,63 +0,0 @@
1
- import { HMSStore } from '../../schema';
2
- import { IHMSStore } from '../../IHMSStore';
3
- import { HMSLogger } from '../../../common/ui-logger';
4
-
5
- type ActionName = string;
6
- type SetTimeOutId = number;
7
- type SetState = (store: HMSStore) => void;
8
-
9
- /**
10
- * pass in an action and an update function, the update functions will be batched and run such that
11
- * store updates are limited to only one action in a time interval
12
- *
13
- */
14
- export class ActionBatcher {
15
- private queuedUpdates: Record<ActionName, SetState[]> = {};
16
- private timers: Record<ActionName, SetTimeOutId> = {};
17
- private DEFAULT_INTERVAL_MS = 50;
18
- private store: IHMSStore;
19
- constructor(store: IHMSStore) {
20
- this.store = store;
21
- }
22
-
23
- setState(fn: SetState, action: ActionName) {
24
- this.queuedUpdates[action] = this.queuedUpdates[action] || [];
25
- this.queuedUpdates[action].push(fn);
26
- if (this.timers[action]) {
27
- return;
28
- }
29
- // set a future timeout if a timer is not there already
30
- if (window) {
31
- this.timers[action] = window.setTimeout(
32
- () => this.setStateBatched(action),
33
- this.DEFAULT_INTERVAL_MS,
34
- );
35
- } else {
36
- // nodejs, ignore batching for now
37
- this.setStateBatched(action);
38
- }
39
- }
40
-
41
- private setStateBatched(action: ActionName) {
42
- if (this.queuedUpdates[action]?.length > 0) {
43
- const batchedFn = (draftStore: HMSStore) => {
44
- this.queuedUpdates[action].forEach(fn => {
45
- try {
46
- fn(draftStore);
47
- } catch (err) {
48
- HMSLogger.w('failed to update store', err);
49
- }
50
- });
51
- };
52
- console.time(`timed-${action}`);
53
- this.store.namedSetState(batchedFn, action);
54
- console.timeEnd(`timed-${action}`);
55
- }
56
- // cleanup
57
- delete this.queuedUpdates[action];
58
- if (window && this.timers[action]) {
59
- window.clearTimeout(this.timers[action]);
60
- delete this.timers[action];
61
- }
62
- }
63
- }
@@ -1,5 +0,0 @@
1
- import { HMSTrack, HMSRemoteAudioTrack, HMSRemoteVideoTrack } from '@100mslive/hms-video';
2
-
3
- export function isRemoteTrack(track: HMSTrack) {
4
- return track instanceof HMSRemoteAudioTrack || track instanceof HMSRemoteVideoTrack;
5
- }
@@ -1,98 +0,0 @@
1
- import { HMSPeer, HMSPeerID, HMSTrack, HMSTrackID } from '../../schema';
2
-
3
- /**
4
- * updates draftPeers with newPeers ensuring minimal reference changes
5
- * @remarks
6
- * This is mutable and impure function, it modifies the passed in data to ensure
7
- * minimal reference changes
8
- * @param draftPeers the current peers object in store, an immer draft object
9
- * @param newPeers the latest update which needs to be stored
10
- * @param newHmsTracks this will be update if required
11
- * @param newHmsSDkTracks this is future value of local hms tacks map
12
- */
13
- export const mergeNewPeersInDraft = (
14
- draftPeers: Record<HMSPeerID, HMSPeer>,
15
- newPeers: Record<HMSPeerID, Partial<HMSPeer>>,
16
- ) => {
17
- const peerIDs = union(Object.keys(draftPeers), Object.keys(newPeers));
18
- for (let peerID of peerIDs) {
19
- const oldPeer = draftPeers[peerID];
20
- const newPeer = newPeers[peerID];
21
- if (isEntityUpdated(oldPeer, newPeer)) {
22
- if (areArraysEqual(oldPeer.auxiliaryTracks, newPeer.auxiliaryTracks)) {
23
- newPeer.auxiliaryTracks = oldPeer.auxiliaryTracks;
24
- }
25
- Object.assign(oldPeer, newPeer);
26
- } else if (isEntityRemoved(oldPeer, newPeer)) {
27
- delete draftPeers[peerID];
28
- } else if (isEntityAdded(oldPeer, newPeer)) {
29
- draftPeers[peerID] = newPeer as HMSPeer;
30
- }
31
- }
32
- };
33
-
34
- export const mergeNewTracksInDraft = (
35
- draftTracks: Record<HMSTrackID, HMSTrack>,
36
- newTracks: Record<HMSTrackID, Partial<HMSTrack>>,
37
- ) => {
38
- const trackIDs = union(Object.keys(draftTracks), Object.keys(newTracks));
39
- for (let trackID of trackIDs) {
40
- const oldTrack = draftTracks[trackID];
41
- const newTrack = newTracks[trackID];
42
- if (isEntityUpdated(oldTrack, newTrack)) {
43
- mergeTrackArrayFields(oldTrack, newTrack);
44
- Object.assign(oldTrack, newTrack);
45
- } else if (isEntityRemoved(oldTrack, newTrack)) {
46
- delete draftTracks[trackID];
47
- } else if (isEntityAdded(oldTrack, newTrack)) {
48
- draftTracks[trackID] = newTrack as HMSTrack;
49
- }
50
- }
51
- };
52
-
53
- /**
54
- * array's are usually created with new reference, avoid that update if both arrays are same
55
- */
56
- const mergeTrackArrayFields = (oldTrack: HMSTrack, newTrack: Partial<HMSTrack>) => {
57
- if (oldTrack.plugins && areArraysEqual(oldTrack.plugins, newTrack.plugins)) {
58
- newTrack.plugins = oldTrack.plugins;
59
- }
60
- if (
61
- oldTrack.layerDefinitions &&
62
- areArraysEqual(oldTrack.layerDefinitions, newTrack.layerDefinitions)
63
- ) {
64
- newTrack.layerDefinitions = oldTrack.layerDefinitions;
65
- }
66
- };
67
-
68
- const isEntityUpdated = <T>(oldItem: T, newItem: T) => oldItem && newItem;
69
- const isEntityRemoved = <T>(oldItem: T, newItem: T) => oldItem && !newItem;
70
- const isEntityAdded = <T>(oldItem: T, newItem: T) => !oldItem && newItem;
71
-
72
- // eslint-disable-next-line complexity
73
- export const areArraysEqual = <T>(arr1: T[], arr2?: T[]): boolean => {
74
- if (arr1 === arr2 || (arr1.length === 0 && arr2?.length === 0)) {
75
- // reference check
76
- return true;
77
- }
78
- if (!arr1 || !arr2 || !(arr1.length === arr2.length)) {
79
- return false;
80
- }
81
- for (let i = 0; i < arr1.length; i++) {
82
- if (arr1[i] !== arr2[i]) {
83
- return false;
84
- }
85
- }
86
- return true;
87
- };
88
-
89
- const union = <T>(arr1: T[], arr2: T[]): T[] => {
90
- const set: Set<T> = new Set();
91
- for (let elem of arr1) {
92
- set.add(elem);
93
- }
94
- for (let elem of arr2) {
95
- set.add(elem);
96
- }
97
- return Array.from(set);
98
- };
package/src/core/index.ts DELETED
@@ -1,18 +0,0 @@
1
- export { IHMSStore, IHMSStoreReadOnly as HMSStoreWrapper } from './IHMSStore';
2
- export { IHMSActions as HMSActions } from './IHMSActions';
3
- export { IHMSNotifications as HMSNotifications } from './IHMSNotifications';
4
- export { HMSReactiveStore } from './hmsSDKStore/HMSReactiveStore';
5
- export * from './schema';
6
- export * from './selectors';
7
- export {
8
- HMSConfig,
9
- HMSAudioTrackSettings,
10
- HMSVideoTrackSettings,
11
- HMSSimulcastLayer,
12
- SimulcastLayerDefinition,
13
- DeviceMap,
14
- HMSLogLevel,
15
- RTMPRecordingConfig,
16
- HMSRecording,
17
- HMSRTMP,
18
- } from './hmsSDKStore/sdkTypes';
@@ -1,14 +0,0 @@
1
- import { DeviceMap } from '../hmsSDKStore/sdkTypes';
2
- import { HMSException } from './error';
3
-
4
- /**
5
- * Test fails when adding InputDeviceInfo[error TS2304: Cannot find name 'InputDeviceInfo'.]
6
- * InputDeviceInfo extends MediaDeviceInfo. See https://w3c.github.io/mediacapture-main/#input-specific-device-info
7
- * So, `selection?: MediaDeviceInfo` instead of `selection?: InputDeviceInfo | MediaDeviceInfo` is valid
8
- */
9
- export interface HMSDeviceChangeEvent {
10
- error?: HMSException;
11
- devices: DeviceMap;
12
- selection?: MediaDeviceInfo;
13
- type: 'audioOutput' | 'audioInput' | 'video';
14
- }
@@ -1,13 +0,0 @@
1
- /**
2
- * any mid call error notification will be in this format
3
- */
4
- export interface HMSException {
5
- code: number;
6
- action: string;
7
- name: string;
8
- message: string;
9
- description: string;
10
- isTerminal: boolean;
11
- timestamp: Date;
12
- nativeError?: Error;
13
- }
@@ -1,11 +0,0 @@
1
- export * from './schema';
2
- export * from './room';
3
- export * from './peer';
4
- export * from './message';
5
- export * from './settings';
6
- export * from './notification';
7
- export * from './role';
8
- export * from './error';
9
- export * from './requests';
10
- export * from './device-change';
11
- export * from './playlist';
@@ -1,35 +0,0 @@
1
- import { HMSPeerID } from './peer';
2
- import { HMSRoleName } from './role';
3
-
4
- export type HMSMessageID = string;
5
-
6
- /**
7
- * @internal
8
- */
9
- export enum HMSMessageType {
10
- CHAT = 'chat',
11
- }
12
-
13
- export interface HMSMessage {
14
- id: HMSMessageID;
15
- sender: HMSPeerID;
16
- senderName: string;
17
- senderUserId?: string;
18
- senderRole?: string;
19
- recipientPeer?: HMSPeerID;
20
- recipientRoles?: HMSRoleName[];
21
- time: Date;
22
- read: boolean;
23
- type: string;
24
- message: any;
25
- }
26
-
27
- /**
28
- * @internal
29
- */
30
- export interface HMSMessageInput {
31
- recipientPeer?: HMSPeerID;
32
- recipientRoles?: HMSRoleName[];
33
- type?: string;
34
- message: any;
35
- }
@@ -1,41 +0,0 @@
1
- export interface HMSNotification {
2
- id: number;
3
- type: string;
4
- message: string;
5
- /**
6
- * HMSPeer | HMSTrack | HMSMessage | HMSException
7
- */
8
- data?: any;
9
- severity?: HMSNotificationSeverity;
10
- }
11
- export enum HMSNotificationSeverity {
12
- INFO = 'info',
13
- ERROR = 'error',
14
- CRITICAL = 'critical',
15
- }
16
-
17
- export enum HMSNotificationTypes {
18
- PEER_JOINED = 'PEER_JOINED',
19
- PEER_LEFT = 'PEER_LEFT',
20
- PEER_LIST = 'PEER_LIST',
21
- NEW_MESSAGE = 'NEW_MESSAGE',
22
- ERROR = 'ERROR',
23
- RECONNECTING = 'RECONNECTING',
24
- RECONNECTED = 'RECONNECTED',
25
- TRACK_ADDED = 'TRACK_ADDED',
26
- TRACK_REMOVED = 'TRACK_REMOVED',
27
- TRACK_MUTED = 'TRACK_MUTED',
28
- TRACK_UNMUTED = 'TRACK_UNMUTED',
29
- TRACK_DEGRADED = 'TRACK_DEGRADED',
30
- TRACK_RESTORED = 'TRACK_RESTORED',
31
- ROLE_CHANGE_REQUEST = 'ROLE_CHANGE_REQUEST',
32
- ROLE_UPDATED = 'ROLE_UPDATED',
33
- CHANGE_TRACK_STATE_REQUEST = 'CHANGE_TRACK_STATE_REQUEST',
34
- CHANGE_MULTI_TRACK_STATE_REQUEST = 'CHANGE_MULTI_TRACK_STATE_REQUEST',
35
- ROOM_ENDED = 'ROOM_ENDED',
36
- REMOVED_FROM_ROOM = 'REMOVED_FROM_ROOM',
37
- DEVICE_CHANGE_UPDATE = 'DEVICE_CHANGE_UPDATE',
38
- PLAYLIST_TRACK_ENDED = 'PLAYLIST_TRACK_ENDED',
39
- NAME_UPDATED = 'NAME_UPDATED',
40
- METADATA_UPDATED = 'METADATA_UPDATED',
41
- }