Skip to content
Snippets Groups Projects
Commit 1495e22e authored by Adrien Béraud's avatar Adrien Béraud
Browse files

nodejs: update for Node v12

Change-Id: I54e1cf4dfc9aa95f25f90523bd2ae465cbf098f4
parent ea846611
No related branches found
No related tags found
No related merge requests found
include $(top_srcdir)/globals.mk
BUILT_SOURCES= \
ring_wrapper.cpp \
jami_wrapper.cpp \
build/Makefile \
build/Release/obj.target/dring.node
ring_wrapper.cpp: nodejs_interface.i configurationmanager.i managerimpl.i
$(SWIG) -v -c++ -javascript -node -o ring_wrapper.cpp nodejs_interface.i
jami_wrapper.cpp: nodejs_interface.i configurationmanager.i managerimpl.i
$(SWIG) -v -c++ -javascript -node -o jami_wrapper.cpp nodejs_interface.i
build/Makefile: ring_wrapper.cpp binding.gyp
node-gyp configure --target=1.6.2 --arch=x64
build/Makefile: jami_wrapper.cpp binding.gyp
node-gyp configure --target=v12.18.2 --arch=x64
build/Release/obj.target/dring.node: build/Makefile ring_wrapper.cpp callback.h
build/Release/obj.target/dring.node: build/Makefile jami_wrapper.cpp callback.h
node-gyp build
CLEANFILES= \
......
......@@ -2,9 +2,9 @@
"targets": [
{
"target_name": "dring",
"sources": [ "ring_wrapper.cpp" ],
"sources": [ "jami_wrapper.cpp" ],
'include_dirs': ['../../src/'],
'libraries': ['-L<(module_root_dir)/../../src/.libs/', '-lring'],
'libraries': ['-L<(module_root_dir)/../../src/.libs', '-lring'],
'cflags!': [ '-fno-exceptions' ],
'cflags_cc!': [ '-fno-exceptions' ]
}
......
#pragma once
#define V8_STRING_NEW(str) v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), str.data(), v8::String::kNormalString, str.size())
#define V8_STRING_NEW(str) v8::String::NewFromUtf8(v8::Isolate::GetCurrent(), str.data(), v8::NewStringType::kNormal, str.size())
#define V8_STRING_NEW_LOCAL(str) V8_STRING_NEW(str).ToLocalChecked()
#include <uv.h>
#include <queue>
......@@ -66,12 +67,12 @@ Persistent<Function>* getPresistentCb(const std::string &signal) {
void intVectToJsArray(const std::vector<uint8_t>& intVect, const Local<Array>& jsArray) {
for (unsigned int i = 0; i < intVect.size(); i++)
jsArray->Set(SWIGV8_INTEGER_NEW_UNS(i), SWIGV8_INTEGER_NEW(intVect[i]));
jsArray->Set(SWIGV8_CURRENT_CONTEXT(), SWIGV8_INTEGER_NEW_UNS(i), SWIGV8_INTEGER_NEW(intVect[i]));
}
void stringMapToJsMap(const std::map<std::string, std::string>& strmap, const Local<Object> &jsMap) {
for (auto& kvpair : strmap)
jsMap->Set(V8_STRING_NEW(std::get<0>(kvpair)), V8_STRING_NEW(std::get<1>(kvpair)));
jsMap->Set(SWIGV8_CURRENT_CONTEXT(), V8_STRING_NEW_LOCAL(std::get<0>(kvpair)), V8_STRING_NEW_LOCAL(std::get<1>(kvpair)));
}
void setCallback(const std::string& signal, Local<Function>& func) {
......@@ -87,12 +88,12 @@ void setCallback(const std::string& signal, Local<Function>& func) {
}
void parseCbMap(const Local<Value>& callbackMap) {
Local<Object> cbAssocArray = callbackMap->ToObject();
Local<Array> props = cbAssocArray->GetOwnPropertyNames();
Local<Object> cbAssocArray = callbackMap->ToObject(SWIGV8_CURRENT_CONTEXT()).ToLocalChecked();
Local<Array> props = cbAssocArray->GetOwnPropertyNames(SWIGV8_CURRENT_CONTEXT()).ToLocalChecked();
for (uint32_t i = 0; i < props->Length(); ++i) {
const Local<Value> key_local = props->Get(i);
std::string key = *String::Utf8Value(key_local);
Handle<Object> buffer = cbAssocArray->Get(V8_STRING_NEW(key))->ToObject();
const Local<Value> key_local = props->Get(SWIGV8_CURRENT_CONTEXT(), i).ToLocalChecked();
std::string key = *String::Utf8Value(Isolate::GetCurrent(), key_local);
Local<Object> buffer = cbAssocArray->Get(SWIGV8_CURRENT_CONTEXT(), V8_STRING_NEW_LOCAL(key)).ToLocalChecked()->ToObject(SWIGV8_CURRENT_CONTEXT()).ToLocalChecked();
Local<Function> func = Local<Function>::Cast(buffer);
setCallback(key, func);
}
......@@ -113,8 +114,12 @@ void registrationStateChanged(const std::string& account_id, const std::string&
pendingSignals.emplace([account_id, state, code, detail_str]() {
Local<Function> func = Local<Function>::New(Isolate::GetCurrent(), registrationStateChangedCb);
if (!func.IsEmpty()) {
Local<Value> callback_args[] = {V8_STRING_NEW(account_id), V8_STRING_NEW(state), SWIGV8_INTEGER_NEW(code), V8_STRING_NEW(detail_str)};
func->Call(SWIGV8_CURRENT_CONTEXT()->Global(), 4, callback_args);
Local<Value> callback_args[] = {
V8_STRING_NEW_LOCAL(account_id),
V8_STRING_NEW_LOCAL(state),
SWIGV8_INTEGER_NEW(code),
V8_STRING_NEW_LOCAL(detail_str)};
func->Call(SWIGV8_CURRENT_CONTEXT(), SWIGV8_NULL(), 4, callback_args);
}
});
......@@ -129,8 +134,8 @@ void volatileDetailsChanged(const std::string& account_id, const std::map<std::s
if (!func.IsEmpty()) {
Local<Object> jsMap = SWIGV8_OBJECT_NEW();
stringMapToJsMap(details, jsMap);
Local<Value> callback_args[] = {V8_STRING_NEW(account_id), jsMap};
func->Call(SWIGV8_CURRENT_CONTEXT()->Global(), 2, callback_args);
Local<Value> callback_args[] = {V8_STRING_NEW_LOCAL(account_id), jsMap};
func->Call(SWIGV8_CURRENT_CONTEXT(), SWIGV8_NULL(), 2, callback_args);
}
});
......@@ -144,7 +149,7 @@ void accountsChanged() {
Local<Function> func = Local<Function>::New(Isolate::GetCurrent(), accountsChangedCb);
if (!func.IsEmpty()) {
Local<Value> callback_args[] = {};
func->Call(SWIGV8_CURRENT_CONTEXT()->Global(), 0, callback_args);
func->Call(SWIGV8_CURRENT_CONTEXT(), SWIGV8_NULL(), 0, callback_args);
}
});
......@@ -157,8 +162,8 @@ void contactAdded(const std::string& account_id, const std::string& uri, bool co
pendingSignals.emplace([account_id, uri, confirmed]() {
Local<Function> func = Local<Function>::New(Isolate::GetCurrent(), contactAddedCb);
if (!func.IsEmpty()) {
Local<Value> callback_args[] = {V8_STRING_NEW(account_id), V8_STRING_NEW(uri), SWIGV8_BOOLEAN_NEW(confirmed)};
func->Call(SWIGV8_CURRENT_CONTEXT()->Global(), 3, callback_args);
Local<Value> callback_args[] = {V8_STRING_NEW_LOCAL(account_id), V8_STRING_NEW_LOCAL(uri), SWIGV8_BOOLEAN_NEW(confirmed)};
func->Call(SWIGV8_CURRENT_CONTEXT(), SWIGV8_NULL(), 3, callback_args);
}
});
......@@ -171,8 +176,8 @@ void contactRemoved(const std::string& account_id, const std::string& uri, bool
pendingSignals.emplace([account_id, uri, banned]() {
Local<Function> func = Local<Function>::New(Isolate::GetCurrent(), contactRemovedCb);
if (!func.IsEmpty()) {
Local<Value> callback_args[] = {V8_STRING_NEW(account_id), V8_STRING_NEW(uri), SWIGV8_BOOLEAN_NEW(banned)};
func->Call(SWIGV8_CURRENT_CONTEXT()->Global(), 3, callback_args);
Local<Value> callback_args[] = {V8_STRING_NEW_LOCAL(account_id), V8_STRING_NEW_LOCAL(uri), SWIGV8_BOOLEAN_NEW(banned)};
func->Call(SWIGV8_CURRENT_CONTEXT(), SWIGV8_NULL(), 3, callback_args);
}
});
......@@ -185,8 +190,8 @@ void exportOnRingEnded(const std::string& account_id, int state, const std::stri
pendingSignals.emplace([account_id, state, pin]() {
Local<Function> func = Local<Function>::New(Isolate::GetCurrent(), exportOnRingEndedCb);
if (!func.IsEmpty()) {
Local<Value> callback_args[] = {V8_STRING_NEW(account_id), SWIGV8_INTEGER_NEW(state), V8_STRING_NEW(pin)};
func->Call(SWIGV8_CURRENT_CONTEXT()->Global(), 3, callback_args);
Local<Value> callback_args[] = {V8_STRING_NEW_LOCAL(account_id), SWIGV8_INTEGER_NEW(state), V8_STRING_NEW_LOCAL(pin)};
func->Call(SWIGV8_CURRENT_CONTEXT(), SWIGV8_NULL(), 3, callback_args);
}
});
......@@ -199,8 +204,8 @@ void nameRegistrationEnded(const std::string& account_id, int state, const std::
pendingSignals.emplace([account_id, state, name]() {
Local<Function> func = Local<Function>::New(Isolate::GetCurrent(), nameRegistrationEndedCb);
if (!func.IsEmpty()) {
Local<Value> callback_args[] = {V8_STRING_NEW(account_id), SWIGV8_INTEGER_NEW(state), V8_STRING_NEW(name)};
func->Call(SWIGV8_CURRENT_CONTEXT()->Global(), 3, callback_args);
Local<Value> callback_args[] = {V8_STRING_NEW_LOCAL(account_id), SWIGV8_INTEGER_NEW(state), V8_STRING_NEW_LOCAL(name)};
func->Call(SWIGV8_CURRENT_CONTEXT(), SWIGV8_NULL(), 3, callback_args);
}
});
......@@ -213,8 +218,8 @@ void registeredNameFound(const std::string& account_id, int state, const std::st
pendingSignals.emplace([account_id, state, address, name]() {
Local<Function> func = Local<Function>::New(Isolate::GetCurrent(), registeredNameFoundCb);
if (!func.IsEmpty()) {
Local<Value> callback_args[] = {V8_STRING_NEW(account_id), SWIGV8_INTEGER_NEW(state), V8_STRING_NEW(address), V8_STRING_NEW(name)};
func->Call(SWIGV8_CURRENT_CONTEXT()->Global(), 4, callback_args);
Local<Value> callback_args[] = {V8_STRING_NEW_LOCAL(account_id), SWIGV8_INTEGER_NEW(state), V8_STRING_NEW_LOCAL(address), V8_STRING_NEW_LOCAL(name)};
func->Call(SWIGV8_CURRENT_CONTEXT(), SWIGV8_NULL(), 4, callback_args);
}
});
......@@ -227,8 +232,8 @@ void accountMessageStatusChanged(const std::string& account_id, uint64_t message
pendingSignals.emplace([account_id, message_id, to, state]() {
Local<Function> func = Local<Function>::New(Isolate::GetCurrent(), accountMessageStatusChangedCb);
if (!func.IsEmpty()) {
Local<Value> callback_args[] = {V8_STRING_NEW(account_id), SWIGV8_INTEGER_NEW_UNS(message_id), V8_STRING_NEW(to), SWIGV8_INTEGER_NEW(state)};
func->Call(SWIGV8_CURRENT_CONTEXT()->Global(), 4, callback_args);
Local<Value> callback_args[] = {V8_STRING_NEW_LOCAL(account_id), SWIGV8_INTEGER_NEW_UNS(message_id), V8_STRING_NEW_LOCAL(to), SWIGV8_INTEGER_NEW(state)};
func->Call(SWIGV8_CURRENT_CONTEXT(), SWIGV8_NULL(), 4, callback_args);
}
});
......@@ -243,8 +248,8 @@ void incomingAccountMessage(const std::string& account_id, const std::string& me
if (!func.IsEmpty()) {
Local<Object> jsMap = SWIGV8_OBJECT_NEW();
stringMapToJsMap(payloads, jsMap);
Local<Value> callback_args[] = {V8_STRING_NEW(account_id), V8_STRING_NEW(from), jsMap};
func->Call(SWIGV8_CURRENT_CONTEXT()->Global(), 3, callback_args);
Local<Value> callback_args[] = {V8_STRING_NEW_LOCAL(account_id), V8_STRING_NEW_LOCAL(from), jsMap};
func->Call(SWIGV8_CURRENT_CONTEXT(), SWIGV8_NULL(), 3, callback_args);
}
});
......@@ -259,8 +264,8 @@ void knownDevicesChanged(const std::string& account_id, const std::map<std::stri
if (!func.IsEmpty()) {
Local<Object> jsMap = SWIGV8_OBJECT_NEW();
stringMapToJsMap(devices, jsMap);
Local<Value> callback_args[] = {V8_STRING_NEW(account_id), jsMap};
func->Call(SWIGV8_CURRENT_CONTEXT()->Global(), 2, callback_args);
Local<Value> callback_args[] = {V8_STRING_NEW_LOCAL(account_id), jsMap};
func->Call(SWIGV8_CURRENT_CONTEXT(), SWIGV8_NULL(), 2, callback_args);
}
});
......@@ -276,8 +281,8 @@ void incomingTrustRequest(const std::string& account_id, const std::string& from
if (!func.IsEmpty()) {
Local<Array> jsArray = SWIGV8_ARRAY_NEW(payload.size());
intVectToJsArray(payload, jsArray);
Local<Value> callback_args[] = {V8_STRING_NEW(account_id), V8_STRING_NEW(from), jsArray, SWIGV8_NUMBER_NEW(received)};
func->Call(SWIGV8_CURRENT_CONTEXT()->Global(), 4, callback_args);
Local<Value> callback_args[] = {V8_STRING_NEW_LOCAL(account_id), V8_STRING_NEW_LOCAL(from), jsArray, SWIGV8_NUMBER_NEW(received)};
func->Call(SWIGV8_CURRENT_CONTEXT(), SWIGV8_NULL(), 4, callback_args);
}
});
uv_async_send(&signalAsync);
......@@ -289,8 +294,8 @@ void callStateChanged(const std::string& call_id, const std::string& state, int
pendingSignals.emplace([call_id, state, detail_code]() {
Local<Function> func = Local<Function>::New(Isolate::GetCurrent(), callStateChangedCb);
if (!func.IsEmpty()) {
Local<Value> callback_args[] = {V8_STRING_NEW(call_id), V8_STRING_NEW(state), SWIGV8_INTEGER_NEW(detail_code)};
func->Call(SWIGV8_CURRENT_CONTEXT()->Global(), 3, callback_args);
Local<Value> callback_args[] = {V8_STRING_NEW_LOCAL(call_id), V8_STRING_NEW_LOCAL(state), SWIGV8_INTEGER_NEW(detail_code)};
func->Call(SWIGV8_CURRENT_CONTEXT(), SWIGV8_NULL(), 3, callback_args);
}
});
......@@ -305,8 +310,8 @@ void incomingMessage(const std::string& id, const std::string& from, const std::
if (!func.IsEmpty()) {
Local<Object> jsMap = SWIGV8_OBJECT_NEW();
stringMapToJsMap(messages, jsMap);
Local<Value> callback_args[] = {V8_STRING_NEW(id), V8_STRING_NEW(from), jsMap};
func->Call(SWIGV8_CURRENT_CONTEXT()->Global(), 4, callback_args);
Local<Value> callback_args[] = {V8_STRING_NEW_LOCAL(id), V8_STRING_NEW_LOCAL(from), jsMap};
func->Call(SWIGV8_CURRENT_CONTEXT(), SWIGV8_NULL(), 4, callback_args);
}
});
......@@ -319,8 +324,8 @@ void incomingCall(const std::string& account_id, const std::string& call_id, con
pendingSignals.emplace([account_id, call_id, from]() {
Local<Function> func = Local<Function>::New(Isolate::GetCurrent(), incomingCallCb);
if (!func.IsEmpty()) {
Local<Value> callback_args[] = {V8_STRING_NEW(account_id), V8_STRING_NEW(call_id), V8_STRING_NEW(from)};
func->Call(SWIGV8_CURRENT_CONTEXT()->Global(), 3, callback_args);
Local<Value> callback_args[] = {V8_STRING_NEW_LOCAL(account_id), V8_STRING_NEW_LOCAL(call_id), V8_STRING_NEW_LOCAL(from)};
func->Call(SWIGV8_CURRENT_CONTEXT(), SWIGV8_NULL(), 3, callback_args);
}
});
......
......@@ -21,7 +21,7 @@
class JamiDaemon {
constructor(callbackMap) {
if(callbackMap){
if (callbackMap){
this.dring = require("./build/Release/dring.node");
this.dring.init(callbackMap);
}
......
......@@ -5,7 +5,7 @@ nodejs_wrapper_target = custom_target('nodejs.wrapper',
)
nodejs_makefile_target = custom_target('nodejs.makefile',
command: [prognodegyp, 'configure', '--target=1.6.2', '--arch=x64'],
command: [prognodegyp, 'configure', '--target=v12.18.2', '--arch=x64'],
output: 'build/Makefile',
depends: nodejs_wrapper_target
)
......
......@@ -20,7 +20,7 @@
*/
/* File : nodejs_interface.i */
%module (directors="1") Ringservice
%module (directors="1") JamiService
#define SWIG_JAVA_ATTACH_CURRENT_THREAD_AS_DAEMON
%include "typemaps.i"
......@@ -88,9 +88,18 @@ namespace std {
}
//typemap for handling map of functions
%typemap(in) const v8::Handle<v8::Value> {
%typemap(in) SWIGV8_VALUE {
$1 = $input;
}
%typemap(in) const SWIGV8_VALUE {
$1 = $input;
}
%typemap(varin) SWIGV8_VALUE {
$result = $input;
}
%typemap(varin) const SWIGV8_VALUE {
$result = $input;
}
%inline %{
......@@ -98,7 +107,7 @@ namespace std {
* that are not declared elsewhere in the c++ code
*/
void init(const v8::Handle<v8::Value> &funcMap){
void init(const SWIGV8_VALUE& funcMap){
parseCbMap(funcMap);
uv_async_init(uv_default_loop(), &signalAsync, handlePendingSignals);
......@@ -129,7 +138,7 @@ void init(const v8::Handle<v8::Value> &funcMap){
exportable_callback<ConfigurationSignal::IncomingTrustRequest>(bind(&incomingTrustRequest, _1, _2, _3, _4 )),
};
if (!DRing::init(static_cast<DRing::InitFlag>(DRing::DRING_FLAG_DEBUG)))
if (!DRing::init(static_cast<DRing::InitFlag>(DRing::DRING_FLAG_DEBUG | DRing::DRING_FLAG_CONSOLE_LOG)))
return;
registerSignalHandlers(configEvHandlers);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment