Skip to content

Conversation

@DrFlowerkick
Copy link
Contributor

No description provided.

@DrFlowerkick
Copy link
Contributor Author

One question regarding use_user_media:

Effect::watch(
    move || enabled.get(),
    move |enabled, _, _| {
        if *enabled {
            leptos::task::spawn_local({
                #[cfg(not(feature = "ssr"))]
                let _start = _start.clone();

                async move {
                    _start().await;
                }
            });
        } else {
            _stop();
        }
    },
    true,
);

As far as I understand, a leptos Effect is only executed inside the reactive system on client side. Therefore we do not need to check #[cfg(not(feature = "ssr"))], correct?

@DrFlowerkick
Copy link
Contributor Author

I suggest some rework of the API of these hooks:

  1. Remove enabled form UseUserMediaOptions. We can create a enabled signal inside the hook and return it.
  2. Add bool immediate variable to UseUserMediaOptions to start the stream immediately.
  3. Remove set_enabled from UseUserMediaReturn. The hook provides start and stop to control the stream.
  4. Add a stream source variable to UseUserMediaOptions. The examples of both hooks show, that a source has to be attached to the stream. I suggest to include this to the hook API for better usability.

@maccesch maccesch merged commit baba63a into Synphonyte:main Nov 26, 2025
2 of 4 checks passed
@maccesch
Copy link
Contributor

Thank you!

I suggest some rework of the API of these hooks:

1. Remove `enabled` form `UseUserMediaOptions`. We can create a `enabled` signal inside the hook and return it.

Answered in Discord.


2. Add bool `immediate` variable to `UseUserMediaOptions` to start the stream immediately.

I'm a bit torn with this one... we have a few other hooks that use this kind of options.
But then again, this is already possible with providing the enabled option as true.


3. Remove `set_enabled` from `UseUserMediaReturn`. The hook provides `start` and `stop` to control the stream.
4. Add a stream source variable to `UseUserMediaOptions`. The examples of both hooks show, that a source has to be attached to the stream. I suggest to include this to the hook API for better usability.

Both also answered in Discord.

@DrFlowerkick DrFlowerkick deleted the fix_media_stream_hooks branch November 26, 2025 22:11
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.

2 participants