Skip to content
This repository was archived by the owner on Oct 23, 2024. It is now read-only.

Commit 873a3e9

Browse files
authored
Make addons compatible with higher version Node.js (#1096)
1 parent 1b51c04 commit 873a3e9

35 files changed

+493
-409
lines changed

scripts/build.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@
33
"include" : [
44
"video-mixer-sw",
55
"video-transcoder-sw",
6-
"video-analyzer-sw",
76
"internal-io",
87
"logger",
98
"media-frame-multicaster",
109
"audio",
1110
"audio-ranker",
1211
"webrtc",
1312
"avstream",
14-
"gst-pipeline",
1513
"sip"
1614
]
1715
},
@@ -32,13 +30,17 @@
3230
"mcu-all" : {
3331
"include" : [
3432
"mcu",
33+
"video-analyzer-sw",
34+
"gst-pipeline",
3535
"video-mixer-msdk",
3636
"video-transcoder-msdk"
3737
]
3838
},
3939
"all" : {
4040
"include" : [
4141
"mcu",
42+
"video-analyzer-sw",
43+
"gst-pipeline",
4244
"video-mixer-msdk",
4345
"video-transcoder-msdk"
4446
]

source/agent/addons/audioRanker/AudioRankerWrapper.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ NAN_MODULE_INIT(AudioRanker::Init) {
2424
Nan::SetPrototypeMethod(tpl, "addInput", addInput);
2525
Nan::SetPrototypeMethod(tpl, "removeInput", removeInput);
2626

27-
constructor.Reset(tpl->GetFunction());
27+
constructor.Reset(Nan::GetFunction(tpl).ToLocalChecked());
2828
Nan::Set(target, Nan::New("AudioRanker").ToLocalChecked(), Nan::GetFunction(tpl).ToLocalChecked());
2929
}
3030

@@ -72,7 +72,8 @@ NAN_METHOD(AudioRanker::addOutput) {
7272
AudioRanker* obj = Nan::ObjectWrap::Unwrap<AudioRanker>(info.Holder());
7373
owt_base::AudioRanker* me = obj->me;
7474

75-
FrameDestination* param = node::ObjectWrap::Unwrap<FrameDestination>(info[0]->ToObject(Nan::GetCurrentContext()).ToLocalChecked());
75+
FrameDestination* param = node::ObjectWrap::Unwrap<FrameDestination>(
76+
Nan::To<v8::Object>(info[0]).ToLocalChecked());
7677
owt_base::FrameDestination* dest = param->dest;
7778

7879
me->addOutput(dest);
@@ -82,7 +83,8 @@ NAN_METHOD(AudioRanker::addInput) {
8283
AudioRanker* obj = Nan::ObjectWrap::Unwrap<AudioRanker>(info.Holder());
8384
owt_base::AudioRanker* me = obj->me;
8485

85-
FrameSource* param = node::ObjectWrap::Unwrap<FrameSource>(info[0]->ToObject(Nan::GetCurrentContext()).ToLocalChecked());
86+
FrameSource* param = node::ObjectWrap::Unwrap<FrameSource>(
87+
Nan::To<v8::Object>(info[0]).ToLocalChecked());
8688
owt_base::FrameSource* src = param->src;
8789

8890
Nan::Utf8String streamIdPara(Nan::To<v8::String>(info[1]).ToLocalChecked());

source/agent/addons/avstreamLib/AVStreamInWrap.cc

Lines changed: 46 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,44 +9,51 @@
99

1010
using namespace v8;
1111

12+
static std::string getString(v8::Local<v8::Value> value) {
13+
Nan::Utf8String value_str(Nan::To<v8::String>(value).ToLocalChecked());
14+
return std::string(*value_str);
15+
}
16+
1217
Persistent<Function> AVStreamInWrap::constructor;
1318
AVStreamInWrap::AVStreamInWrap()
1419
{
1520
}
1621
AVStreamInWrap::~AVStreamInWrap() {}
1722

18-
void AVStreamInWrap::Init(Handle<Object> exports, Handle<Object> module)
23+
void AVStreamInWrap::Init(Local<Object> exports, Local<Object> module)
1924
{
2025
Isolate* isolate = exports->GetIsolate();
2126
// Prepare constructor template
2227
Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, New);
23-
tpl->SetClassName(String::NewFromUtf8(isolate, "AVStreamIn"));
28+
tpl->SetClassName(Nan::New("AVStreamIn").ToLocalChecked());
2429
tpl->InstanceTemplate()->SetInternalFieldCount(1);
2530
// Prototype
2631
SETUP_EVENTED_PROTOTYPE_METHODS(tpl);
2732
NODE_SET_PROTOTYPE_METHOD(tpl, "close", close);
2833
NODE_SET_PROTOTYPE_METHOD(tpl, "addDestination", addDestination);
2934
NODE_SET_PROTOTYPE_METHOD(tpl, "removeDestination", removeDestination);
3035

31-
constructor.Reset(isolate, tpl->GetFunction());
32-
module->Set(String::NewFromUtf8(isolate, "exports"), tpl->GetFunction());
36+
constructor.Reset(isolate, Nan::GetFunction(tpl).ToLocalChecked());
37+
Nan::Set(module, Nan::New("exports").ToLocalChecked(),
38+
Nan::GetFunction(tpl).ToLocalChecked());
3339
}
3440

35-
void AVStreamInWrap::Init(Handle<Object> exports)
41+
void AVStreamInWrap::Init(Local<Object> exports)
3642
{
3743
Isolate* isolate = exports->GetIsolate();
3844
// Prepare constructor template
3945
Local<FunctionTemplate> tpl = FunctionTemplate::New(isolate, New);
40-
tpl->SetClassName(String::NewFromUtf8(isolate, "AVStreamIn"));
46+
tpl->SetClassName(Nan::New("AVStreamIn").ToLocalChecked());
4147
tpl->InstanceTemplate()->SetInternalFieldCount(1);
4248
// Prototype
4349
SETUP_EVENTED_PROTOTYPE_METHODS(tpl);
4450
NODE_SET_PROTOTYPE_METHOD(tpl, "close", close);
4551
NODE_SET_PROTOTYPE_METHOD(tpl, "addDestination", addDestination);
4652
NODE_SET_PROTOTYPE_METHOD(tpl, "removeDestination", removeDestination);
4753

48-
constructor.Reset(isolate, tpl->GetFunction());
49-
exports->Set(String::NewFromUtf8(isolate, "AVStreamIn"), tpl->GetFunction());
54+
constructor.Reset(isolate, Nan::GetFunction(tpl).ToLocalChecked());
55+
Nan::Set(exports, Nan::New("AVStreamIn").ToLocalChecked(),
56+
Nan::GetFunction(tpl).ToLocalChecked());
5057
}
5158

5259
void AVStreamInWrap::New(const FunctionCallbackInfo<Value>& args)
@@ -55,41 +62,45 @@ void AVStreamInWrap::New(const FunctionCallbackInfo<Value>& args)
5562
HandleScope scope(isolate);
5663

5764
if (args.Length() == 0 || !args[0]->IsObject()) {
58-
isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Wrong arguments")));
65+
Nan::ThrowError("Wrong arguments");
5966
return;
6067
}
6168

62-
Local<String> keyUrl = String::NewFromUtf8(isolate, "url");
63-
Local<String> keyTransport = String::NewFromUtf8(isolate, "transport");
64-
Local<String> keyBufferSize = String::NewFromUtf8(isolate, "buffer_size");
65-
Local<String> keyAudio = String::NewFromUtf8(isolate, "has_audio");
66-
Local<String> keyVideo = String::NewFromUtf8(isolate, "has_video");
69+
Local<String> keyUrl = Nan::New("url").ToLocalChecked();
70+
Local<String> keyTransport = Nan::New("transport").ToLocalChecked();
71+
Local<String> keyBufferSize = Nan::New("buffer_size").ToLocalChecked();
72+
Local<String> keyAudio = Nan::New("has_audio").ToLocalChecked();
73+
Local<String> keyVideo = Nan::New("has_video").ToLocalChecked();
6774
owt_base::LiveStreamIn::Options param{};
68-
Local<Object> options = args[0]->ToObject(Nan::GetCurrentContext()).ToLocalChecked();
69-
if (options->Has(keyUrl))
70-
param.url = std::string(*String::Utf8Value(isolate, options->Get(keyUrl)->ToString()));
71-
if (options->Has(keyTransport))
72-
param.transport = std::string(*String::Utf8Value(isolate, options->Get(keyTransport)->ToString()));
73-
if (options->Has(keyBufferSize))
74-
param.bufferSize = options->Get(keyBufferSize)->Uint32Value(Nan::GetCurrentContext()).ToChecked();
75-
if (options->Has(keyAudio))
76-
param.enableAudio = std::string(*String::Utf8Value(isolate, options->Get(keyAudio)->ToString()));
77-
if (options->Has(keyVideo))
78-
param.enableVideo = std::string(*String::Utf8Value(isolate, options->Get(keyVideo)->ToString()));
75+
Local<Object> options = Nan::To<v8::Object>(args[0]).ToLocalChecked();
76+
if (Nan::Has(options, keyUrl).FromMaybe(false))
77+
param.url = getString(Nan::Get(options, keyUrl).ToLocalChecked());
78+
if (Nan::Has(options, keyTransport).FromMaybe(false))
79+
param.transport = getString(Nan::Get(options, keyTransport).ToLocalChecked());
80+
if (Nan::Has(options, keyBufferSize).FromMaybe(false))
81+
param.bufferSize = Nan::To<int32_t>(Nan::Get(options, keyBufferSize).ToLocalChecked())
82+
.FromJust();
83+
if (Nan::Has(options, keyAudio).FromMaybe(false))
84+
param.enableAudio = getString(Nan::Get(options, keyAudio).ToLocalChecked());
85+
if (Nan::Has(options, keyVideo).FromMaybe(false))
86+
param.enableVideo = getString(Nan::Get(options, keyVideo).ToLocalChecked());
7987

8088
AVStreamInWrap* obj = new AVStreamInWrap();
81-
std::string type = std::string(*String::Utf8Value(isolate, options->Get(String::NewFromUtf8(isolate, "type"))->ToString()));
89+
std::string type = getString(Nan::Get(options, Nan::New("type").ToLocalChecked())
90+
.ToLocalChecked());
8291
if (type.compare("streaming") == 0)
8392
obj->me = new owt_base::LiveStreamIn(param, obj);
8493
else if (type.compare("file") == 0)
8594
obj->me = new owt_base::MediaFileIn();
8695
else {
87-
isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "Unsupported AVStreamIn type")));
96+
Nan::ThrowError("Unsupported AVStreamIn type");
8897
return;
8998
}
9099

91-
if (args.Length() > 1 && args[1]->IsFunction())
92-
Local<Object>::New(isolate, obj->m_store)->Set(String::NewFromUtf8(isolate, "status"), args[1]);
100+
if (args.Length() > 1 && args[1]->IsFunction()) {
101+
Nan::Set(Local<Object>::New(isolate, obj->m_store),
102+
Nan::New("status").ToLocalChecked(), args[1]);
103+
}
93104

94105
obj->Wrap(args.This());
95106
args.GetReturnValue().Set(args.This());
@@ -115,8 +126,9 @@ void AVStreamInWrap::addDestination(const FunctionCallbackInfo<Value>& args)
115126
AVStreamInWrap* obj = ObjectWrap::Unwrap<AVStreamInWrap>(args.Holder());
116127
if (!obj->me)
117128
return;
118-
std::string track = std::string(*String::Utf8Value(isolate, args[0]->ToString()));
119-
FrameDestination* param = ObjectWrap::Unwrap<FrameDestination>(args[1]->ToObject(Nan::GetCurrentContext()).ToLocalChecked());
129+
std::string track = getString(args[0]);
130+
FrameDestination* param = ObjectWrap::Unwrap<FrameDestination>(
131+
Nan::To<v8::Object>(args[1]).ToLocalChecked());
120132
owt_base::FrameDestination* dest = param->dest;
121133

122134
if (track == "audio")
@@ -133,8 +145,9 @@ void AVStreamInWrap::removeDestination(const FunctionCallbackInfo<Value>& args)
133145
AVStreamInWrap* obj = ObjectWrap::Unwrap<AVStreamInWrap>(args.Holder());
134146
if (!obj->me)
135147
return;
136-
std::string track = std::string(*String::Utf8Value(isolate, args[0]->ToString()));
137-
FrameDestination* param = ObjectWrap::Unwrap<FrameDestination>(args[1]->ToObject(Nan::GetCurrentContext()).ToLocalChecked());
148+
std::string track = getString(args[0]);
149+
FrameDestination* param = ObjectWrap::Unwrap<FrameDestination>(
150+
Nan::To<v8::Object>(args[1]).ToLocalChecked());
138151
owt_base::FrameDestination* dest = param->dest;
139152

140153
if (track == "audio")

source/agent/addons/avstreamLib/AVStreamInWrap.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
*/
1515
class AVStreamInWrap : public NodeEventedObjectWrap {
1616
public:
17-
static void Init(v8::Handle<v8::Object>);
18-
static void Init(v8::Handle<v8::Object>, v8::Handle<v8::Object>);
17+
static void Init(v8::Local<v8::Object>);
18+
static void Init(v8::Local<v8::Object>, v8::Local<v8::Object>);
1919
owt_base::FrameSource* me;
2020

2121
private:

0 commit comments

Comments
 (0)