From cd214f757121294d20b4e638127051a89da0b1f8 Mon Sep 17 00:00:00 2001 From: lukasIO Date: Wed, 14 Aug 2024 09:46:49 +0200 Subject: [PATCH] Add LocalTrackSubscribed engine event (#1222) * Add LocalTrackSubscribed engine event * Create sixty-foxes-refuse.md --- .changeset/sixty-foxes-refuse.md | 5 +++++ src/api/SignalClient.ts | 6 ++++++ src/room/RTCEngine.ts | 5 +++++ src/room/events.ts | 1 + 4 files changed, 17 insertions(+) create mode 100644 .changeset/sixty-foxes-refuse.md diff --git a/.changeset/sixty-foxes-refuse.md b/.changeset/sixty-foxes-refuse.md new file mode 100644 index 0000000000..ef08d2b2b5 --- /dev/null +++ b/.changeset/sixty-foxes-refuse.md @@ -0,0 +1,5 @@ +--- +"livekit-client": patch +--- + +Add internal LocalTrackSubscribed engine event diff --git a/src/api/SignalClient.ts b/src/api/SignalClient.ts index 286e63c5ca..cc98d5012e 100644 --- a/src/api/SignalClient.ts +++ b/src/api/SignalClient.ts @@ -144,6 +144,8 @@ export class SignalClient { onRequestResponse?: (response: RequestResponse) => void; + onLocalTrackSubscribed?: (trackSid: string) => void; + connectOptions?: ConnectOpts; ws?: WebSocket; @@ -743,6 +745,10 @@ export class SignalClient { if (this.onRequestResponse) { this.onRequestResponse(msg.value); } + } else if (msg.case === 'trackSubscribed') { + if (this.onLocalTrackSubscribed) { + this.onLocalTrackSubscribed(msg.value.trackSid); + } } else { this.log.debug('unsupported message', { ...this.logContext, msgCase: msg.case }); } diff --git a/src/room/RTCEngine.ts b/src/room/RTCEngine.ts index 12e5a5e811..de026d51c2 100644 --- a/src/room/RTCEngine.ts +++ b/src/room/RTCEngine.ts @@ -494,6 +494,10 @@ export default class RTCEngine extends (EventEmitter as new () => TypedEventEmit this.emit(EngineEvent.LocalTrackUnpublished, response); }; + this.client.onLocalTrackSubscribed = (trackSid: string) => { + this.emit(EngineEvent.LocalTrackSubscribed, trackSid); + }; + this.client.onTokenRefresh = (token: string) => { this.token = token; }; @@ -1413,6 +1417,7 @@ export type EngineEventCallbacks = { subscriptionPermissionUpdate: (update: SubscriptionPermissionUpdate) => void; subscribedQualityUpdate: (update: SubscribedQualityUpdate) => void; localTrackUnpublished: (unpublishedResponse: TrackUnpublishedResponse) => void; + localTrackSubscribed: (trackSid: string) => void; remoteMute: (trackSid: string, muted: boolean) => void; offline: () => void; signalRequestResponse: (response: RequestResponse) => void; diff --git a/src/room/events.ts b/src/room/events.ts index 57f922c691..32e043e089 100644 --- a/src/room/events.ts +++ b/src/room/events.ts @@ -538,6 +538,7 @@ export enum EngineEvent { RemoteMute = 'remoteMute', SubscribedQualityUpdate = 'subscribedQualityUpdate', LocalTrackUnpublished = 'localTrackUnpublished', + LocalTrackSubscribed = 'localTrackSubscribed', Offline = 'offline', SignalRequestResponse = 'signalRequestResponse', }