Skip to content

Commit e441565

Browse files
authored
return exitCode for virtualcam install, uninstall, & start functions (#1558)
* return exitCode for virtualcam install, uninstall, & start functions. * frontend will synthesize the error message
1 parent 6156a74 commit e441565

File tree

6 files changed

+23
-32
lines changed

6 files changed

+23
-32
lines changed

obs-studio-client/source/nodeobs_service.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -383,10 +383,9 @@ Napi::Value service::OBS_service_startVirtualCam(const Napi::CallbackInfo &info)
383383
// On macOS, we will wait for a response. Our situation is more complicated due to the vcam SystemExtension
384384
// which will return errors that we need to display to the user.
385385
std::vector<ipc::value> response = conn->call_synchronous_helper("NodeOBS_Service", "OBS_service_startVirtualCam", {});
386-
387-
if (response.size() == 2) {
386+
if (response.size() > 1) {
388387
// We encountered an error setting up the vcam
389-
return Napi::String::New(info.Env(), response.at(1).value_str);
388+
Napi::Error::New(info.Env(), response[1].value_str).ThrowAsJavaScriptException();
390389
}
391390
#else
392391
conn->call("NodeOBS_Service", "OBS_service_startVirtualCam", {});
@@ -422,7 +421,7 @@ Napi::Value service::OBS_service_updateVirtualCam(const Napi::CallbackInfo &info
422421

423422
Napi::Value service::OBS_service_installVirtualCamPlugin(const Napi::CallbackInfo &info)
424423
{
425-
std::string message;
424+
int errorCode = 0;
426425
#ifdef WIN32
427426
SHELLEXECUTEINFO ShExecInfo = {0};
428427
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
@@ -442,14 +441,14 @@ Napi::Value service::OBS_service_installVirtualCamPlugin(const Napi::CallbackInf
442441
CloseHandle(ShExecInfo.hProcess);
443442

444443
#elif __APPLE__
445-
message = g_util_osx->installPlugin();
444+
errorCode = g_util_osx->installPlugin();
446445
#endif
447-
return Napi::String::New(info.Env(), message);
446+
return Napi::Number::New(info.Env(), errorCode);
448447
}
449448

450449
Napi::Value service::OBS_service_uninstallVirtualCamPlugin(const Napi::CallbackInfo &info)
451450
{
452-
std::string message;
451+
int errorCode = 0;
453452
#ifdef WIN32
454453
SHELLEXECUTEINFO ShExecInfo = {0};
455454
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
@@ -481,9 +480,9 @@ Napi::Value service::OBS_service_uninstallVirtualCamPlugin(const Napi::CallbackI
481480
CloseHandle(ShExecInfo.hProcess);
482481
}
483482
#elif __APPLE__
484-
message = g_util_osx->uninstallPlugin();
483+
errorCode = g_util_osx->uninstallPlugin();
485484
#endif
486-
return Napi::String::New(info.Env(), message);
485+
return Napi::Number::New(info.Env(), errorCode);
487486
}
488487

489488
Napi::Value service::OBS_service_isVirtualCamPluginInstalled(const Napi::CallbackInfo &info)

obs-studio-client/source/util-osx-impl.mm

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ void uninstallLegacyDALPlugin()
3838
}
3939
}
4040

41-
std::string executeTaskAndCaptureOutput(const std::string &path, NSArray<NSString *> *exeArguments = nullptr)
41+
int executeTaskAndCaptureOutput(const std::string &path, NSArray<NSString *> *exeArguments = nullptr)
4242
{
43-
std::string errorMessage;
43+
int exitCode = 0;
4444
@autoreleasepool {
4545
@try {
4646
// Create an NSTask instance
@@ -61,7 +61,7 @@ void uninstallLegacyDALPlugin()
6161
[task launch];
6262
[task waitUntilExit];
6363

64-
int exitCode = [task terminationStatus];
64+
exitCode = [task terminationStatus];
6565

6666
// Read the data from the pipe
6767
NSFileHandle *readHandle = [outputPipe fileHandleForReading];
@@ -71,19 +71,16 @@ void uninstallLegacyDALPlugin()
7171
NSString *outputString = [[NSString alloc] initWithData:outputData encoding:NSUTF8StringEncoding];
7272

7373
// Print the captured output
74-
if (exitCode != 0) {
75-
errorMessage = outputString.UTF8String;
76-
}
7774
std::cout << "Child process output:\n" << outputString.UTF8String << std::endl;
7875
std::cout << "Child process exited with code: " << exitCode << std::endl;
7976
} @catch (NSException *exception) {
8077
std::cout << "Caught an NSException!" << std::endl;
8178
std::cout << "Name: " << [[exception name] UTF8String] << std::endl;
8279
std::cout << "Reason: " << [[exception reason] UTF8String] << std::endl;
83-
errorMessage = [[exception reason] UTF8String];
80+
exitCode = 1;
8481
}
8582
}
86-
return errorMessage;
83+
return exitCode;
8784
}
8885

8986
// In our app bundle, we will search for the slobs-virtual-cam-installer.app which
@@ -172,13 +169,13 @@ bool replace(std::string &str, const std::string &from, const std::string &to)
172169
return true;
173170
}
174171

175-
std::string UtilObjCInt::installPlugin()
172+
int UtilObjCInt::installPlugin()
176173
{
177174
const std::string path = getInstallerAppPath();
178175
return executeTaskAndCaptureOutput(path); // Run the installer
179176
}
180177

181-
std::string UtilObjCInt::uninstallPlugin()
178+
int UtilObjCInt::uninstallPlugin()
182179
{
183180
uninstallLegacyDALPlugin();
184181
// Uninstall the camera system extension

obs-studio-client/source/util-osx-int.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ class UtilObjCInt {
3737
void init(void);
3838
void getPermissionsStatus(bool &webcam, bool &mic);
3939
void requestPermissions(void *async_cb, perms_cb cb);
40-
std::string installPlugin(void);
41-
std::string uninstallPlugin(void);
40+
int installPlugin(void);
41+
int uninstallPlugin(void);
4242
void setServerWorkingDirectoryPath(std::string path);
4343
bool isPluginInstalled();
4444

obs-studio-client/source/util-osx.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ void UtilInt::requestPermissions(void *async_cb, perms_cb cb)
4444
_impl->requestPermissions(async_cb, cb);
4545
}
4646

47-
std::string UtilInt::installPlugin(void)
47+
int UtilInt::installPlugin(void)
4848
{
4949
return _impl->installPlugin();
5050
}
5151

52-
std::string UtilInt::uninstallPlugin(void)
52+
int UtilInt::uninstallPlugin(void)
5353
{
5454
return _impl->uninstallPlugin();
5555
}

obs-studio-client/source/util-osx.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ class UtilInt {
3333
void init(void);
3434
void getPermissionsStatus(bool &webcam, bool &mic);
3535
void requestPermissions(void *async_cb, perms_cb cb);
36-
std::string installPlugin(void);
37-
std::string uninstallPlugin(void);
36+
int installPlugin(void);
37+
int uninstallPlugin(void);
3838
void setServerWorkingDirectoryPath(std::string path);
3939
bool isPluginInstalled();
4040

obs-studio-server/source/nodeobs_service.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3137,10 +3137,7 @@ void OBS_service::StartVirtualCam(std::vector<ipc::value> &rval)
31373137
virtualCamVideo = typeIsProgram ? obs_get_video() : obs_view_add(virtualCamView);
31383138

31393139
if (!virtualCamVideo) {
3140-
blog(LOG_ERROR, "Failed to create virtual camera video");
3141-
rval.push_back(ipc::value((uint64_t)ErrorCode::Error));
3142-
rval.push_back(ipc::value("Failed to create virtual camera video"));
3143-
return;
3140+
PRETTY_ERROR_RETURN(ErrorCode::Error, "Failed to create virtual camera video");
31443141
}
31453142
}
31463143

@@ -3149,10 +3146,8 @@ void OBS_service::StartVirtualCam(std::vector<ipc::value> &rval)
31493146
bool success = obs_output_start(virtualCam);
31503147
if (!success) {
31513148
const char *error = obs_output_get_last_error(virtualCam);
3152-
blog(LOG_ERROR, "Virtual Camera output start failed. Error: '%s'", error);
3153-
rval.push_back(ipc::value((uint64_t)ErrorCode::Error));
3154-
rval.push_back(ipc::value(error));
31553149
DestroyVirtualCamView();
3150+
PRETTY_ERROR_RETURN(ErrorCode::Error, error);
31563151
}
31573152

31583153
virtualCamActive = true;

0 commit comments

Comments
 (0)