diff --git a/doric-Qt/example/doric/doric.pro b/doric-Qt/example/doric/doric.pro index 97e6fedd..c3d7babf 100644 --- a/doric-Qt/example/doric/doric.pro +++ b/doric-Qt/example/doric/doric.pro @@ -38,6 +38,7 @@ SOURCES += \ engine/v8/V8Executor.cpp \ plugin/DoricModalPlugin.cpp \ plugin/DoricNetworkPlugin.cpp \ + plugin/DoricNotificationPlugin.cpp \ plugin/DoricPopoverPlugin.cpp \ plugin/DoricShaderPlugin.cpp \ plugin/DoricStoragePlugin.cpp \ @@ -124,6 +125,7 @@ HEADERS += \ plugin/DoricModalPlugin.h \ plugin/DoricNativePlugin.h \ plugin/DoricNetworkPlugin.h \ + plugin/DoricNotificationPlugin.h \ plugin/DoricPopoverPlugin.h \ plugin/DoricShaderPlugin.h \ plugin/DoricStoragePlugin.h \ diff --git a/doric-Qt/example/doric/plugin/DoricNotificationPlugin.cpp b/doric-Qt/example/doric/plugin/DoricNotificationPlugin.cpp new file mode 100644 index 00000000..5c8dc26f --- /dev/null +++ b/doric-Qt/example/doric/plugin/DoricNotificationPlugin.cpp @@ -0,0 +1,46 @@ +#include "DoricNotificationPlugin.h" + +#include "engine/DoricPromise.h" + +#include +#include +#include + +void DoricNotificationPlugin::publish(QString jsValueString, + QString callbackId) { + QJsonDocument document = QJsonDocument::fromJson(jsValueString.toUtf8()); + QJsonValue jsValue = document.object(); + + getContext()->getDriver()->asyncCall( + [this, callbackId] { + QVariantList args; + DoricPromise::resolve(getContext(), callbackId, args); + }, + DoricThreadMode::JS); +} + +void DoricNotificationPlugin::subscribe(QString jsValueString, + QString callbackId) { + QJsonDocument document = QJsonDocument::fromJson(jsValueString.toUtf8()); + QJsonValue jsValue = document.object(); + + getContext()->getDriver()->asyncCall( + [this, callbackId] { + QVariantList args; + DoricPromise::resolve(getContext(), callbackId, args); + }, + DoricThreadMode::JS); +} + +void DoricNotificationPlugin::unsubscribe(QString jsValueString, + QString callbackId) { + QJsonDocument document = QJsonDocument::fromJson(jsValueString.toUtf8()); + QJsonValue jsValue = document.object(); + + getContext()->getDriver()->asyncCall( + [this, callbackId] { + QVariantList args; + DoricPromise::resolve(getContext(), callbackId, args); + }, + DoricThreadMode::JS); +} diff --git a/doric-Qt/example/doric/plugin/DoricNotificationPlugin.h b/doric-Qt/example/doric/plugin/DoricNotificationPlugin.h new file mode 100644 index 00000000..3422352d --- /dev/null +++ b/doric-Qt/example/doric/plugin/DoricNotificationPlugin.h @@ -0,0 +1,25 @@ +#ifndef DORICNOTIFICATIONPLUGIN_H +#define DORICNOTIFICATIONPLUGIN_H + +#include "DoricExport.h" + +#include "DoricNativePlugin.h" + +#include + +class DORIC_EXPORT DoricNotificationPlugin : public DoricNativePlugin { + Q_OBJECT + +private: + QUdpSocket udpSocket; + +public: + using DoricNativePlugin::DoricNativePlugin; + + Q_INVOKABLE void publish(QString jsValueString, QString callbackId); + + Q_INVOKABLE void subscribe(QString jsValueString, QString callbackId); + + Q_INVOKABLE void unsubscribe(QString jsValueString, QString callbackId); +}; +#endif // DORICNOTIFICATIONPLUGIN_H