Skip to content

Commit 64cfc2f

Browse files
author
eddyStreamlabs
committed
Add module load/init
1 parent adce1f0 commit 64cfc2f

7 files changed

Lines changed: 560 additions & 3 deletions

File tree

js/module.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ export interface IAudioFactory {
661661
getGlobal(): IAudio;
662662
}
663663
export interface IModuleFactory {
664-
create(binPath: string, dataPath: string): IModule;
664+
open(binPath: string, dataPath: string): IModule;
665665
loadAll(): void;
666666
addPath(path: string, dataPath: string): void;
667667
logLoaded(): void;

js/module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1494,7 +1494,7 @@ export interface IAudioFactory {
14941494

14951495

14961496
export interface IModuleFactory {
1497-
create(binPath: string, dataPath: string): IModule;
1497+
open(binPath: string, dataPath: string): IModule;
14981498
loadAll(): void;
14991499
addPath(path: string, dataPath: string): void;
15001500
logLoaded(): void;

obs-studio-client/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ SET(PROJECT_SOURCE
6969
"${PROJECT_SOURCE_DIR}/source/main.cpp"
7070
"${PROJECT_SOURCE_DIR}/source/volmeter.cpp" "${PROJECT_SOURCE_DIR}/source/volmeter.hpp"
7171
"${PROJECT_SOURCE_DIR}/source/video.cpp" "${PROJECT_SOURCE_DIR}/source/video.hpp"
72+
"${PROJECT_SOURCE_DIR}/source/module.cpp" "${PROJECT_SOURCE_DIR}/source/module.hpp"
7273
)
7374
SET(PROJECT_LIBRARIES
7475
${NODEJS_LIBRARIES}
Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
// Client module for the OBS Studio node module.
2+
// Copyright(C) 2017 Streamlabs (General Workings Inc)
3+
//
4+
// This program is free software; you can redistribute it and/or
5+
// modify it under the terms of the GNU General Public License
6+
// as published by the Free Software Foundation; either version 2
7+
// of the License, or (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with this program; if not, write to the Free Software
16+
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 - 1301, USA.
17+
18+
#include <condition_variable>
19+
#include <mutex>
20+
#include <string>
21+
#include "controller.hpp"
22+
#include "error.hpp"
23+
#include "ipc-value.hpp"
24+
#include "shared.hpp"
25+
#include "utility.hpp"
26+
#include "module.hpp"
27+
28+
osn::Module::Module(uint64_t id)
29+
{
30+
this->moduleId = id;
31+
}
32+
33+
Nan::Persistent<v8::FunctionTemplate> osn::Module::prototype = Nan::Persistent<v8::FunctionTemplate>();
34+
35+
void osn::Module::Register(Nan::ADDON_REGISTER_FUNCTION_ARGS_TYPE target)
36+
{
37+
auto fnctemplate = Nan::New<v8::FunctionTemplate>();
38+
fnctemplate->Inherit(Nan::New<v8::FunctionTemplate>(osn::Module::prototype));
39+
fnctemplate->InstanceTemplate()->SetInternalFieldCount(1);
40+
fnctemplate->SetClassName(Nan::New<v8::String>("Module").ToLocalChecked());
41+
42+
utilv8::SetTemplateField(fnctemplate, "open", Open);
43+
utilv8::SetTemplateField(fnctemplate, "initialize", Initialize);
44+
45+
v8::Local<v8::Template> objtemplate = fnctemplate->PrototypeTemplate();
46+
utilv8::SetTemplateAccessorProperty(objtemplate, "name", Name);
47+
utilv8::SetTemplateAccessorProperty(objtemplate, "fileName", FileName);
48+
utilv8::SetTemplateAccessorProperty(objtemplate, "author", Author);
49+
utilv8::SetTemplateAccessorProperty(objtemplate, "description", Description);
50+
utilv8::SetTemplateAccessorProperty(objtemplate, "binaryPath", BinaryPath);
51+
utilv8::SetTemplateAccessorProperty(objtemplate, "dataPath", DataPath);
52+
53+
utilv8::SetObjectField(target, "Module", fnctemplate->GetFunction());
54+
prototype.Reset(fnctemplate);
55+
}
56+
57+
Nan::NAN_METHOD_RETURN_TYPE osn::Module::Open(Nan::NAN_METHOD_ARGS_TYPE info)
58+
{
59+
std::string bin_path, data_path;
60+
61+
ASSERT_INFO_LENGTH(info, 2);
62+
ASSERT_GET_VALUE(info[0], bin_path);
63+
ASSERT_GET_VALUE(info[0], data_path);
64+
65+
auto conn = GetConnection();
66+
if (!conn)
67+
return;
68+
69+
std::vector<ipc::value> response = conn->call_synchronous_helper("Module", "Open", {ipc::value(bin_path), ipc::value(data_path)});
70+
71+
if (!ValidateResponse(response))
72+
return;
73+
74+
osn::Module* obj = new osn::Module(response[1].value_union.ui64);
75+
info.GetReturnValue().Set(osn::Module::Store(obj));
76+
}
77+
78+
Nan::NAN_METHOD_RETURN_TYPE osn::Module::Initialize(Nan::NAN_METHOD_ARGS_TYPE info)
79+
{
80+
osn::Module* module;
81+
if (!utilv8::SafeUnwrap(info, module)) {
82+
return;
83+
}
84+
85+
auto conn = GetConnection();
86+
if (!conn)
87+
return;
88+
89+
std::vector<ipc::value> response =
90+
conn->call_synchronous_helper("Module", "Initialize", {ipc::value(module->moduleId)});
91+
92+
if (!ValidateResponse(response))
93+
return;
94+
95+
info.GetReturnValue().Set(response[1].value_union.i32);
96+
}
97+
98+
Nan::NAN_METHOD_RETURN_TYPE osn::Module::Name(Nan::NAN_METHOD_ARGS_TYPE info)
99+
{
100+
osn::Module* module;
101+
if (!utilv8::SafeUnwrap(info, module)) {
102+
return;
103+
}
104+
105+
auto conn = GetConnection();
106+
if (!conn)
107+
return;
108+
109+
std::vector<ipc::value> response =
110+
conn->call_synchronous_helper("Module", "GetName", {ipc::value(module->moduleId)});
111+
112+
if (!ValidateResponse(response))
113+
return;
114+
115+
info.GetReturnValue().Set(utilv8::ToValue(response[1].value_str));
116+
}
117+
118+
Nan::NAN_METHOD_RETURN_TYPE osn::Module::FileName(Nan::NAN_METHOD_ARGS_TYPE info)
119+
{
120+
osn::Module* module;
121+
if (!utilv8::SafeUnwrap(info, module)) {
122+
return;
123+
}
124+
125+
auto conn = GetConnection();
126+
if (!conn)
127+
return;
128+
129+
std::vector<ipc::value> response =
130+
conn->call_synchronous_helper("Module", "GetFileName", {ipc::value(module->moduleId)});
131+
132+
if (!ValidateResponse(response))
133+
return;
134+
135+
info.GetReturnValue().Set(utilv8::ToValue(response[1].value_str));
136+
}
137+
138+
Nan::NAN_METHOD_RETURN_TYPE osn::Module::Description(Nan::NAN_METHOD_ARGS_TYPE info)
139+
{
140+
osn::Module* module;
141+
if (!utilv8::SafeUnwrap(info, module)) {
142+
return;
143+
}
144+
145+
auto conn = GetConnection();
146+
if (!conn)
147+
return;
148+
149+
std::vector<ipc::value> response =
150+
conn->call_synchronous_helper("Module", "GetDescription", {ipc::value(module->moduleId)});
151+
152+
if (!ValidateResponse(response))
153+
return;
154+
155+
info.GetReturnValue().Set(utilv8::ToValue(response[1].value_str));
156+
}
157+
158+
Nan::NAN_METHOD_RETURN_TYPE osn::Module::Author(Nan::NAN_METHOD_ARGS_TYPE info)
159+
{
160+
osn::Module* module;
161+
if (!utilv8::SafeUnwrap(info, module)) {
162+
return;
163+
}
164+
165+
auto conn = GetConnection();
166+
if (!conn)
167+
return;
168+
169+
std::vector<ipc::value> response =
170+
conn->call_synchronous_helper("Module", "GetAuthor", {ipc::value(module->moduleId)});
171+
172+
if (!ValidateResponse(response))
173+
return;
174+
175+
info.GetReturnValue().Set(utilv8::ToValue(response[1].value_str));
176+
}
177+
178+
Nan::NAN_METHOD_RETURN_TYPE osn::Module::BinaryPath(Nan::NAN_METHOD_ARGS_TYPE info)
179+
{
180+
osn::Module* module;
181+
if (!utilv8::SafeUnwrap(info, module)) {
182+
return;
183+
}
184+
185+
auto conn = GetConnection();
186+
if (!conn)
187+
return;
188+
189+
std::vector<ipc::value> response =
190+
conn->call_synchronous_helper("Module", "GetBinaryPath", {ipc::value(module->moduleId)});
191+
192+
if (!ValidateResponse(response))
193+
return;
194+
195+
info.GetReturnValue().Set(utilv8::ToValue(response[1].value_str));
196+
}
197+
198+
Nan::NAN_METHOD_RETURN_TYPE osn::Module::DataPath(Nan::NAN_METHOD_ARGS_TYPE info)
199+
{
200+
osn::Module* module;
201+
if (!utilv8::SafeUnwrap(info, module)) {
202+
return;
203+
}
204+
205+
auto conn = GetConnection();
206+
if (!conn)
207+
return;
208+
209+
std::vector<ipc::value> response =
210+
conn->call_synchronous_helper("Module", "GetDataPath", {ipc::value(module->moduleId)});
211+
212+
if (!ValidateResponse(response))
213+
return;
214+
215+
info.GetReturnValue().Set(utilv8::ToValue(response[1].value_str));
216+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Client module for the OBS Studio node module.
2+
// Copyright(C) 2017 Streamlabs (General Workings Inc)
3+
//
4+
// This program is free software; you can redistribute it and/or
5+
// modify it under the terms of the GNU General Public License
6+
// as published by the Free Software Foundation; either version 2
7+
// of the License, or (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with this program; if not, write to the Free Software
16+
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110 - 1301, USA.
17+
18+
#pragma once
19+
#include <nan.h>
20+
#include <node.h>
21+
#include "utility-v8.hpp"
22+
23+
namespace osn
24+
{
25+
class Module : public utilv8::ManagedObject<osn::Module>, public Nan::ObjectWrap
26+
{
27+
friend class utilv8::ManagedObject<osn::Module>;
28+
29+
public:
30+
uint64_t moduleId;
31+
Module(uint64_t id);
32+
virtual ~Module(){};
33+
34+
// JavaScript
35+
public:
36+
static Nan::Persistent<v8::FunctionTemplate> prototype;
37+
38+
static void Register(Nan::ADDON_REGISTER_FUNCTION_ARGS_TYPE target);
39+
40+
//Functions
41+
static Nan::NAN_METHOD_RETURN_TYPE Open(Nan::NAN_METHOD_ARGS_TYPE info);
42+
static Nan::NAN_METHOD_RETURN_TYPE Initialize(Nan::NAN_METHOD_ARGS_TYPE info);
43+
44+
//Methods
45+
static Nan::NAN_METHOD_RETURN_TYPE Name(Nan::NAN_METHOD_ARGS_TYPE info);
46+
static Nan::NAN_METHOD_RETURN_TYPE FileName(Nan::NAN_METHOD_ARGS_TYPE info);
47+
static Nan::NAN_METHOD_RETURN_TYPE Author(Nan::NAN_METHOD_ARGS_TYPE info);
48+
static Nan::NAN_METHOD_RETURN_TYPE Description(Nan::NAN_METHOD_ARGS_TYPE info);
49+
static Nan::NAN_METHOD_RETURN_TYPE BinaryPath(Nan::NAN_METHOD_ARGS_TYPE info);
50+
static Nan::NAN_METHOD_RETURN_TYPE DataPath(Nan::NAN_METHOD_ARGS_TYPE info);
51+
52+
53+
};
54+
} // namespace osn

0 commit comments

Comments
 (0)