Skip to content

Commit 21d9b87

Browse files
committed
Add function to resize the browser source from javascript
1 parent bdabf83 commit 21d9b87

File tree

3 files changed

+35
-7
lines changed

3 files changed

+35
-7
lines changed

README.md

Lines changed: 9 additions & 0 deletions
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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,13 @@ void BrowserApp::OnBeforeCommandLineProcessing(const CefString &, CefRefPtr<CefC
9999
#endif
100100
}
101101

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

110110
void BrowserApp::OnContextCreated(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame>, CefRefPtr<CefV8Context> context)
111111
{

browser-client.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,25 @@ bool BrowserClient::OnProcessMessageReceived(CefRefPtr<CefBrowser> browser, CefR
218218
case ControlLevel::Basic:
219219
if (name == "saveReplayBuffer") {
220220
obs_frontend_replay_buffer_save();
221+
} else if (name == "setBrowserSize") {
222+
int width = input_args->GetInt(1);
223+
int height = input_args->GetInt(2);
224+
if (!width)
225+
width = (int)round(input_args->GetDouble(1));
226+
if (!height)
227+
height = (int)round(input_args->GetDouble(2));
228+
if (width > 0 && height > 0) {
229+
OBSDataAutoRelease s = obs_source_get_settings(bs->source);
230+
if (s && (obs_data_get_int(s, "width") != width ||
231+
obs_data_get_int(s, "height") != height)) {
232+
obs_data_set_int(s, "width", width);
233+
obs_data_set_int(s, "height", height);
234+
obs_source_update(bs->source, s);
235+
}
236+
} else {
237+
blog(LOG_WARNING, "Browser source '%s' tried to change its size to %ix%i",
238+
obs_source_get_name(bs->source), width, height);
239+
}
221240
}
222241
[[fallthrough]];
223242
case ControlLevel::ReadUser:

0 commit comments

Comments
 (0)