diff --git a/.changeset/fifty-dogs-camp.md b/.changeset/fifty-dogs-camp.md new file mode 100644 index 0000000000..3142d44b49 --- /dev/null +++ b/.changeset/fifty-dogs-camp.md @@ -0,0 +1,5 @@ +--- +"livekit-client": patch +--- + +Add metrics support diff --git a/package.json b/package.json index 0b4a6c553d..59624f6b60 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 28951950ae..3fc7c53be0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9,8 +9,8 @@ importers: .: dependencies: '@livekit/protocol': - specifier: 1.23.0 - version: 1.23.0 + specifier: 1.24.0 + version: 1.24.0 events: specifier: ^3.3.0 version: 3.3.0 @@ -1026,8 +1026,8 @@ packages: '@livekit/changesets-changelog-github@0.0.4': resolution: {integrity: sha512-MXaiLYwgkYciZb8G2wkVtZ1pJJzZmVx5cM30Q+ClslrIYyAqQhRbPmZDM79/5CGxb1MTemR/tfOM25tgJgAK0g==} - '@livekit/protocol@1.23.0': - resolution: {integrity: sha512-Hh83moW437mWhiyRgoDMedJ/s/rCTfe3ACSaIJ3n2NlVaq/+BTuB/yH7a6alM1NEkGBSmgrEHxabDfozVUlgYg==} + '@livekit/protocol@1.24.0': + resolution: {integrity: sha512-9dCsqnkMn7lvbI4NGh18zhLDsrXyUcpS++TEFgEk5Xv1WM3R2kT3EzqgL1P/mr3jaabM6rJ8wZA/KJLuQNpF5w==} '@manypkg/find-root@1.1.0': resolution: {integrity: sha512-mki5uBvhHzO8kYYix/WRy2WX8S3B5wdVSc9D6KcU5lQNglP2yt58/VfLuAK49glRXChosY8ap2oJ1qgma3GUVA==} @@ -3266,8 +3266,8 @@ packages: engines: {node: '>=14.17'} hasBin: true - typescript@5.7.0-dev.20241006: - resolution: {integrity: sha512-XbEUvmjO3pXSwKpsgTKNHLRROzF2K1tSdqiyRPKwJfv84gPU0H6AjRwvaAaYC9D/6+Hpen0bQLLC0uaGePRHTQ==} + typescript@5.7.0-dev.20241008: + resolution: {integrity: sha512-FZzeU/lVGUgdl8+Rl2MChV2+eD0ZciK1LuVeoL8+P8ePsJjduRhGrWGRBHvy5KQOhZpxm0QdjrcnGkGDQEphvQ==} engines: {node: '>=14.17'} hasBin: true @@ -4646,7 +4646,7 @@ snapshots: transitivePeerDependencies: - encoding - '@livekit/protocol@1.23.0': + '@livekit/protocol@1.24.0': dependencies: '@bufbuild/protobuf': 1.10.0 @@ -5493,7 +5493,7 @@ snapshots: dependencies: semver: 7.6.0 shelljs: 0.8.5 - typescript: 5.7.0-dev.20241006 + typescript: 5.7.0-dev.20241008 electron-to-chromium@1.5.4: {} @@ -7094,7 +7094,7 @@ snapshots: typescript@5.6.2: {} - typescript@5.7.0-dev.20241006: {} + typescript@5.7.0-dev.20241008: {} uc.micro@2.1.0: {} diff --git a/src/room/Room.ts b/src/room/Room.ts index 85515cafc6..0121752ebe 100644 --- a/src/room/Room.ts +++ b/src/room/Room.ts @@ -7,6 +7,7 @@ import { JoinResponse, LeaveRequest, LeaveRequest_Action, + MetricsBatch, ParticipantInfo, ParticipantInfo_State, ParticipantPermission, @@ -1546,6 +1547,8 @@ class Room extends (EventEmitter as new () => TypedEmitter) 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); } }; @@ -1595,6 +1598,10 @@ class Room extends (EventEmitter as new () => TypedEmitter) this.emit(RoomEvent.ChatMessage, msg, participant); }; + private handleMetrics = (metrics: MetricsBatch, participant?: Participant) => { + this.emit(RoomEvent.MetricsReceived, metrics, participant); + }; + private handleAudioPlaybackStarted = () => { if (this.canPlaybackAudio) { return; @@ -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; }; diff --git a/src/room/events.ts b/src/room/events.ts index 600b8ecdba..38d9a6e09d 100644 --- a/src/room/events.ts +++ b/src/room/events.ts @@ -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 {