99
1010using 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+
1217Persistent<Function> AVStreamInWrap::constructor;
1318AVStreamInWrap::AVStreamInWrap ()
1419{
1520}
1621AVStreamInWrap::~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
5259void 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" )
0 commit comments