Mute track#79
Conversation
| }, | ||
| "dependencies": { | ||
| "@fishjam-dev/ts-client": "^0.5.0", | ||
| "@fishjam-dev/ts-client": "github:fishjam-dev/ts-client-sdk#mute-track", |
There was a problem hiding this comment.
Replace with released version
| }, | ||
| replaceTrack: async (newTrackMetadata?: TrackMetadata) => { | ||
| const prevTrack = Object.values(localTracks).find((track) => track.track?.id === this.currentCameraTrackId); | ||
| if (!this.currentCameraTrackId) throw Error("There is no audio track id"); |
| type OnDeviceChange = "stop" | "replace" | undefined; | ||
| type OnDeviceStop = "remove" | "mute" | undefined; | ||
|
|
||
| const isRestartChange = (e: string | undefined): e is RestartChange => { | ||
| return e === undefined || e === "stop" || e === "replace"; | ||
| }; | ||
| const isDeviceChangeValue = (e: string | undefined): e is OnDeviceChange => | ||
| e === undefined || e === "stop" || e === "replace"; | ||
|
|
||
| const isDeviceStopValue = (e: string | undefined): e is OnDeviceStop => | ||
| e === undefined || e === "remove" || e === "mute"; | ||
|
|
There was a problem hiding this comment.
I don't get it... why is "stop" in OnDeviceChange not in "OnDeviceStop"? Does the user also need to write such functions? Why undefined is ok?
There was a problem hiding this comment.
Config accepts an optional string which can be stop or replace. Undefined is for situations when the user skips this parameter (which is valid because there is a default value). The user doesn't need to implement them because that config should be hardcoded. These validators are included because this tool tests this config.
Quick explanation:
OnDeviceChange
When the connection is established and the user changes a device, I saw two possible paths. Either the track from a new device replaces the old track, and other people would see it (replace), or the track would be stopped to prevent showing something that should not be shown (stop). I think I should change this word to remove to be consistent with onDeviceStop.
Now, there is 3 option, we are capable of muting this track and reusing it later. This whole idea is just a proof of concept, and I don't know if we should implement this behavior in all our clients, so I don't want to waste time to implement it right now.
OnDeviceStop
When the user stops their device, I see only two options: remove (or stop) or mute.
So, the word stop is confusing. I'll change it.
Description
This PR introduces changes from: fishjam-dev/ts-client-sdk#49 and also:
useCamera, useMicrophone, useScreenshare
Hooks for managing a single track of a given type in the global state (similarly to the React Native API).
onDeviceStop
onDeviceStop?: "remove" | "mute"; This PR introduces a newonDeviceStopconfig parameter that allows the user to decide what to do if a track stops. Without it, the track has been removed fromRTCPeerConnection. Now, with the optionmute, that track can be reused later without renegotiation. It is a companion event toonDeviceChange`.Added
onDeviceStop,onDeviceChange, and the ability to stop a device touse-camera-and-microphone-example.onDeviceChange
onDeviceChange?: "replace" | "stop";Determines whether a track should be replaced when the user requests a device change. Previously,
broadcastOnDeviceChange.Other changes
UseMicrophoneResultchanged to something simpler, likeMicrophoneAPI.Motivation and Context
Fishjam now offers the ability to reuse tracks.
Types of changes
replaceTrackmethod can handle a nullable track parameter.streamparameter was removed from theaddTrackmethod.