Skip to content

Commit

Permalink
Add LocalTrackSubscribed engine event (#1222)
Browse files Browse the repository at this point in the history
* Add LocalTrackSubscribed engine event

* Create sixty-foxes-refuse.md
  • Loading branch information
lukasIO authored Aug 14, 2024
1 parent d53f530 commit cd214f7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/sixty-foxes-refuse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"livekit-client": patch
---

Add internal LocalTrackSubscribed engine event
6 changes: 6 additions & 0 deletions src/api/SignalClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ export class SignalClient {

onRequestResponse?: (response: RequestResponse) => void;

onLocalTrackSubscribed?: (trackSid: string) => void;

connectOptions?: ConnectOpts;

ws?: WebSocket;
Expand Down Expand Up @@ -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 });
}
Expand Down
5 changes: 5 additions & 0 deletions src/room/RTCEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/room/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,7 @@ export enum EngineEvent {
RemoteMute = 'remoteMute',
SubscribedQualityUpdate = 'subscribedQualityUpdate',
LocalTrackUnpublished = 'localTrackUnpublished',
LocalTrackSubscribed = 'localTrackSubscribed',
Offline = 'offline',
SignalRequestResponse = 'signalRequestResponse',
}
Expand Down

0 comments on commit cd214f7

Please sign in to comment.