9
9
10
10
using namespace v8 ;
11
11
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
+
12
17
Persistent<Function> AVStreamInWrap::constructor;
13
18
AVStreamInWrap::AVStreamInWrap ()
14
19
{
15
20
}
16
21
AVStreamInWrap::~AVStreamInWrap () {}
17
22
18
- void AVStreamInWrap::Init (Handle <Object> exports, Handle <Object> module )
23
+ void AVStreamInWrap::Init (Local <Object> exports, Local <Object> module )
19
24
{
20
25
Isolate* isolate = exports->GetIsolate ();
21
26
// Prepare constructor template
22
27
Local<FunctionTemplate> tpl = FunctionTemplate::New (isolate, New);
23
- tpl->SetClassName (String::NewFromUtf8 (isolate, " AVStreamIn" ));
28
+ tpl->SetClassName (Nan::New ( " AVStreamIn" ). ToLocalChecked ( ));
24
29
tpl->InstanceTemplate ()->SetInternalFieldCount (1 );
25
30
// Prototype
26
31
SETUP_EVENTED_PROTOTYPE_METHODS (tpl);
27
32
NODE_SET_PROTOTYPE_METHOD (tpl, " close" , close);
28
33
NODE_SET_PROTOTYPE_METHOD (tpl, " addDestination" , addDestination);
29
34
NODE_SET_PROTOTYPE_METHOD (tpl, " removeDestination" , removeDestination);
30
35
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 ());
33
39
}
34
40
35
- void AVStreamInWrap::Init (Handle <Object> exports)
41
+ void AVStreamInWrap::Init (Local <Object> exports)
36
42
{
37
43
Isolate* isolate = exports->GetIsolate ();
38
44
// Prepare constructor template
39
45
Local<FunctionTemplate> tpl = FunctionTemplate::New (isolate, New);
40
- tpl->SetClassName (String::NewFromUtf8 (isolate, " AVStreamIn" ));
46
+ tpl->SetClassName (Nan::New ( " AVStreamIn" ). ToLocalChecked ( ));
41
47
tpl->InstanceTemplate ()->SetInternalFieldCount (1 );
42
48
// Prototype
43
49
SETUP_EVENTED_PROTOTYPE_METHODS (tpl);
44
50
NODE_SET_PROTOTYPE_METHOD (tpl, " close" , close);
45
51
NODE_SET_PROTOTYPE_METHOD (tpl, " addDestination" , addDestination);
46
52
NODE_SET_PROTOTYPE_METHOD (tpl, " removeDestination" , removeDestination);
47
53
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 ());
50
57
}
51
58
52
59
void AVStreamInWrap::New (const FunctionCallbackInfo<Value>& args)
@@ -55,41 +62,45 @@ void AVStreamInWrap::New(const FunctionCallbackInfo<Value>& args)
55
62
HandleScope scope (isolate);
56
63
57
64
if (args.Length () == 0 || !args[0 ]->IsObject ()) {
58
- isolate-> ThrowException ( Exception::TypeError ( String::NewFromUtf8 (isolate, " Wrong arguments" )) );
65
+ Nan::ThrowError ( " Wrong arguments" );
59
66
return ;
60
67
}
61
68
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 ( );
67
74
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 ());
79
87
80
88
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 ());
82
91
if (type.compare (" streaming" ) == 0 )
83
92
obj->me = new owt_base::LiveStreamIn (param, obj);
84
93
else if (type.compare (" file" ) == 0 )
85
94
obj->me = new owt_base::MediaFileIn ();
86
95
else {
87
- isolate-> ThrowException ( Exception::TypeError ( String::NewFromUtf8 (isolate, " Unsupported AVStreamIn type" )) );
96
+ Nan::ThrowError ( " Unsupported AVStreamIn type" );
88
97
return ;
89
98
}
90
99
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
+ }
93
104
94
105
obj->Wrap (args.This ());
95
106
args.GetReturnValue ().Set (args.This ());
@@ -115,8 +126,9 @@ void AVStreamInWrap::addDestination(const FunctionCallbackInfo<Value>& args)
115
126
AVStreamInWrap* obj = ObjectWrap::Unwrap<AVStreamInWrap>(args.Holder ());
116
127
if (!obj->me )
117
128
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 ());
120
132
owt_base::FrameDestination* dest = param->dest ;
121
133
122
134
if (track == " audio" )
@@ -133,8 +145,9 @@ void AVStreamInWrap::removeDestination(const FunctionCallbackInfo<Value>& args)
133
145
AVStreamInWrap* obj = ObjectWrap::Unwrap<AVStreamInWrap>(args.Holder ());
134
146
if (!obj->me )
135
147
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 ());
138
151
owt_base::FrameDestination* dest = param->dest ;
139
152
140
153
if (track == " audio" )
0 commit comments