Skip to content

Commit a06dc72

Browse files
committed
Add function to resize the browser source from javascript
1 parent b4f724a commit a06dc72

File tree

3 files changed

+40
-7
lines changed

3 files changed

+40
-7
lines changed

README.md

+9
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,15 @@ Permissions required: ALL
315315
window.obsstudio.stopVirtualcam()
316316
```
317317

318+
#### Set the browser size
319+
Permissions required: BASIC
320+
```js
321+
/**
322+
* @param {int} width - Width of the browser size
323+
* @param {int} height - Height of the browser size
324+
*/
325+
window.obsstudio.setBrowserSize(width, height)
326+
```
318327

319328
### Register for visibility callbacks
320329

browser-app.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,13 @@ void BrowserApp::OnBeforeCommandLineProcessing(
100100
}
101101

102102
std::vector<std::string> exposedFunctions = {
103-
"getControlLevel", "getCurrentScene", "getStatus",
104-
"startRecording", "stopRecording", "startStreaming",
105-
"stopStreaming", "pauseRecording", "unpauseRecording",
106-
"startReplayBuffer", "stopReplayBuffer", "saveReplayBuffer",
107-
"startVirtualcam", "stopVirtualcam", "getScenes",
108-
"setCurrentScene", "getTransitions", "getCurrentTransition",
109-
"setCurrentTransition"};
103+
"getControlLevel", "getCurrentScene", "getStatus",
104+
"startRecording", "stopRecording", "startStreaming",
105+
"stopStreaming", "pauseRecording", "unpauseRecording",
106+
"startReplayBuffer", "stopReplayBuffer", "saveReplayBuffer",
107+
"startVirtualcam", "stopVirtualcam", "getScenes",
108+
"setCurrentScene", "getTransitions", "getCurrentTransition",
109+
"setCurrentTransition", "setBrowserSize"};
110110

111111
void BrowserApp::OnContextCreated(CefRefPtr<CefBrowser> browser,
112112
CefRefPtr<CefFrame>,

browser-client.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,30 @@ bool BrowserClient::OnProcessMessageReceived(
198198
case ControlLevel::Basic:
199199
if (name == "saveReplayBuffer") {
200200
obs_frontend_replay_buffer_save();
201+
} else if (name == "setBrowserSize") {
202+
int width = input_args->GetInt(1);
203+
int height = input_args->GetInt(2);
204+
if (!width)
205+
width = (int)round(input_args->GetDouble(1));
206+
if (!height)
207+
height = (int)round(input_args->GetDouble(2));
208+
if (width > 0 && height > 0) {
209+
obs_data_t *s =
210+
obs_source_get_settings(bs->source);
211+
if (s &&
212+
(obs_data_get_int(s, "width") != width ||
213+
obs_data_get_int(s, "height") != height)) {
214+
obs_data_set_int(s, "width", width);
215+
obs_data_set_int(s, "height", height);
216+
obs_source_update(bs->source, nullptr);
217+
obs_data_release(s);
218+
}
219+
} else {
220+
blog(LOG_WARNING,
221+
"Browser source '%s' tried to change its size to %ix%i",
222+
obs_source_get_name(bs->source), width,
223+
height);
224+
}
201225
}
202226
[[fallthrough]];
203227
case ControlLevel::ReadUser:

0 commit comments

Comments
 (0)