Skip to content

Commit

Permalink
fix: exposed method to get raw track data
Browse files Browse the repository at this point in the history
  • Loading branch information
amar-1995 committed Jan 17, 2024
1 parent 8e59b80 commit 99591df
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class BeamSpeakerLabelsLogger<T extends HMSGenericTypes> {
const peerAudioLevels = [];
for (const peer of peers) {
// @ts-ignore
const sdkTrack = this.actions.sdk.store.getTrackById(peer.audioTrack);
const sdkTrack = this.actions.getTrackById(peer.audioTrack);
const nativeStream: MediaStream = sdkTrack?.stream?.nativeStream;
if (!peer.joinedAt) {
continue;
Expand All @@ -103,7 +103,7 @@ export class BeamSpeakerLabelsLogger<T extends HMSGenericTypes> {
event: 'app-audio-level',
data: peerAudioLevels,
};
// HMSLogger.d('logging audio levels', peerAudioLevels);
HMSLogger.d('logging audio levels', peerAudioLevels);
window.__triggerBeamEvent__(JSON.stringify(payload));
}
}
Expand Down
26 changes: 17 additions & 9 deletions packages/hms-video-store/src/reactive-store/HMSSDKActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export class HMSSDKActions<T extends HMSGenericTypes = { sessionStore: Record<st
}

async setPreferredLayer(trackId: string, layer: sdkTypes.HMSPreferredSimulcastLayer) {
const track = this.sdk.store.getTrackById(trackId);
const track = this.getTrackById(trackId);
if (track) {
if (track instanceof SDKHMSRemoteVideoTrack) {
//@ts-ignore
Expand Down Expand Up @@ -201,6 +201,14 @@ export class HMSSDKActions<T extends HMSGenericTypes = { sessionStore: Record<st
}
}

getRawTrackById(trackId: string) {
return this.sdk.store.getTrackById(trackId)?.nativeTrack;
}

getTrackById(trackId: string) {
return this.sdk.store.getTrackById(trackId);
}

getAuthTokenByRoomCode(
tokenRequest: sdkTypes.TokenRequest,
tokenRequestOptions?: sdkTypes.TokenRequestOptions,
Expand Down Expand Up @@ -458,7 +466,7 @@ export class HMSSDKActions<T extends HMSGenericTypes = { sessionStore: Record<st
}

async detachVideo(trackID: string, videoElement: HTMLVideoElement) {
const sdkTrack = this.sdk.store.getTrackById(trackID);
const sdkTrack = this.getTrackById(trackID);
if (sdkTrack?.type === 'video') {
await this.sdk.detachVideo(sdkTrack as SDKHMSVideoTrack, videoElement);
} else {
Expand Down Expand Up @@ -499,7 +507,7 @@ export class HMSSDKActions<T extends HMSGenericTypes = { sessionStore: Record<st
result.errMsg = 'call this function only after local peer has video track';
return result;
}
const sdkTrack = this.sdk.store.getTrackById(trackID);
const sdkTrack = this.getTrackById(trackID);
if (sdkTrack) {
result = (sdkTrack as SDKHMSLocalVideoTrack).validatePlugin(plugin);
} else {
Expand All @@ -524,7 +532,7 @@ export class HMSSDKActions<T extends HMSGenericTypes = { sessionStore: Record<st
result.errMsg = 'call this function only after local peer has audio track';
return result;
}
const sdkTrack = this.sdk.store.getTrackById(trackID);
const sdkTrack = this.getTrackById(trackID);
if (sdkTrack) {
result = (sdkTrack as SDKHMSLocalAudioTrack).validatePlugin(plugin);
} else {
Expand Down Expand Up @@ -711,7 +719,7 @@ export class HMSSDKActions<T extends HMSGenericTypes = { sessionStore: Record<st

async setRemoteTrackEnabled(trackID: HMSTrackID | HMSTrackID[], enabled: boolean) {
if (typeof trackID === 'string') {
const track = this.sdk.store.getTrackById(trackID);
const track = this.getTrackById(trackID);
if (track && isRemoteTrack(track)) {
await this.sdk.changeTrackState(track as SDKHMSRemoteTrack, enabled);
} else {
Expand Down Expand Up @@ -922,7 +930,7 @@ export class HMSSDKActions<T extends HMSGenericTypes = { sessionStore: Record<st
}

private async attachVideoInternal(trackID: string, videoElement: HTMLVideoElement) {
let sdkTrack = this.sdk.store.getTrackById(trackID);
let sdkTrack = this.getTrackById(trackID);
// preview tracks are not added to the sdk store, so access from local peer.
if (!sdkTrack) {
sdkTrack = this.getLocalTrack(trackID);
Expand Down Expand Up @@ -1361,7 +1369,7 @@ export class HMSSDKActions<T extends HMSGenericTypes = { sessionStore: Record<st
}

private async setTrackVolume(value: number, trackId: HMSTrackID) {
const track = this.sdk.store.getTrackById(trackId);
const track = this.getTrackById(trackId);
if (track) {
if (track instanceof SDKHMSAudioTrack) {
await track.setVolume(value);
Expand Down Expand Up @@ -1469,7 +1477,7 @@ export class HMSSDKActions<T extends HMSGenericTypes = { sessionStore: Record<st
if (!storeTrackID) {
return false;
}
return this.sdk.store.getTrackById(storeTrackID)?.trackId === sdkTrackID;
return this.getTrackById(storeTrackID)?.trackId === sdkTrackID;
}

/**
Expand Down Expand Up @@ -1501,7 +1509,7 @@ export class HMSSDKActions<T extends HMSGenericTypes = { sessionStore: Record<st

private getStoreLocalTrackIDfromSDKTrack(sdkTrack: SDKHMSLocalTrack) {
const trackIDs = this.store.getState(selectLocalTrackIDs);
return trackIDs.find(trackID => this.sdk.store.getTrackById(trackID)?.trackId === sdkTrack.trackId);
return trackIDs.find(trackID => this.getTrackById(trackID)?.trackId === sdkTrack.trackId);
}

private setProgress = ({ type, progress }: sdkTypes.HMSPlaylistProgressEvent) => {
Expand Down

0 comments on commit 99591df

Please sign in to comment.