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

nodejs: allow to receive log messages

Change-Id: I738d5dd3ef7ad4787a950e172172c31949b77a74
parent f8546636
No related branches found
No related tags found
No related merge requests found
......@@ -43,6 +43,7 @@ Persistent<Function> conferenceChangedCb;
Persistent<Function> conferenceRemovedCb;
Persistent<Function> onConferenceInfosUpdatedCb;
Persistent<Function> conversationPreferencesUpdatedCb;
Persistent<Function> messageSendCb;
std::queue<std::function<void()>> pendingSignals;
std::mutex pendingSignalsLock;
......@@ -120,6 +121,8 @@ getPresistentCb(std::string_view signal)
return &onConferenceInfosUpdatedCb;
else if (signal == "ConversationPreferencesUpdated")
return &conversationPreferencesUpdatedCb;
else if (signal == "LogMessage")
return &messageSendCb;
else
return nullptr;
}
......@@ -843,3 +846,18 @@ conversationPreferencesUpdated(const std::string& accountId,
});
uv_async_send(&signalAsync);
}
void
logMessage(const std::string& message)
{
std::lock_guard<std::mutex> lock(pendingSignalsLock);
pendingSignals.emplace([message]() {
Local<Function> func = Local<Function>::New(Isolate::GetCurrent(),
messageSendCb);
if (!func.IsEmpty()) {
SWIGV8_VALUE callback_args[] = {V8_STRING_NEW_LOCAL(message)};
func->Call(SWIGV8_CURRENT_CONTEXT(), SWIGV8_NULL(), 1, callback_args);
}
});
uv_async_send(&signalAsync);
}
......@@ -62,6 +62,7 @@ public:
virtual void hardwareEncodingChanged(bool /*state*/){}
virtual void audioMeter(const std::string& /*id*/, float /*level*/){}
virtual void messageSend(const std::string& /*message*/){}
};
%}
......@@ -260,5 +261,5 @@ public:
virtual void hardwareEncodingChanged(bool /*state*/){}
virtual void audioMeter(const std::string& /*id*/, float /*level*/){}
//virtual void messageSend(const std::string& /*message*/){}
virtual void messageSend(const std::string& /*message*/){}
};
......@@ -141,6 +141,7 @@ 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::MessageSend>(bind(&logMessage, _1 )),
//exportable_callback<ConfigurationSignal::ProfileReceived>(bind(&profileReceived, _1, _2, _3, _4 )),
//exportable_callback<ConfigurationSignal::IncomingTrustRequest>(bind(&incomingTrustRequest, _1, _2, _3, _4, _5 )),
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment