Skip to content

Commit

Permalink
webview: add initial WebView support to the daemon
Browse files Browse the repository at this point in the history
Change-Id: Id6967f8fd0976caae81e4c951d0d5dc9901b23d3
  • Loading branch information
Tobias Hildebrandt committed Jun 27, 2022
1 parent b58869b commit f773e24
Show file tree
Hide file tree
Showing 18 changed files with 582 additions and 3 deletions.
61 changes: 61 additions & 0 deletions bin/dbus/cx.ring.Ring.PluginManagerInterface.xml
Original file line number Diff line number Diff line change
Expand Up @@ -198,5 +198,66 @@
</arg>
</method>

<method name="sendWebViewMessage" tp:name-for-bindings="sendWebViewMessage">
<tp:added version="13.2.0"/>
<tp:docstring>
Called by the a client's webview to send a message to the plugin
</tp:docstring>
<arg type="s" name="pluginId" direction="in">
</arg>
<arg type="s" name="webViewId" direction="in">
</arg>
<arg type="s" name="messageId" direction="in">
</arg>
<arg type="s" name="payload" direction="in">
</arg>
</method>

<method name="sendWebViewAttach" tp:name-for-bindings="sendWebViewAttach">
<tp:added version="13.2.0"/>
<tp:docstring>
Called by the a client's webview to notify the plugin that a webview has been created.
Returns a relative path to an HTML file inside the plugin's datapath.
</tp:docstring>
<arg type="s" name="pluginId" direction="in">
</arg>
<arg type="s" name="accountId" direction="in">
</arg>
<arg type="s" name="webViewId" direction="in">
</arg>
<arg type="s" name="action" direction="in">
</arg>
<annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QString"/>
<arg type="s" name="response" direction="out">
</arg>
</method>

<method name="sendWebViewDetach" tp:name-for-bindings="sendWebViewDetach">
<tp:added version="13.2.0"/>
<tp:docstring>
Called by the a client's webview to notify the plugin that a webview has been destroyed
</tp:docstring>
<arg type="s" name="pluginId" direction="in">
</arg>
<arg type="s" name="webViewId" direction="in">
</arg>
</method>

<!-- SIGNALS !-->
<signal name="webViewMessageReceived" tp:name-for-bindings="webViewMessageReceived">
<tp:added version="13.2.0"/>
<tp:docstring>
This signal is emitted when a plugin sends a message up to a webview
</tp:docstring>
<arg type="s" name="pluginId">
</arg>
<arg type="s" name="webViewId">
</arg>
<arg type="s" name="messageId">
</arg>
<arg type="s" name="payload">
</arg>
</signal>

</interface>
</node>
15 changes: 15 additions & 0 deletions bin/dbus/dbusclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ DBusClient::initLibrary(int flags)
auto videoM = videoManager_.get();
#endif

#ifdef ENABLE_PLUGIN
auto pluginM = pluginManagerInterface_.get();
#endif

// Call event handlers
const std::map<std::string, SharedCallback> callEvHandlers
= {exportable_callback<CallSignal::StateChange>(
Expand Down Expand Up @@ -322,6 +326,14 @@ DBusClient::initLibrary(int flags)
};
#endif

#ifdef ENABLE_PLUGIN
// Plugin event handlers
const std::map<std::string, SharedCallback> pluginEvHandlers = {
exportable_callback<DRing::PluginSignal::WebViewMessageReceived>(
bind(&DBusPluginManagerInterface::webViewMessageReceived, pluginM, _1, _2, _3, _4)),
};
#endif

if (!DRing::init(static_cast<DRing::InitFlag>(flags)))
return -1;

Expand All @@ -334,6 +346,9 @@ DBusClient::initLibrary(int flags)
#ifdef ENABLE_VIDEO
DRing::registerSignalHandlers(videoEvHandlers);
#endif
#ifdef ENABLE_PLUGIN
DRing::registerSignalHandlers(pluginEvHandlers);
#endif

if (!DRing::start())
return -1;
Expand Down
26 changes: 25 additions & 1 deletion bin/dbus/dbuspluginmanagerinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ DBusPluginManagerInterface::getChatHandlers() -> decltype(DRing::getChatHandlers
{
return DRing::getChatHandlers();
}

void
DBusPluginManagerInterface::toggleCallMediaHandler(const std::string& mediaHandlerId,
const std::string& callId,
Expand Down Expand Up @@ -162,3 +161,28 @@ DBusPluginManagerInterface::setPluginsEnabled(const bool& state)
{
DRing::setPluginsEnabled(state);
}

void
DBusPluginManagerInterface::sendWebViewMessage(const std::string& pluginId,
const std::string& webViewId,
const std::string& messageId,
const std::string& payload)
{
DRing::sendWebViewAttach(pluginId, webViewId, messageId, payload);
}

std::string
DBusPluginManagerInterface::sendWebViewAttach(const std::string& pluginId,
const std::string& accountId,
const std::string& webViewId,
const std::string& action)
{
return DRing::sendWebViewAttach(pluginId, accountId, webViewId, action);
}

void
DBusPluginManagerInterface::sendWebViewDetach(const std::string& pluginId,
const std::string& webViewId)
{
DRing::sendWebViewDetach(pluginId, webViewId);
}
12 changes: 12 additions & 0 deletions bin/dbus/dbuspluginmanagerinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,16 @@ class DRING_PUBLIC DBusPluginManagerInterface

bool getPluginsEnabled();
void setPluginsEnabled(const bool& state);

void sendWebViewMessage(const std::string& pluginId,
const std::string& webViewId,
const std::string& messageId,
const std::string& payload);

std::string sendWebViewAttach(const std::string& pluginId,
const std::string& accountId,
const std::string& webViewId,
const std::string& action);

void sendWebViewDetach(const std::string& pluginId, const std::string& webViewId);
};
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ dnl Jami - configure.ac

dnl Process this file with autoconf to produce a configure script.
AC_PREREQ([2.69])
AC_INIT([Jami Daemon],[13.1.0],[jami@gnu.org],[jami])
AC_INIT([Jami Daemon],[13.2.0],[jami@gnu.org],[jami])

dnl Clear the implicit flags that default to '-g -O2', otherwise they
dnl take precedence over the values we set via the
Expand Down
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
project('jami-daemon', ['c', 'cpp'],
version: '13.1.0',
version: '13.2.0',
license: 'GPL3+',
default_options: ['cpp_std=gnu++17', 'buildtype=debugoptimized'],
meson_version:'>= 0.56'
Expand Down
33 changes: 33 additions & 0 deletions src/client/plugin_manager_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,37 @@ setPluginsEnabled(bool state)
}
jami::Manager::instance().saveConfig();
}

void
sendWebViewMessage(const std::string& pluginId,
const std::string& webViewId,
const std::string& messageId,
const std::string& payload)
{
jami::Manager::instance()
.getJamiPluginManager()
.getWebViewServicesManager()
.sendWebViewMessage(pluginId, webViewId, messageId, payload);
}

std::string
sendWebViewAttach(const std::string& pluginId,
const std::string& accountId,
const std::string& webViewId,
const std::string& action)
{
return jami::Manager::instance()
.getJamiPluginManager()
.getWebViewServicesManager()
.sendWebViewAttach(pluginId, accountId, webViewId, action);
}

void
sendWebViewDetach(const std::string& pluginId, const std::string& webViewId)
{
jami::Manager::instance()
.getJamiPluginManager()
.getWebViewServicesManager()
.sendWebViewDetach(pluginId, webViewId);
}
} // namespace DRing
4 changes: 4 additions & 0 deletions src/client/ring_signal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ getSignalHandlers()
exported_callback<DRing::ConversationSignal::ConversationRemoved>(),
exported_callback<DRing::ConversationSignal::ConversationMemberEvent>(),
exported_callback<DRing::ConversationSignal::OnConversationError>(),

#ifdef ENABLE_PLUGIN
exported_callback<DRing::PluginSignal::WebViewMessageReceived>(),
#endif
};

return handlers;
Expand Down
4 changes: 4 additions & 0 deletions src/client/ring_signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
#include "videomanager_interface.h"
#endif

#ifdef ENABLE_PLUGIN
#include "plugin_manager_interface.h"
#endif

#include "jami.h"
#include "logger.h"
#include "trace-tools.h"
Expand Down
24 changes: 24 additions & 0 deletions src/jami/plugin_manager_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,28 @@ DRING_PUBLIC std::vector<std::string> getChatHandlerStatus(const std::string& ac
const std::string& peerId);
DRING_PUBLIC bool getPluginsEnabled();
DRING_PUBLIC void setPluginsEnabled(bool state);

DRING_PUBLIC void sendWebViewMessage(const std::string& pluginId,
const std::string& webViewId,
const std::string& messageId,
const std::string& payload);

DRING_PUBLIC std::string sendWebViewAttach(const std::string& pluginId,
const std::string& accountId,
const std::string& webViewId,
const std::string& action);

DRING_PUBLIC void sendWebViewDetach(const std::string& pluginId, const std::string& webViewId);

namespace PluginSignal {
struct DRING_PUBLIC WebViewMessageReceived
{
constexpr static const char* name = "WebViewMessageReceived";
using cb_type = void(const std::string& /*pluginId*/,
const std::string& /*webViewId*/,
const std::string& /*messageId*/,
const std::string& /*payload*/);
};
} // namespace PluginSignal

} // namespace DRing
1 change: 1 addition & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ if conf.get('ENABLE_PLUGIN')
'plugin/preferenceservicesmanager.cpp',
'plugin/callservicesmanager.cpp',
'plugin/chatservicesmanager.cpp',
'plugin/webviewservicesmanager.cpp',
'plugin/jamipluginmanager.cpp',
'plugin/pluginloader.cpp',
'plugin/pluginmanager.cpp',
Expand Down
3 changes: 3 additions & 0 deletions src/plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ list (APPEND Source_Files__plugin
"${CMAKE_CURRENT_SOURCE_DIR}/chatservicesmanager.h"
"${CMAKE_CURRENT_SOURCE_DIR}/chatservicesmanager.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/preferencehandler.h"
"${CMAKE_CURRENT_SOURCE_DIR}/webviewservicesmanager.h"
"${CMAKE_CURRENT_SOURCE_DIR}/webviewservicesmanager.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/webviewhandler.h"
"${CMAKE_CURRENT_SOURCE_DIR}/chathandler.h"
"${CMAKE_CURRENT_SOURCE_DIR}/jamiplugin.h"
"${CMAKE_CURRENT_SOURCE_DIR}/jamipluginmanager.h"
Expand Down
3 changes: 3 additions & 0 deletions src/plugin/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ noinst_HEADERS += \
./plugin/preferencehandler.h \
./plugin/chathandler.h \
./plugin/chatservicesmanager.h \
./plugin/webviewservicesmanager.h \
./plugin/webviewhandler.h \
./plugin/jamiplugin.h \
./plugin/jamipluginmanager.h \
./plugin/mediahandler.h \
Expand All @@ -24,6 +26,7 @@ libplugin_la_SOURCES = \
./plugin/pluginpreferencesutils.cpp \
./plugin/pluginsutils.cpp \
./plugin/chatservicesmanager.cpp \
./plugin/webviewservicesmanager.cpp \
./plugin/callservicesmanager.cpp \
./plugin/preferenceservicesmanager.cpp

Expand Down
5 changes: 5 additions & 0 deletions src/plugin/jamipluginmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#pragma once

#include "noncopyable.h"
#include "plugin/webviewservicesmanager.h"
#include "pluginmanager.h"
#include "pluginpreferencesutils.h"

Expand Down Expand Up @@ -48,6 +49,7 @@ class JamiPluginManager
JamiPluginManager()
: callsm_ {pm_}
, chatsm_ {pm_}
, webviewsm_ {pm_}
, preferencesm_ {pm_}
{
registerServices();
Expand Down Expand Up @@ -146,6 +148,8 @@ class JamiPluginManager

ChatServicesManager& getChatServicesManager() { return chatsm_; }

WebViewServicesManager& getWebViewServicesManager() { return webviewsm_; }

PreferenceServicesManager& getPreferenceServicesManager() { return preferencesm_; }

private:
Expand All @@ -165,6 +169,7 @@ class JamiPluginManager
// Services instances
CallServicesManager callsm_;
ChatServicesManager chatsm_;
WebViewServicesManager webviewsm_;
PreferenceServicesManager preferencesm_;
};
} // namespace jami
Loading

0 comments on commit f773e24

Please sign in to comment.