Skip to content
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
41 changes: 41 additions & 0 deletions packages/client/src/events/__tests__/participant.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,47 @@ describe('Participant events', () => {

expect(state.participants).toEqual([]);
});

it('sets a server-side pin when isPinned is true', () => {
const state = new CallState();
state.setSortParticipantsBy(noopComparator());

const onParticipantJoined = watchParticipantJoined(state);
const now = Date.now();

onParticipantJoined({
// @ts-expect-error incomplete data
participant: {
userId: 'user-id',
sessionId: 'session-id',
},
isPinned: true,
});

const participant = state.findParticipantBySessionId('session-id');
expect(participant?.pin).toBeDefined();
expect(participant?.pin?.isLocalPin).toBe(false);
expect(participant?.pin?.pinnedAt).toBeGreaterThanOrEqual(now);
});

it('does not set a pin when isPinned is false', () => {
const state = new CallState();
state.setSortParticipantsBy(noopComparator());

const onParticipantJoined = watchParticipantJoined(state);

onParticipantJoined({
// @ts-expect-error incomplete data
participant: {
userId: 'user-id',
sessionId: 'session-id',
},
isPinned: false,
});

const participant = state.findParticipantBySessionId('session-id');
expect(participant?.pin).toBeUndefined();
});
});

describe('orphaned tracks reconciliation', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/client/src/events/participant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const watchParticipantJoined = (state: CallState) => {
StreamVideoParticipantPatch | undefined,
Partial<StreamVideoParticipant>
>(participant, orphanedTracks, {
...(e.isPinned && { pin: { isLocalPin: false, pinnedAt: Date.now() } }),
viewportVisibilityState: {
videoTrack: VisibilityState.UNKNOWN,
screenShareTrack: VisibilityState.UNKNOWN,
Expand Down
5 changes: 5 additions & 0 deletions packages/client/src/gen/video/sfu/event/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,10 @@ export interface ParticipantJoined {
* @generated from protobuf field: stream.video.sfu.models.Participant participant = 2;
*/
participant?: Participant;
/**
* @generated from protobuf field: bool is_pinned = 3;
*/
isPinned: boolean;
}
/**
* ParticipantJoined is fired when a user leaves a call
Expand Down Expand Up @@ -1557,6 +1561,7 @@ class ParticipantJoined$Type extends MessageType<ParticipantJoined> {
super('stream.video.sfu.event.ParticipantJoined', [
{ no: 1, name: 'call_cid', kind: 'scalar', T: 9 /*ScalarType.STRING*/ },
{ no: 2, name: 'participant', kind: 'message', T: () => Participant },
{ no: 3, name: 'is_pinned', kind: 'scalar', T: 8 /*ScalarType.BOOL*/ },
]);
}
}
Expand Down
Loading