Skip to content

Commit b96de03

Browse files
authored
feat: Participant Stats (#1922)
1 parent 2399b86 commit b96de03

File tree

4 files changed

+807
-4
lines changed

4 files changed

+807
-4
lines changed

packages/client/src/Call.ts

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import type {
3939
EndCallResponse,
4040
GetCallReportResponse,
4141
GetCallResponse,
42+
GetCallSessionParticipantStatsDetailsResponse,
4243
GetOrCreateCallRequest,
4344
GetOrCreateCallResponse,
4445
GoLiveRequest,
@@ -55,6 +56,8 @@ import type {
5556
PinResponse,
5657
QueryCallMembersRequest,
5758
QueryCallMembersResponse,
59+
QueryCallSessionParticipantStatsResponse,
60+
QueryCallSessionParticipantStatsTimelineResponse,
5861
RejectCallRequest,
5962
RejectCallResponse,
6063
RequestPermissionRequest,
@@ -2238,13 +2241,10 @@ export class Call {
22382241

22392242
/**
22402243
* Allows you to grant or revoke a specific permission to a user in a call. The permissions are specific to the call experience and do not survive the call itself.
2241-
*
22422244
* When revoking a permission, this endpoint will also mute the relevant track from the user. This is similar to muting a user with the difference that the user will not be able to unmute afterwards.
2243-
*
22442245
* Supported permissions that can be granted or revoked: `send-audio`, `send-video` and `screenshare`.
22452246
*
22462247
* `call.permissions_updated` event is sent to all members of the call.
2247-
*
22482248
*/
22492249
updateUserPermissions = async (data: UpdateUserPermissionsRequest) => {
22502250
return this.streamClient.post<
@@ -2561,6 +2561,43 @@ export class Call {
25612561
return this.streamClient.get<GetCallReportResponse>(endpoint, params);
25622562
};
25632563

2564+
/**
2565+
* Loads the call participant stats for the given parameters.
2566+
*/
2567+
getCallParticipantsStats = async (opts: {
2568+
sessionId?: string;
2569+
userId?: string;
2570+
userSessionId?: string;
2571+
kind?: 'timeline' | 'details';
2572+
}): Promise<
2573+
| QueryCallSessionParticipantStatsResponse
2574+
| GetCallSessionParticipantStatsDetailsResponse
2575+
| QueryCallSessionParticipantStatsTimelineResponse
2576+
| undefined
2577+
> => {
2578+
const {
2579+
sessionId = this.state.session?.id,
2580+
userId = this.currentUserId,
2581+
userSessionId = this.unifiedSessionId,
2582+
kind = 'details',
2583+
} = opts;
2584+
if (!sessionId) return;
2585+
const base = `${this.streamClient.baseURL}/call_stats/${this.type}/${this.id}/${sessionId}`;
2586+
if (!userId || !userSessionId) {
2587+
return this.streamClient.get<QueryCallSessionParticipantStatsResponse>(
2588+
`${base}/participants`,
2589+
);
2590+
}
2591+
if (kind === 'details') {
2592+
return this.streamClient.get<GetCallSessionParticipantStatsDetailsResponse>(
2593+
`${base}/participant/${userId}/${userSessionId}/details`,
2594+
);
2595+
}
2596+
return this.streamClient.get<QueryCallSessionParticipantStatsTimelineResponse>(
2597+
`${base}/participants/${userId}/${userSessionId}/timeline`,
2598+
);
2599+
};
2600+
25642601
/**
25652602
* Submit user feedback for the call
25662603
*

0 commit comments

Comments
 (0)