mirror of
https://git.jami.net/savoirfairelinux/jami-daemon.git
synced 2025-08-07 22:02:12 +08:00
nodejs-interface: add presence signals
Change-Id: Ifb3d176bc37c4ecbc6ce9ff682e7721d55ea7e0f
This commit is contained in:
@ -56,6 +56,11 @@ Persistent<Function> accountProfileReceivedCb;
|
||||
Persistent<Function> profileReceivedCb;
|
||||
Persistent<Function> userSearchEndedCb;
|
||||
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::mutex pendingSignalsLock;
|
||||
@ -159,6 +164,16 @@ getPresistentCb(std::string_view signal)
|
||||
return &userSearchEndedCb;
|
||||
else if (signal == "DeviceRevocationEnded")
|
||||
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
|
||||
return nullptr;
|
||||
}
|
||||
@ -1163,3 +1178,78 @@ profileReceived(const std::string& accountId,
|
||||
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);
|
||||
}
|
@ -115,6 +115,7 @@ void init(const SWIGV8_VALUE& funcMap){
|
||||
using libjami::ConfigurationSignal;
|
||||
using libjami::CallSignal;
|
||||
using libjami::ConversationSignal;
|
||||
using libjami::PresenceSignal;
|
||||
using SharedCallback = std::shared_ptr<libjami::CallbackWrapperBase>;
|
||||
const std::map<std::string, SharedCallback> callEvHandlers = {
|
||||
exportable_callback<CallSignal::StateChange>(bind(&callStateChanged, _1, _2, _3, _4)),
|
||||
@ -171,6 +172,16 @@ void init(const SWIGV8_VALUE& funcMap){
|
||||
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)))
|
||||
return;
|
||||
|
||||
@ -178,6 +189,7 @@ void init(const SWIGV8_VALUE& funcMap){
|
||||
registerSignalHandlers(callEvHandlers);
|
||||
registerSignalHandlers(conversationHandlers);
|
||||
registerSignalHandlers(dataTransferEvHandlers);
|
||||
registerSignalHandlers(presenceEvHandlers);
|
||||
libjami::start();
|
||||
}
|
||||
%}
|
||||
|
Reference in New Issue
Block a user