Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FCE-207] Fix error on muted track renegotiation #18

Merged
merged 11 commits into from
Jul 4, 2024

Conversation

kamil-stasiak
Copy link
Contributor

Description

This PR fixes an error that occurs when a muted track is renegotiated.

Motivation and Context

Steps to reproduce:

  • Join the room with Peer 1.
  • Join the room with Peer 2.
  • Peer 2 mutes the microphone.
  • Peer 2 turns off the camera.
  • The error appears for Peer 1.

Types of changes

Breaking change (fix or feature that would cause existing functionality to not work as expected)

  • type AudioOrVideoType from react-client has been replaced by TrackKind from ts-client

@@ -164,7 +164,7 @@ const handleNotAllowedError = async (constraints: MediaStreamConstraints): Promi
return await getMedia({ video: false, audio: false }, { video: PERMISSION_DENIED, audio: PERMISSION_DENIED });
};

const getError = (result: GetMedia, type: AudioOrVideoType): DeviceError | null => {
const getError = (result: GetMedia, type: TrackKind): DeviceError | null => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imo TrackType sounds better than TrackKind

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it because MediaStreamTrack has a kind field

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe update the variable name as well to kind: TrackKind

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed with @czerwiukk. lets rename function parameter name to kind.

midToTrackId: Map<string, string> = new Map(),
localEndpoint: EndpointWithTrackContext<EndpointMetadata, TrackMetadata>,
): Record<string, string> => {
return [...midToTrackId.entries()]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

midToTrackId.entries() would not be enough?

Copy link
Contributor Author

@kamil-stasiak kamil-stasiak Jul 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need it to map the result of entries(), which is an IterableIterator, to a simple array

Comment on lines 28 to 30
const trackContext = Array.from(localTrackIdToTrack.values()).find(
(trackContext) => trackContext?.track?.id === localTrackId,
)!;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we move it to a function?

Comment on lines 38 to 49
export const getMuted = <EndpointMetadata, TrackMetadata>(
midToTrackId: Map<string, string> = new Map(),
localEndpoint: EndpointWithTrackContext<EndpointMetadata, TrackMetadata>,
): Record<string, string> => {
return [...midToTrackId.entries()]
.filter(([_mid, trackId]) => localEndpoint.tracks.get(trackId))
.reduce((acc, [mid, trackId]) => {
acc[mid] = trackId;

return acc
}, {} as Record<string, string>);
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly this function should return muted tracks, where do we filter out tracks that are not muted here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed the names of these functions in this file, and I've added some comments


const trackContext = this.trackIdToTrack.get(trackId)!;

trackContext.stream = stream;
trackContext.track = event.track;
trackContext.trackKind = event.track.kind;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i may have missed something, but why are we copying the event.track.kind information to another field while we can access it through trackCotnext.track.kind?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The track field is optional; it's possible to mute a track (replace the track with null) and then unmute it in the future. We need the trackKind to assess bandwidth even though the track is muted

return { ...active, ...muted };
};

export const getActive = <EndpointMetadata, TrackMetadata>(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is active? isn't the name lacking something?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking at the code and comments, i'd go for getActiveTracks/mutedTracks

…ix-error-on-muted-track-renegotiation

# Conflicts:
#	packages/react-client/package.json
#	packages/ts-client/package.json
#	packages/ts-client/src/webrtc/bitrate.ts
#	packages/ts-client/src/webrtc/webRTCEndpoint.ts
…ix-error-on-muted-track-renegotiation

# Conflicts:
#	packages/react-client/package.json
#	packages/ts-client/package.json
#	yarn.lock
@kamil-stasiak kamil-stasiak merged commit 6fbc674 into main Jul 4, 2024
2 checks passed
@kamil-stasiak kamil-stasiak deleted the fix-error-on-muted-track-renegotiation branch July 4, 2024 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants