@100mslive/hms-video-store 0.2.75-1 → 0.2.78

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.
@@ -1,7 +1,8 @@
1
1
  import { HMSPeer, HMSSpeaker, HMSStore, HMSTrack } from '../core';
2
2
  import { HMSPlaylist, HMSRole } from '../core/schema';
3
3
  export declare let localPeer: HMSPeer;
4
- export declare let remotePeer: HMSPeer;
4
+ export declare let remotePeerOne: HMSPeer;
5
+ export declare let remotePeerTwo: HMSPeer;
5
6
  export declare let peerScreenSharing: HMSPeer;
6
7
  export declare let localVideo: HMSTrack;
7
8
  export declare let localAudio: HMSTrack;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.2.75-1",
2
+ "version": "0.2.78",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -57,10 +57,10 @@
57
57
  "zustand": "3.5.7"
58
58
  },
59
59
  "peerDependencies": {
60
- "@100mslive/hms-video": "^0.1.26"
60
+ "@100mslive/hms-video": "^0.1.32"
61
61
  },
62
62
  "devDependencies": {
63
- "@100mslive/hms-video": "^0.1.26",
63
+ "@100mslive/hms-video": "^0.1.32",
64
64
  "@cypress/code-coverage": "^3.9.11",
65
65
  "@istanbuljs/nyc-config-typescript": "^1.0.1",
66
66
  "@size-limit/file": "^5.0.3",
@@ -17,7 +17,7 @@ import {
17
17
  HMSChangeMultiTrackStateParams,
18
18
  } from './schema';
19
19
  import { HMSRoleChangeRequest } from './selectors';
20
- import { RTMPRecordingConfig } from './hmsSDKStore/sdkTypes';
20
+ import { RTMPRecordingConfig, HMSPeerUpdateConfig } from './hmsSDKStore/sdkTypes';
21
21
 
22
22
  /**
23
23
  * The below interface defines our SDK API Surface for taking room related actions.
@@ -280,6 +280,15 @@ export interface IHMSActions {
280
280
  */
281
281
  stopRTMPAndRecording(): Promise<void>;
282
282
 
283
+ /**
284
+ * If both name and data is undefined: Message is ignored.
285
+ * If data is undefined: Name of the peer is changed.
286
+ * If name is undefined: Metadata of the peer is updated.
287
+ * If both name and data is defined: Both name and metadata is updated.
288
+ * @alpha
289
+ */
290
+ updatePeer(params: HMSPeerUpdateConfig): Promise<void>;
291
+
283
292
  /**
284
293
  * Set the type of logs from the SDK you want to be logged in the browser console.
285
294
  *
@@ -58,11 +58,16 @@ export class HMSNotifications implements IHMSNotifications {
58
58
  }
59
59
 
60
60
  sendLeaveRoom(request: HMSLeaveRoomRequest) {
61
+ const peerName = request.requestedBy?.name;
61
62
  const notification = this.createNotification(
62
- request.roomEnded ? HMSNotificationTypes.ROOM_ENDED : HMSNotificationTypes.REMOVED_FROM_ROOM,
63
+ request.roomEnded || !peerName
64
+ ? HMSNotificationTypes.ROOM_ENDED
65
+ : HMSNotificationTypes.REMOVED_FROM_ROOM,
63
66
  request,
64
67
  HMSNotificationSeverity.INFO,
65
- `${request.roomEnded ? `Room ended` : 'Removed from room'} by ${request.requestedBy.name}`,
68
+ `${request.roomEnded ? `Room ended` : 'Removed from room'} ${
69
+ peerName ? `by ${peerName}` : ''
70
+ }`,
66
71
  );
67
72
  this.emitEvent(notification);
68
73
  }
@@ -69,6 +69,8 @@ import { HMSNotifications } from './HMSNotifications';
69
69
  import { NamedSetState } from './internalTypes';
70
70
  import { isRemoteTrack } from './sdkUtils/sdkUtils';
71
71
  import { HMSPlaylist } from './HMSPlaylist';
72
+ import { ACTION_TYPES } from './common/mapping';
73
+
72
74
  // import { ActionBatcher } from './sdkUtils/ActionBatcher';
73
75
 
74
76
  /**
@@ -448,6 +450,16 @@ export class HMSSDKActions implements IHMSActions {
448
450
  await this.sdk.stopRTMPAndRecording();
449
451
  }
450
452
 
453
+ async updatePeer(params: sdkTypes.HMSPeerUpdateConfig) {
454
+ await this.sdk.updatePeer(params);
455
+ if (params.name) {
456
+ this.syncRoomState('nameUpdated');
457
+ }
458
+ if (params.metadata) {
459
+ this.syncRoomState('metadataUpdated');
460
+ }
461
+ }
462
+
451
463
  async setRemoteTrackEnabled(trackID: HMSTrackID | HMSTrackID[], enabled: boolean) {
452
464
  if (typeof trackID === 'string') {
453
465
  const track = this.hmsSDKTracks[trackID];
@@ -513,19 +525,13 @@ export class HMSSDKActions implements IHMSActions {
513
525
  }
514
526
 
515
527
  private onRemovedFromRoom(request: SDKHMSLeaveRoomRequest) {
516
- const requestedBy = this.store.getState(selectPeerByID(request.requestedBy.peerId));
517
- if (!requestedBy) {
518
- this.logPossibleInconsistency(
519
- `Not found peer who requested leave room, ${request.requestedBy}`,
520
- );
521
- return;
522
- }
528
+ const requestedBy = this.store.getState(selectPeerByID(request.requestedBy?.peerId));
523
529
  this.hmsNotifications.sendLeaveRoom({
524
530
  ...request,
525
- requestedBy,
531
+ requestedBy: requestedBy || undefined,
526
532
  });
527
533
  HMSLogger.i('resetting state after peer removed', request);
528
- this.resetState(request.roomEnded ? 'roomEnded' : 'removedFromRoom');
534
+ this.resetState(request.roomEnded || !requestedBy ? 'roomEnded' : 'removedFromRoom');
529
535
  }
530
536
 
531
537
  private onDeviceChange(event: sdkTypes.HMSDeviceChangeEvent) {
@@ -1129,11 +1135,7 @@ export class HMSSDKActions implements IHMSActions {
1129
1135
  ) => {
1130
1136
  let peer = this.store.getState(selectPeerByID(sdkPeer.peerId));
1131
1137
  let actionName = 'peerUpdate';
1132
- if (type === sdkTypes.HMSPeerUpdate.PEER_JOINED) {
1133
- actionName = 'peerJoined';
1134
- } else if (type === sdkTypes.HMSPeerUpdate.PEER_LEFT) {
1135
- actionName = 'peerLeft';
1136
- }
1138
+ actionName = ACTION_TYPES[type];
1137
1139
  this.syncRoomState(actionName);
1138
1140
  // if peer wasn't available before sync(will happen if event is peer join)
1139
1141
  if (!peer) {
@@ -11,6 +11,8 @@ export const PEER_NOTIFICATION_TYPES: notifcationMap = {
11
11
  [sdkTypes.HMSPeerUpdate.ROLE_UPDATED]: HMSNotificationTypes.ROLE_UPDATED,
12
12
  [sdkTypes.HMSPeerUpdate.AUDIO_TOGGLED]: 'PEER_AUDIO_UPDATED',
13
13
  [sdkTypes.HMSPeerUpdate.VIDEO_TOGGLED]: 'PEER_VIDEO_UPDATED',
14
+ [sdkTypes.HMSPeerUpdate.NAME_UPDATED]: HMSNotificationTypes.NAME_UPDATED,
15
+ [sdkTypes.HMSPeerUpdate.METADATA_UPDATED]: HMSNotificationTypes.METADATA_UPDATED,
14
16
  };
15
17
 
16
18
  export const TRACK_NOTIFICATION_TYPES: notifcationMap = {
@@ -19,3 +21,10 @@ export const TRACK_NOTIFICATION_TYPES: notifcationMap = {
19
21
  [sdkTypes.HMSTrackUpdate.TRACK_MUTED]: HMSNotificationTypes.TRACK_MUTED,
20
22
  [sdkTypes.HMSTrackUpdate.TRACK_UNMUTED]: HMSNotificationTypes.TRACK_UNMUTED,
21
23
  };
24
+
25
+ export const ACTION_TYPES: notifcationMap = {
26
+ [sdkTypes.HMSPeerUpdate.PEER_JOINED]: 'peerJoined',
27
+ [sdkTypes.HMSPeerUpdate.PEER_LEFT]: 'peerLeft',
28
+ [sdkTypes.HMSPeerUpdate.NAME_UPDATED]: 'nameUpdated',
29
+ [sdkTypes.HMSPeerUpdate.METADATA_UPDATED]: 'metadataUpdated',
30
+ };
@@ -24,6 +24,7 @@ import {
24
24
  RTMPRecordingConfig,
25
25
  HMSRecording,
26
26
  HMSRTMP,
27
+ HMSPeerUpdateConfig,
27
28
  } from '@100mslive/hms-video';
28
29
 
29
30
  export {
@@ -52,4 +53,5 @@ export {
52
53
  RTMPRecordingConfig,
53
54
  HMSRecording,
54
55
  HMSRTMP,
56
+ HMSPeerUpdateConfig,
55
57
  };
@@ -34,4 +34,6 @@ export enum HMSNotificationTypes {
34
34
  REMOVED_FROM_ROOM = 'REMOVED_FROM_ROOM',
35
35
  DEVICE_CHANGE_UPDATE = 'DEVICE_CHANGE_UPDATE',
36
36
  PLAYLIST_TRACK_ENDED = 'PLAYLIST_TRACK_ENDED',
37
+ NAME_UPDATED = 'NAME_UPDATED',
38
+ METADATA_UPDATED = 'METADATA_UPDATED',
37
39
  }
@@ -30,7 +30,7 @@ export interface HMSChangeMultiTrackStateParams {
30
30
  }
31
31
 
32
32
  export interface HMSLeaveRoomRequest {
33
- requestedBy: HMSPeer;
33
+ requestedBy?: HMSPeer;
34
34
  reason: string;
35
35
  roomEnded: boolean;
36
36
  }
@@ -1,5 +1,11 @@
1
1
  import { createSelector } from 'reselect';
2
- import { selectHMSMessages, selectLocalPeerID, selectPeersMap, selectTracksMap } from './selectors';
2
+ import {
3
+ selectHMSMessages,
4
+ selectLocalPeerID,
5
+ selectPeers,
6
+ selectPeersMap,
7
+ selectTracksMap,
8
+ } from './selectors';
3
9
  import { HMSPeerID, HMSRoleName, HMSStore, HMSTrack, HMSTrackID } from '../schema';
4
10
  import {
5
11
  getPeerTracksByCondition,
@@ -368,3 +374,13 @@ export const selectMessagesByRole = byIDCurry(selectMessagesByRoleInternal);
368
374
 
369
375
  export const selectMessagesUnreadCountByRole = byIDCurry(selectUnreadMessageCountByRole);
370
376
  export const selectMessagesUnreadCountByPeerID = byIDCurry(selectUnreadMessageCountByPeerID);
377
+
378
+ /**
379
+ * Select an array of peers of a particular role
380
+ * @param role HMSRoleName
381
+ * @returns HMSPeer[]
382
+ */
383
+ export const selectPeersByRole = (role: HMSRoleName) =>
384
+ createSelector([selectPeers], peers => {
385
+ return peers.filter(p => p.roleName === role);
386
+ });
@@ -32,7 +32,8 @@ function makeTrack(
32
32
  }
33
33
 
34
34
  export let localPeer: HMSPeer;
35
- export let remotePeer: HMSPeer;
35
+ export let remotePeerOne: HMSPeer;
36
+ export let remotePeerTwo: HMSPeer;
36
37
  export let peerScreenSharing: HMSPeer;
37
38
  export let localVideo: HMSTrack;
38
39
  export let localAudio: HMSTrack;
@@ -58,7 +59,7 @@ export const makeFakeStore = (): HMSStore => {
58
59
  id: '123',
59
60
  isConnected: true,
60
61
  name: 'test room',
61
- peers: ['1', '2'],
62
+ peers: ['1', '2', '3'],
62
63
  localPeer: '1',
63
64
  shareableLink: '',
64
65
  hasWaitingRoom: false,
@@ -94,6 +95,15 @@ export const makeFakeStore = (): HMSStore => {
94
95
  audioTrack: '104',
95
96
  auxiliaryTracks: ['105', '106', '107'],
96
97
  },
98
+ '3': {
99
+ id: '3',
100
+ name: 'test3',
101
+ roleName: ROLES.SPEAKER,
102
+ isLocal: false,
103
+ videoTrack: '105',
104
+ audioTrack: '106',
105
+ auxiliaryTracks: [],
106
+ },
97
107
  },
98
108
  tracks: {
99
109
  '101': makeTrack('101', 'video', 'regular', '1'),
@@ -243,7 +253,8 @@ export const makeFakeStore = (): HMSStore => {
243
253
  };
244
254
 
245
255
  localPeer = fakeStore.peers['1'];
246
- remotePeer = fakeStore.peers['2'];
256
+ remotePeerOne = fakeStore.peers['2'];
257
+ remotePeerTwo = fakeStore.peers['3'];
247
258
  peerScreenSharing = fakeStore.peers['2'];
248
259
  localVideo = fakeStore.tracks['101'];
249
260
  localAudio = fakeStore.tracks['102'];
@@ -8,7 +8,14 @@ import {
8
8
  selectIsAllowedToPublish,
9
9
  selectIsAllowedToSubscribe,
10
10
  } from '../../core';
11
- import { hostRole, localPeer, makeFakeStore, remotePeer, ROLES, speakerRole } from '../fakeStore';
11
+ import {
12
+ hostRole,
13
+ localPeer,
14
+ makeFakeStore,
15
+ remotePeerOne,
16
+ ROLES,
17
+ speakerRole,
18
+ } from '../fakeStore';
12
19
 
13
20
  let fakeStore: HMSStore;
14
21
 
@@ -38,7 +45,7 @@ describe('test role related selectors', () => {
38
45
 
39
46
  test('selectRole change request', () => {
40
47
  const req = selectRoleChangeRequest(fakeStore);
41
- expect(req?.requestedBy).toBe(remotePeer);
48
+ expect(req?.requestedBy).toBe(remotePeerOne);
42
49
  expect(req?.role.name).toBe(ROLES.SPEAKER);
43
50
  expect(req?.role).toBe(speakerRole);
44
51
  expect(req?.token).toBe('123');
@@ -11,6 +11,8 @@ import {
11
11
  screenShare,
12
12
  screenshareAudio,
13
13
  playlist,
14
+ remotePeerTwo,
15
+ remotePeerOne,
14
16
  } from '../fakeStore';
15
17
  import {
16
18
  HMSStore,
@@ -65,6 +67,7 @@ import {
65
67
  selectMessagesUnreadCountByPeerID,
66
68
  selectAudioPlaylist,
67
69
  selectVideoPlaylist,
70
+ selectPeersByRole,
68
71
  } from '../../core';
69
72
 
70
73
  let fakeStore: HMSStore;
@@ -150,7 +153,7 @@ describe('secondary selectors', () => {
150
153
  });
151
154
 
152
155
  test('remote peers', () => {
153
- expect(selectRemotePeers(fakeStore)).toEqual([peerScreenSharing]);
156
+ expect(selectRemotePeers(fakeStore)).toEqual([remotePeerOne, remotePeerTwo]);
154
157
  });
155
158
 
156
159
  test('some track degraded', () => {
@@ -283,6 +286,12 @@ describe('by ID selectors', () => {
283
286
  const messages = selectBroadcastMessagesUnreadCount(fakeStore);
284
287
  expect(messages).toBe(0);
285
288
  });
289
+
290
+ test('selectPeersByRole', () => {
291
+ expect(selectPeersByRole('speaker')(fakeStore)).toEqual([remotePeerTwo]);
292
+ // If role is not present
293
+ expect(selectPeersByRole('incognito')(fakeStore)).toEqual([]);
294
+ });
286
295
  });
287
296
 
288
297
  describe('derived selectors', () => {
@@ -291,6 +300,7 @@ describe('derived selectors', () => {
291
300
  expect(selectPeersWithAudioStatus(fakeStore)).toEqual([
292
301
  { peer: localPeer, isAudioEnabled: true },
293
302
  { peer: peerScreenSharing, isAudioEnabled: false },
303
+ { peer: remotePeerTwo, isAudioEnabled: false },
294
304
  ]);
295
305
  });
296
306
  });