Skip to content

Commit

Permalink
Add metrics support (#1278)
Browse files Browse the repository at this point in the history
* add metrics support

* update protocol

* fix import

* Create fifty-dogs-camp.md
  • Loading branch information
lukasIO authored Oct 9, 2024
1 parent 4936bad commit 6d77449
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/fifty-dogs-camp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"livekit-client": patch
---

Add metrics support
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"size-limit": "size-limit"
},
"dependencies": {
"@livekit/protocol": "1.23.0",
"@livekit/protocol": "1.24.0",
"events": "^3.3.0",
"loglevel": "^1.8.0",
"sdp-transform": "^2.14.1",
Expand Down
18 changes: 9 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/room/Room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
JoinResponse,
LeaveRequest,
LeaveRequest_Action,
MetricsBatch,
ParticipantInfo,
ParticipantInfo_State,
ParticipantPermission,
Expand Down Expand Up @@ -1546,6 +1547,8 @@ class Room extends (EventEmitter as new () => TypedEmitter<RoomEventCallbacks>)
this.handleSipDtmf(participant, packet.value.value);
} else if (packet.value.case === 'chatMessage') {
this.handleChatMessage(participant, packet.value.value);
} else if (packet.value.case === 'metrics') {
this.handleMetrics(packet.value.value, participant);
}
};

Expand Down Expand Up @@ -1595,6 +1598,10 @@ class Room extends (EventEmitter as new () => TypedEmitter<RoomEventCallbacks>)
this.emit(RoomEvent.ChatMessage, msg, participant);
};

private handleMetrics = (metrics: MetricsBatch, participant?: Participant) => {
this.emit(RoomEvent.MetricsReceived, metrics, participant);
};

private handleAudioPlaybackStarted = () => {
if (this.canPlaybackAudio) {
return;
Expand Down Expand Up @@ -2295,4 +2302,5 @@ export type RoomEventCallbacks = {
activeDeviceChanged: (kind: MediaDeviceKind, deviceId: string) => void;
chatMessage: (message: ChatMessage, participant?: RemoteParticipant | LocalParticipant) => void;
localTrackSubscribed: (publication: LocalTrackPublication, participant: LocalParticipant) => void;
metricsReceived: (metrics: MetricsBatch, participant?: Participant) => void;
};
5 changes: 5 additions & 0 deletions src/room/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,11 @@ export enum RoomEvent {
* fired when the first remote participant has subscribed to the localParticipant's track
*/
LocalTrackSubscribed = 'localTrackSubscribed',

/**
* fired when the client receives connection metrics from other participants
*/
MetricsReceived = 'metricsReceived',
}

export enum ParticipantEvent {
Expand Down

0 comments on commit 6d77449

Please sign in to comment.