Add function to resize the browser source from JavaScript #423

Open
exeldro wants to merge 1 commit from exeldro/browser_size into master
exeldro commented 2023-08-23 02:35:40 -05:00 (Migrated from github.com)

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.
### 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: - [x] My code has been run through [clang-format](https://github.com/obsproject/obs-studio/blob/master/.clang-format). - [x] I have read the [**contributing** document](https://github.com/obsproject/obs-studio/blob/master/CONTRIBUTING.rst). - [x] My code is not on the master branch. - [x] The code has been tested. - [x] All commit messages are properly formatted and commits squashed where appropriate. - [x] I have included updates to all appropriate documentation.
Lain-B (Migrated from github.com) requested changes 2023-09-16 18:31:17 -05:00
Lain-B (Migrated from github.com) left a comment

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.

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.
Lain-B (Migrated from github.com) commented 2023-09-16 18:30:24 -05:00

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

`bs->source` probably should be `s` just to be safe.
exeldro (Migrated from github.com) reviewed 2024-04-05 02:49:30 -05:00
exeldro (Migrated from github.com) commented 2024-04-05 02:49:30 -05:00

I am not sure what you mean as bs->source is a obs_source_t* and s is a obs_data_t*.

I am not sure what you mean as `bs->source` is a `obs_source_t*` and `s` is a `obs_data_t*`.
sebastian-s-beckmann (Migrated from github.com) reviewed 2024-04-05 03:24:36 -05:00
sebastian-s-beckmann (Migrated from github.com) commented 2024-04-05 03:24:13 -05:00

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.

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 commented 2024-04-05 10:54:36 -05:00 (Migrated from github.com)

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.

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 commented 2025-08-08 01:11:12 -05:00 (Migrated from github.com)

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.

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.
deemonrider commented 2026-01-04 09:31:01 -06:00 (Migrated from github.com)

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?

Yes, getting streamers to setup websocket for obs is usally too complicated, you will lose the majority of streamers if they need to setup this. But even worse: you can’t connect from a browser source to the OBS WebSocket:
Browser sources are usually HTTPS-only, while the OBS WebSocket is non-secure, which results in a mixed-content restriction.

That means the browser source would need to be hosted over HTTP to be able to even use obs-ws

> 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? Yes, getting streamers to setup websocket for obs is usally too complicated, you will lose the majority of streamers if they need to setup this. But even worse: you can’t connect from a browser source to the OBS WebSocket: Browser sources are usually HTTPS-only, while the OBS WebSocket is non-secure, which results in a mixed-content restriction. That means the browser source would need to be hosted over HTTP to be able to even use obs-ws
This pull request is broken due to missing fork information.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'exeldro/browser_size:exeldro/browser_size'
git switch 'exeldro/browser_size'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'master'
git merge --no-ff 'exeldro/browser_size'
git switch 'exeldro/browser_size'
git rebase 'master'
git switch 'master'
git merge --ff-only 'exeldro/browser_size'
git switch 'exeldro/browser_size'
git rebase 'master'
git switch 'master'
git merge --no-ff 'exeldro/browser_size'
git switch 'master'
git merge --squash 'exeldro/browser_size'
git switch 'master'
git merge --ff-only 'exeldro/browser_size'
git switch 'master'
git merge 'exeldro/browser_size'
git push origin 'master'
Sign in to join this conversation.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-obsproject/obs-browser!423
No description provided.