Skip to content

Commit cb61754

Browse files
Add 'destroy' method to service classes.
Add 'destroy' method to service classes. Revert "Add destroy method to test file." This reverts commit 13db2b7. Add 'destroy' to test file.
1 parent c28ea64 commit cb61754

File tree

7 files changed

+41
-1
lines changed

7 files changed

+41
-1
lines changed

js/module.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,7 @@ export declare function getSourcesSize(sourcesNames: string[]): ISourceSize[];
734734
export interface IServiceFactory {
735735
types(): string[];
736736
create(id: string, name: string, settings?: ISettings): IService;
737+
destroy(stream: IService): void;
737738
legacySettings: IService;
738739
}
739740
export interface IService {

js/module.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,6 +1594,7 @@ export function getSourcesSize(sourcesNames: string[]): ISourceSize[] {
15941594
export interface IServiceFactory {
15951595
types(): string[];
15961596
create(id: string, name: string, settings?: ISettings): IService;
1597+
destroy(stream: IService): void;
15971598
legacySettings: IService;
15981599
}
15991600
/**

obs-studio-client/source/service.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ Napi::Object osn::Service::Init(Napi::Env env, Napi::Object exports)
3030
Napi::HandleScope scope(env);
3131
Napi::Function func = DefineClass(
3232
env, "Service",
33-
{StaticMethod("types", &osn::Service::Types), StaticMethod("create", &osn::Service::Create), InstanceMethod("update", &osn::Service::Update),
33+
{StaticMethod("types", &osn::Service::Types), StaticMethod("destroy", &osn::Service::Destroy), StaticMethod("create", &osn::Service::Create),
34+
InstanceMethod("update", &osn::Service::Update),
3435

3536
InstanceAccessor("name", &osn::Service::GetName, nullptr), InstanceAccessor("properties", &osn::Service::GetProperties, nullptr),
3637
InstanceAccessor("settings", &osn::Service::GetSettings, nullptr),
@@ -127,6 +128,23 @@ Napi::Value osn::Service::Create(const Napi::CallbackInfo &info)
127128
return instance;
128129
}
129130

131+
void osn::Service::Destroy(const Napi::CallbackInfo &info)
132+
{
133+
if (info.Length() != 1)
134+
return;
135+
136+
auto service = Napi::ObjectWrap<osn::Service>::Unwrap(info[0].ToObject());
137+
138+
auto conn = GetConnection(info);
139+
if (!conn)
140+
return;
141+
142+
std::vector<ipc::value> response = conn->call_synchronous_helper("Service", "Destroy", {ipc::value(service->uid)});
143+
144+
if (!ValidateResponse(info, response))
145+
return;
146+
}
147+
130148
Napi::Value osn::Service::GetName(const Napi::CallbackInfo &info)
131149
{
132150
auto conn = GetConnection(info);

obs-studio-client/source/service.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class Service : public Napi::ObjectWrap<osn::Service> {
3131

3232
static Napi::Value Types(const Napi::CallbackInfo &info);
3333
static Napi::Value Create(const Napi::CallbackInfo &info);
34+
static void Destroy(const Napi::CallbackInfo &info);
3435

3536
Napi::Value GetName(const Napi::CallbackInfo &info);
3637
Napi::Value GetProperties(const Napi::CallbackInfo &info);

obs-studio-server/source/osn-service.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ void osn::Service::Register(ipc::server &srv)
3232
std::make_shared<ipc::function>("Create", std::vector<ipc::type>{ipc::type::String, ipc::type::String, ipc::type::String}, Create));
3333
cls->register_function(std::make_shared<ipc::function>(
3434
"Create", std::vector<ipc::type>{ipc::type::String, ipc::type::String, ipc::type::String, ipc::type::String}, Create));
35+
cls->register_function(std::make_shared<ipc::function>("Destroy", std::vector<ipc::type>{ipc::type::UInt64}, Destroy));
3536
cls->register_function(std::make_shared<ipc::function>("CreatePrivate", std::vector<ipc::type>{ipc::type::String, ipc::type::String}, CreatePrivate));
3637
cls->register_function(std::make_shared<ipc::function>("CreatePrivate", std::vector<ipc::type>{ipc::type::String, ipc::type::String, ipc::type::String},
3738
CreatePrivate));
@@ -93,6 +94,21 @@ void osn::Service::Create(void *data, const int64_t id, const std::vector<ipc::v
9394
AUTO_DEBUG;
9495
}
9596

97+
void osn::Service::Destroy(void *data, const int64_t id, const std::vector<ipc::value> &args, std::vector<ipc::value> &rval)
98+
{
99+
obs_service_t *service = static_cast<obs_service_t *>(osn::Service::Manager::GetInstance().find(args[0].value_union.ui64));
100+
if (!service) {
101+
PRETTY_ERROR_RETURN(ErrorCode::InvalidReference, "Service reference is not valid.");
102+
}
103+
104+
osn::Service::Manager::GetInstance().free(service);
105+
106+
obs_service_release(service);
107+
108+
rval.push_back(ipc::value((uint64_t)ErrorCode::Ok));
109+
AUTO_DEBUG;
110+
}
111+
96112
void osn::Service::CreatePrivate(void *data, const int64_t id, const std::vector<ipc::value> &args, std::vector<ipc::value> &rval)
97113
{
98114
std::string serviceId, name;

obs-studio-server/source/osn-service.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class Service {
4444

4545
static void GetTypes(void *data, const int64_t id, const std::vector<ipc::value> &args, std::vector<ipc::value> &rval);
4646
static void Create(void *data, const int64_t id, const std::vector<ipc::value> &args, std::vector<ipc::value> &rval);
47+
static void Destroy(void *data, const int64_t id, const std::vector<ipc::value> &args, std::vector<ipc::value> &rval);
4748
static void CreatePrivate(void *data, const int64_t id, const std::vector<ipc::value> &args, std::vector<ipc::value> &rval);
4849
static void GetName(void *data, const int64_t id, const std::vector<ipc::value> &args, std::vector<ipc::value> &rval);
4950
static void GetProperties(void *data, const int64_t id, const std::vector<ipc::value> &args, std::vector<ipc::value> &rval);

tests/osn-tests/src/test_osn_service.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ describe(testName, () => {
7272
if (prop && prop.name == 'server')
7373
expect(prop.details.items).to.have.lengthOf.above(1);
7474
}
75+
osn.ServiceFactory.destroy(service);
7576
});
7677

7778
it('Create rtmp custom', () => {
@@ -91,5 +92,6 @@ describe(testName, () => {
9192
expect(settings.key).to.equal('key', 'Error while updating the service key');
9293
expect(settings.username).to.equal('username', 'Error while updating the service username');
9394
expect(settings.password).to.equal('password', 'Error while updating the service password');
95+
osn.ServiceFactory.destroy(service);
9496
});
9597
});

0 commit comments

Comments
 (0)