Skip to content
Snippets Groups Projects
Commit 912aa59a authored by Léopold Chappuis's avatar Léopold Chappuis Committed by Adrien Béraud
Browse files

nodejs-interface: add presence signals

Change-Id: Ifb3d176bc37c4ecbc6ce9ff682e7721d55ea7e0f
parent 35ccafac
No related branches found
No related tags found
No related merge requests found
...@@ -56,6 +56,11 @@ Persistent<Function> accountProfileReceivedCb; ...@@ -56,6 +56,11 @@ Persistent<Function> accountProfileReceivedCb;
Persistent<Function> profileReceivedCb; Persistent<Function> profileReceivedCb;
Persistent<Function> userSearchEndedCb; Persistent<Function> userSearchEndedCb;
Persistent<Function> deviceRevocationEndedCb; Persistent<Function> deviceRevocationEndedCb;
Persistent<Function> subscriptionStateChangedCb;
Persistent<Function> nearbyPeerNotificationCb;
Persistent<Function> newBuddyNotificationCb;
Persistent<Function> serverErrorCb;
Persistent<Function> newServerSubscriptionRequestCb;
std::queue<std::function<void()>> pendingSignals; std::queue<std::function<void()>> pendingSignals;
std::mutex pendingSignalsLock; std::mutex pendingSignalsLock;
...@@ -159,6 +164,16 @@ getPresistentCb(std::string_view signal) ...@@ -159,6 +164,16 @@ getPresistentCb(std::string_view signal)
return &userSearchEndedCb; return &userSearchEndedCb;
else if (signal == "DeviceRevocationEnded") else if (signal == "DeviceRevocationEnded")
return &deviceRevocationEndedCb; return &deviceRevocationEndedCb;
else if (signal == "SubscriptionStateChanged")
return &subscriptionStateChangedCb;
else if (signal == "NearbyPeerNotification")
return &nearbyPeerNotificationCb;
else if (signal == "NewBuddyNotification")
return &newBuddyNotificationCb;
else if (signal == "ServerError")
return &serverErrorCb;
else if (signal == "NewServerSubscriptionRequest")
return &newServerSubscriptionRequestCb;
else else
return nullptr; return nullptr;
} }
...@@ -1163,3 +1178,78 @@ profileReceived(const std::string& accountId, ...@@ -1163,3 +1178,78 @@ profileReceived(const std::string& accountId,
uv_async_send(&signalAsync); uv_async_send(&signalAsync);
} }
void
subscriptionStateChanged(const std::string& accountId, const std::string& buddy_uri, int state)
{
std::lock_guard lock(pendingSignalsLock);
pendingSignals.emplace([accountId, buddy_uri, state]() {
Local<Function> func = Local<Function>::New(Isolate::GetCurrent(), subscriptionStateChangedCb);
if (!func.IsEmpty()) {
SWIGV8_VALUE callback_args[] = {V8_STRING_NEW_LOCAL(accountId),
V8_STRING_NEW_LOCAL(buddy_uri),
SWIGV8_INTEGER_NEW(state)};
func->Call(SWIGV8_CURRENT_CONTEXT(), SWIGV8_NULL(), 3, callback_args);
}
});
uv_async_send(&signalAsync);
}
void
nearbyPeerNotification(const std::string& accountId, const std::string& buddy_uri, int state, const std::string& displayName){
std::lock_guard lock(pendingSignalsLock);
pendingSignals.emplace([accountId, buddy_uri, state, displayName]() {
Local<Function> func = Local<Function>::New(Isolate::GetCurrent(), nearbyPeerNotificationCb);
if (!func.IsEmpty()) {
SWIGV8_VALUE callback_args[] = {V8_STRING_NEW_LOCAL(accountId),
V8_STRING_NEW_LOCAL(buddy_uri),
SWIGV8_INTEGER_NEW(state),
V8_STRING_NEW_LOCAL(displayName)};
func->Call(SWIGV8_CURRENT_CONTEXT(), SWIGV8_NULL(), 4, callback_args);
}
});
uv_async_send(&signalAsync);
}
void
newBuddyNotification(const std::string& accountId, const std::string& buddy_uri, int status, const std::string& line_status){
std::lock_guard lock(pendingSignalsLock);
pendingSignals.emplace([accountId, buddy_uri, status, line_status]() {
Local<Function> func = Local<Function>::New(Isolate::GetCurrent(), newBuddyNotificationCb);
if (!func.IsEmpty()) {
SWIGV8_VALUE callback_args[] = {V8_STRING_NEW_LOCAL(accountId),
V8_STRING_NEW_LOCAL(buddy_uri),
SWIGV8_INTEGER_NEW(status),
V8_STRING_NEW_LOCAL(line_status)};
func->Call(SWIGV8_CURRENT_CONTEXT(), SWIGV8_NULL(), 4, callback_args);
}
});
uv_async_send(&signalAsync);
}
void
newServerSubscriptionRequest(const std::string& remote){
std::lock_guard lock(pendingSignalsLock);
pendingSignals.emplace([remote]() {
Local<Function> func = Local<Function>::New(Isolate::GetCurrent(), newServerSubscriptionRequestCb);
if (!func.IsEmpty()) {
SWIGV8_VALUE callback_args[] = {V8_STRING_NEW_LOCAL(remote)};
func->Call(SWIGV8_CURRENT_CONTEXT(), SWIGV8_NULL(), 1, callback_args);
}
});
uv_async_send(&signalAsync);
}
void
serverError(const std::string& accountId, const std::string& error, const std::string& msg){
std::lock_guard lock(pendingSignalsLock);
pendingSignals.emplace([accountId, error, msg]() {
Local<Function> func = Local<Function>::New(Isolate::GetCurrent(), serverErrorCb);
if (!func.IsEmpty()) {
SWIGV8_VALUE callback_args[] = {V8_STRING_NEW_LOCAL(accountId),
V8_STRING_NEW_LOCAL(error),
V8_STRING_NEW_LOCAL(msg)};
func->Call(SWIGV8_CURRENT_CONTEXT(), SWIGV8_NULL(), 3, callback_args);
}
});
uv_async_send(&signalAsync);
}
\ No newline at end of file
...@@ -115,6 +115,7 @@ void init(const SWIGV8_VALUE& funcMap){ ...@@ -115,6 +115,7 @@ void init(const SWIGV8_VALUE& funcMap){
using libjami::ConfigurationSignal; using libjami::ConfigurationSignal;
using libjami::CallSignal; using libjami::CallSignal;
using libjami::ConversationSignal; using libjami::ConversationSignal;
using libjami::PresenceSignal;
using SharedCallback = std::shared_ptr<libjami::CallbackWrapperBase>; using SharedCallback = std::shared_ptr<libjami::CallbackWrapperBase>;
const std::map<std::string, SharedCallback> callEvHandlers = { const std::map<std::string, SharedCallback> callEvHandlers = {
exportable_callback<CallSignal::StateChange>(bind(&callStateChanged, _1, _2, _3, _4)), exportable_callback<CallSignal::StateChange>(bind(&callStateChanged, _1, _2, _3, _4)),
...@@ -171,6 +172,16 @@ void init(const SWIGV8_VALUE& funcMap){ ...@@ -171,6 +172,16 @@ void init(const SWIGV8_VALUE& funcMap){
exportable_callback<ConversationSignal::ConversationPreferencesUpdated>(bind(&conversationPreferencesUpdated, _1, _2, _3)) exportable_callback<ConversationSignal::ConversationPreferencesUpdated>(bind(&conversationPreferencesUpdated, _1, _2, _3))
}; };
// Presence event handlers
const std::map<std::string, SharedCallback> presenceEvHandlers = {
exportable_callback<PresenceSignal::NewServerSubscriptionRequest>(bind(&newServerSubscriptionRequest, _1 )),
exportable_callback<PresenceSignal::ServerError>(bind(&serverError, _1, _2, _3 )),
exportable_callback<PresenceSignal::NewBuddyNotification>(bind(&newBuddyNotification, _1, _2, _3, _4 )),
exportable_callback<PresenceSignal::NearbyPeerNotification>(bind(&nearbyPeerNotification, _1, _2, _3, _4)),
exportable_callback<PresenceSignal::SubscriptionStateChanged>(bind(&subscriptionStateChanged, _1, _2, _3 ))
};
if (!libjami::init(static_cast<libjami::InitFlag>(libjami::LIBJAMI_FLAG_DEBUG))) if (!libjami::init(static_cast<libjami::InitFlag>(libjami::LIBJAMI_FLAG_DEBUG)))
return; return;
...@@ -178,6 +189,7 @@ void init(const SWIGV8_VALUE& funcMap){ ...@@ -178,6 +189,7 @@ void init(const SWIGV8_VALUE& funcMap){
registerSignalHandlers(callEvHandlers); registerSignalHandlers(callEvHandlers);
registerSignalHandlers(conversationHandlers); registerSignalHandlers(conversationHandlers);
registerSignalHandlers(dataTransferEvHandlers); registerSignalHandlers(dataTransferEvHandlers);
registerSignalHandlers(presenceEvHandlers);
libjami::start(); libjami::start();
} }
%} %}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment