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

nodejs: update for new API

Change-Id: I1db1fc47a7a3164318dcaad6bfd51be006838bc0
parent 92fbb845
No related branches found
No related tags found
No related merge requests found
......@@ -23,8 +23,10 @@ Persistent<Function> nameRegistrationEndedCb;
Persistent<Function> knownDevicesChangedCb;
Persistent<Function> registeredNameFoundCb;
Persistent<Function> callStateChangedCb;
Persistent<Function> mediaChangeRequestedCb;
Persistent<Function> incomingMessageCb;
Persistent<Function> incomingCallCb;
Persistent<Function> incomingCallWithMediaCb;
Persistent<Function> conversationLoadedCb;
Persistent<Function> messageReceivedCb;
Persistent<Function> conversationRequestReceivedCb;
......@@ -73,10 +75,14 @@ getPresistentCb(std::string_view signal)
return &registeredNameFoundCb;
else if (signal == "CallStateChanged")
return &callStateChangedCb;
else if (signal == "MediaChangeRequested")
return &mediaChangeRequestedCb;
else if (signal == "IncomingMessage")
return &incomingMessageCb;
else if (signal == "IncomingCall")
return &incomingCallCb;
else if (signal == "IncomingCallWithMedia")
return &incomingCallWithMediaCb;
else if (signal == "ConversationLoaded")
return &conversationLoadedCb;
else if (signal == "MessageReceived")
......@@ -342,7 +348,12 @@ accountMessageStatusChanged(const std::string& account_id,
Local<Function> func = Local<Function>::New(Isolate::GetCurrent(),
accountMessageStatusChangedCb);
if (!func.IsEmpty()) {
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)};
Local<Value> callback_args[] = {
V8_STRING_NEW_LOCAL(account_id),
V8_STRING_NEW_LOCAL(message_id),
V8_STRING_NEW_LOCAL(peer),
SWIGV8_INTEGER_NEW(state)
};
func->Call(SWIGV8_CURRENT_CONTEXT(), SWIGV8_NULL(), 4, callback_args);
}
});
......@@ -408,7 +419,31 @@ callStateChanged(const std::string& callId, const std::string& state, int detail
pendingSignals.emplace([callId, state, detail_code]() {
Local<Function> func = Local<Function>::New(Isolate::GetCurrent(), callStateChangedCb);
if (!func.IsEmpty()) {
SWIGV8_VALUE callback_args[] = {V8_STRING_NEW_LOCAL(callId), V8_STRING_NEW_LOCAL(state), SWIGV8_INTEGER_NEW(detail_code)};
SWIGV8_VALUE callback_args[] = {
V8_STRING_NEW_LOCAL(callId),
V8_STRING_NEW_LOCAL(state),
SWIGV8_INTEGER_NEW(detail_code)
};
func->Call(SWIGV8_CURRENT_CONTEXT(), SWIGV8_NULL(), 3, callback_args);
}
});
uv_async_send(&signalAsync);
}
void
mediaChangeRequested(const std::string& accountId, const std::string& callId,
const std::vector<std::map<std::string, std::string>>& mediaList)
{
std::lock_guard<std::mutex> lock(pendingSignalsLock);
pendingSignals.emplace([accountId, callId, mediaList]() {
Local<Function> func = Local<Function>::New(Isolate::GetCurrent(), mediaChangeRequestedCb);
if (!func.IsEmpty()) {
SWIGV8_VALUE callback_args[] = {
V8_STRING_NEW_LOCAL(accountId),
V8_STRING_NEW_LOCAL(callId),
stringMapVecToJsMapArray(mediaList)
};
func->Call(SWIGV8_CURRENT_CONTEXT(), SWIGV8_NULL(), 3, callback_args);
}
});
......@@ -456,6 +491,27 @@ incomingCall(const std::string& accountId, const std::string& callId, const std:
uv_async_send(&signalAsync);
}
void
incomingCallWithMedia(const std::string& accountId, const std::string& callId, const std::string& from, const std::vector<std::map<std::string, std::string>>& mediaList)
{
std::lock_guard<std::mutex> lock(pendingSignalsLock);
pendingSignals.emplace([accountId, callId, from, mediaList]() {
Local<Function> func = Local<Function>::New(Isolate::GetCurrent(), incomingCallWithMediaCb);
if (!func.IsEmpty()) {
SWIGV8_VALUE callback_args[] = {
V8_STRING_NEW_LOCAL(accountId),
V8_STRING_NEW_LOCAL(callId),
V8_STRING_NEW_LOCAL(from),
stringMapVecToJsMapArray(mediaList)
};
func->Call(SWIGV8_CURRENT_CONTEXT(), SWIGV8_NULL(), 3, callback_args);
}
});
uv_async_send(&signalAsync);
}
/** Conversations */
void
......
......@@ -124,7 +124,7 @@ void init(const SWIGV8_VALUE& funcMap){
exportable_callback<CallSignal::IncomingMessage>(bind(&incomingMessage, _1, _2, _3)),
exportable_callback<CallSignal::IncomingCall>(bind(&incomingCall, _1, _2, _3)),
exportable_callback<CallSignal::IncomingCallWithMedia>(bind(&incomingCallWithMedia, _1, _2, _3, _4)),
exportable_callback<CallSignal::MediaChangeRequested>(bind(&mediaChangeRequested, _1, _2, _3)
exportable_callback<CallSignal::MediaChangeRequested>(bind(&mediaChangeRequested, _1, _2, _3))
};
const std::map<std::string, SharedCallback> configEvHandlers = {
......@@ -140,8 +140,8 @@ void init(const SWIGV8_VALUE& funcMap){
exportable_callback<ConfigurationSignal::KnownDevicesChanged>(bind(&knownDevicesChanged, _1, _2 )),
exportable_callback<ConfigurationSignal::IncomingAccountMessage>(bind(&incomingAccountMessage, _1, _2, _3, _4 )),
exportable_callback<ConfigurationSignal::AccountMessageStatusChanged>(bind(&accountMessageStatusChanged, _1, _2, _3, _4, _5 )),
exportable_callback<ConfigurationSignal::ProfileReceived>(bind(&profileReceived, _1, _2, _3, _4 )),
exportable_callback<ConfigurationSignal::IncomingTrustRequest>(bind(&incomingTrustRequest, _1, _2, _3, _4, _5 )),
//exportable_callback<ConfigurationSignal::ProfileReceived>(bind(&profileReceived, _1, _2, _3, _4 )),
//exportable_callback<ConfigurationSignal::IncomingTrustRequest>(bind(&incomingTrustRequest, _1, _2, _3, _4, _5 )),
};
const std::map<std::string, SharedCallback> conversationHandlers = {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment