Skip to content

Conversation

exeldro
Copy link
Contributor

@exeldro exeldro commented Aug 23, 2023

Description

Add function to resize the browser source from javascript

Motivation and Context

Allows browser sources to be sized to exactly fit its contents.
The use case is my Markdown Source plugin. I want to me able to size the browser source to its contents provided by the markdown. I could hack a way by forcing obs-websocket enabled and getting the obs-websocket port and password from the settings and provide that to the the browser source, but I prefer a way that I don't have to force users to enable obs-websocket.

How Has This Been Tested?

On windows 11 64 bit using Markdown Source with the following javascript:

	let size = document.body.getBoundingClientRect();
	window.obsstudio.setBrowserSize(Math.ceil(size.width), Math.ceil(size.height));

Types of changes

  • New feature (non-breaking change which adds functionality)

Checklist:

  • My code has been run through clang-format.
  • I have read the contributing document.
  • My code is not on the master branch.
  • The code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.

@WizardCM WizardCM added the Enhancement New feature or improvement label Aug 23, 2023
Copy link
Collaborator

@Lain-B Lain-B left a comment

Choose a reason for hiding this comment

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

Would love to have more feedback from others, but otherwise I don't mind one way or another. Maybe @Warchamp7 has an opinion on this one?

But here's one super tiny nitpick.

obs_data_get_int(s, "height") != height)) {
obs_data_set_int(s, "width", width);
obs_data_set_int(s, "height", height);
obs_source_update(bs->source, nullptr);
Copy link
Collaborator

Choose a reason for hiding this comment

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

bs->source probably should be s just to be safe.

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 am not sure what you mean as bs->source is a obs_source_t* and s is a obs_data_t*.

obs_data_get_int(s, "height") != height)) {
obs_data_set_int(s, "width", width);
obs_data_set_int(s, "height", height);
obs_source_update(bs->source, nullptr);
Copy link
Member

Choose a reason for hiding this comment

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

I think this isn't really how obs_source_update is meant to be used.
Sure, you can do it like this, but really you're meant to pass a new obs_data_t object containing the new settings (in place of the nullptr), instead of modifying the object obtained by obs_source_get_settings directly.

And while you're at it, you should probably use the C++-RAII-types (OBSData / OBSDataAutoRelease) in C++-code.

@Warchamp7
Copy link
Member

What's the use case for adding a new obs-browser js binding over say using obs-websockets? Is it just the hurdle of connecting to obs-ws?

Ever since obs-ws was made a core plugin I'm generally against adding new obs-browser bindings to avoid maintaining essentially two browser source APIs.

At the very least, I think a better approach here would be a more abstract system that allows browser sources to dispatch() an event to OBS plugins. Then your plugin could handle the source resizing in response to that event.

@exeldro exeldro changed the title Add function to resize the browser source from javascript Add function to resize the browser source from JavaScript Apr 11, 2024
@exeldro
Copy link
Contributor Author

exeldro commented Aug 8, 2025

The use case is my Markdown Source plugin. I want to me able to size the browser source to its contents provided by the markdown. I could hack a way by forcing obs-websocket enabled and getting the obs-websocket port and password from the settings and provide that to the the browser source, but I prefer a way that I don't have to force users to enable obs-websocket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants