Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add type to peer #2748

Merged
merged 6 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/hms-video-store/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export type {
HMSPollQuestionOption,
HMSQuizLeaderboardResponse,
HMSQuizLeaderboardSummary,
HMSPeerType,
} from './internal';

export { EventBus } from './events/EventBus';
Expand Down
3 changes: 3 additions & 0 deletions packages/hms-video-store/src/interfaces/peer/hms-peer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { HMSAudioTrack, HMSTrack, HMSVideoTrack } from '../../media/tracks';
import { HMSRole } from '../role';

export type HMSPeerType = 'sip' | 'regular';

export interface HMSPeer {
peerId: string;
name: string;
Expand All @@ -16,6 +18,7 @@ export interface HMSPeer {
groups?: string[];
realtime?: boolean;
isHandRaised: boolean;
type: HMSPeerType;

updateRole(newRole: HMSRole): void;
updateName(newName: string): void;
Expand Down
2 changes: 1 addition & 1 deletion packages/hms-video-store/src/interfaces/peer/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type { HMSPeer } from './hms-peer';
export type { HMSPeer, HMSPeerType } from './hms-peer';
export type { HMSLocalPeer } from './hms-local-peer';
export type { HMSRemotePeer } from './hms-remote-peer';
export type { HMSConnectionQuality } from './connection-quality';
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { VideoTrackLayerUpdate } from '../connection/channel-messages';
import { HMSPeerType } from '../interfaces/peer/hms-peer';
import { HMSRole } from '../interfaces/role';
import { HMSLocalTrack } from '../media/tracks';
import { HMSTrack, HMSTrackSource } from '../media/tracks/HMSTrack';
Expand Down Expand Up @@ -39,6 +40,7 @@ export interface Info {
name: string;
data: string;
user_id: string;
type: HMSPeerType;
}

export enum HMSRecordingState {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const FAKE_PEER_ID = 'peer_id_1';

export const fakePeer: PeerNotification = {
peer_id: 'peer_id_0',
info: { data: 'data', name: 'Sarvesh0', user_id: 'customer_user_id' },
info: { data: 'data', name: 'Sarvesh0', user_id: 'customer_user_id', type: 'regular' },
role: 'host',
tracks: {},
groups: [],
Expand All @@ -17,6 +17,7 @@ export const fakePeerList: PeerListNotification = {
name: 'Sarvesh1',
data: 'data',
user_id: 'customer_user_id',
type: 'regular',
},
role: 'host',
peer_id: FAKE_PEER_ID,
Expand Down Expand Up @@ -45,6 +46,7 @@ export const fakePeerList: PeerListNotification = {
name: 'Sarvesh3',
data: 'data',
user_id: 'customer_user_id',
type: 'regular',
},
peer_id: 'peer_id_3',
role: 'viewer',
Expand Down Expand Up @@ -85,6 +87,7 @@ export const fakeReconnectPeerList: PeerListNotification = {
name: 'Sarvesh1',
data: 'data',
user_id: 'customer_user_id',
type: 'regular',
},
role: 'host',
peer_id: FAKE_PEER_ID,
Expand Down Expand Up @@ -113,6 +116,7 @@ export const fakeReconnectPeerList: PeerListNotification = {
name: 'Sarvesh2',
data: 'data',
user_id: 'customer_user_id',
type: 'regular',
},
peer_id: 'peer_id_2',
role: 'viewer',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export class PeerListManager {
name: peer.name,
data: peer.metadata || '',
user_id: peer.customerUserId || '',
type: peer.type,
},
tracks: {},
groups: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ export const createRemotePeer = (notifPeer: PeerNotificationInfo, store: Store)
customerUserId: notifPeer.info.user_id,
metadata: notifPeer.info.data,
groups: notifPeer.groups,
type: notifPeer.info.type,
});
};
1 change: 1 addition & 0 deletions packages/hms-video-store/src/reactive-store/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export class SDKToHMS {
joinedAt: sdkPeer.joinedAt,
groups: sdkPeer.groups,
isHandRaised: sdkPeer.isHandRaised,
type: sdkPeer.type,
};
}

Expand Down
2 changes: 2 additions & 0 deletions packages/hms-video-store/src/schema/peer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
HMSSimulcastLayerDefinition,
ScreenCaptureHandle,
} from '../interfaces';
import { HMSPeerType } from '../interfaces/peer/hms-peer';

export type HMSPeerID = string;
export type HMSTrackID = string;
Expand Down Expand Up @@ -42,6 +43,7 @@ export interface HMSPeer {
joinedAt?: Date;
groups?: HMSGroupName[];
isHandRaised: boolean;
type: HMSPeerType;
}

/**
Expand Down
3 changes: 3 additions & 0 deletions packages/hms-video-store/src/sdk/LocalTrackManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ const publishParams = hostRole.publishParams;
let localPeer = new HMSLocalPeer({
name: 'test',
role: hostRole,
type: 'regular',
});
testStore.addPeer(localPeer);

Expand Down Expand Up @@ -231,6 +232,7 @@ describe('LocalTrackManager', () => {
localPeer = new HMSLocalPeer({
name: 'test',
role: hostRole,
type: 'regular',
});
testStore.addPeer(localPeer);
});
Expand Down Expand Up @@ -408,6 +410,7 @@ describe('LocalTrackManager', () => {
localPeer = new HMSLocalPeer({
name: 'test',
role: hostRole,
type: 'regular',
});
testStore.addPeer(localPeer);
mockGetUserMedia.mockClear();
Expand Down
1 change: 1 addition & 0 deletions packages/hms-video-store/src/sdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1300,6 +1300,7 @@ export class HMSSdk implements HMSInterface {
role: policy,
// default value is the original role if user didn't pass asRole in config
asRole: asRolePolicy || policy,
type: 'regular',
});

this.store.addPeer(localPeer);
Expand Down
18 changes: 17 additions & 1 deletion packages/hms-video-store/src/sdk/models/peer/HMSPeer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { HMSPeer as IHMSPeer } from '../../../interfaces/peer';
import { HMSPeerType } from '../../../interfaces/peer/hms-peer';
import { HMSRole } from '../../../interfaces/role';
import { HMSAudioTrack, HMSTrack, HMSVideoTrack } from '../../../media/tracks';
import { HAND_RAISE_GROUP_NAME } from '../../../utils/constants';
Expand All @@ -16,6 +17,7 @@ export type HMSPeerInit = {
groups?: string[];
realtime?: boolean;
isHandRaised?: boolean;
type: HMSPeerType;
};

export class HMSPeer implements IHMSPeer {
Expand All @@ -32,8 +34,20 @@ export class HMSPeer implements IHMSPeer {
networkQuality?: number;
groups?: string[];
realtime?: boolean;
type: HMSPeerType;

constructor({ peerId, name, isLocal, customerUserId, metadata, role, joinedAt, groups, realtime }: HMSPeerInit) {
constructor({
peerId,
name,
isLocal,
customerUserId,
metadata,
role,
joinedAt,
groups,
realtime,
type,
}: HMSPeerInit) {
this.name = name;
this.peerId = peerId;
this.isLocal = isLocal;
Expand All @@ -42,6 +56,7 @@ export class HMSPeer implements IHMSPeer {
this.joinedAt = joinedAt;
this.groups = groups;
this.realtime = realtime;
this.type = type;

if (role) {
this.role = role;
Expand All @@ -68,6 +83,7 @@ export class HMSPeer implements IHMSPeer {
updateNetworkQuality(quality: number) {
this.networkQuality = quality;
}

/**
* @internal
*/
Expand Down
4 changes: 4 additions & 0 deletions packages/hms-video-store/src/sdk/models/peer/peer.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { HMSLocalPeer } from './HMSLocalPeer';
import { HMSRemotePeer } from './HMSRemotePeer';
import { HMSPeerType } from '../../../internal';
import { PeerNotification } from '../../../notification-manager';
import decodeJWT from '../../../utils/jwt';

Expand Down Expand Up @@ -45,6 +46,7 @@ describe('HMSLocalPeer', () => {
name: 'John Doe',
role: getParamsForRole(role),
customerUserId: userId,
type: 'regular' as HMSPeerType,
raviteja83 marked this conversation as resolved.
Show resolved Hide resolved
};
const peer = new HMSLocalPeer(params);

Expand Down Expand Up @@ -80,6 +82,7 @@ describe('HMSRemotPeer', () => {
name: 'John Doe',
data: 'data',
user_id: 'customer_user_id',
type: 'regular',
},
role: 'viewer',
tracks: {},
Expand All @@ -91,6 +94,7 @@ describe('HMSRemotPeer', () => {
role: getParamsForRole(peerInfo.role),
customerUserId: peerInfo.info.user_id,
metadata: peerInfo.info.data,
type: 'regular',
});

it('should be constructed using params', () => {
Expand Down
3 changes: 3 additions & 0 deletions packages/hms-video-store/src/test/fakeStore/fakeHMSStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export const makeFakeStore = (): HMSStore => {
metadata: '{}',
groups: [],
isHandRaised: false,
type: 'regular',
},
'2': {
id: '2',
Expand All @@ -110,6 +111,7 @@ export const makeFakeStore = (): HMSStore => {
metadata: '{"hello":"world"}',
groups: [],
isHandRaised: false,
type: 'regular',
},
'3': {
id: '3',
Expand All @@ -121,6 +123,7 @@ export const makeFakeStore = (): HMSStore => {
auxiliaryTracks: [],
groups: [],
isHandRaised: false,
type: 'regular',
},
},
tracks: {
Expand Down
1 change: 1 addition & 0 deletions packages/hms-video-store/src/test/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ export const makeFakePeer = (): HMSPeer => {
videoTrack: '',
groups: [],
isHandRaised: false,
type: 'regular',
};
};
1 change: 1 addition & 0 deletions packages/roomkit-react/src/fixtures/peers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const makeFakeParticipant = (name: string, role = 'Student'): HMSPeerWith
isLocal: counter === 1,
groups: [],
isHandRaised: false,
type: 'regular',
},
isAudioEnabled: false,
};
Expand Down
Loading