add notification plugin
This commit is contained in:
parent
8c0b4d0b11
commit
bb48faaf47
@ -38,6 +38,7 @@ SOURCES += \
|
|||||||
engine/v8/V8Executor.cpp \
|
engine/v8/V8Executor.cpp \
|
||||||
plugin/DoricModalPlugin.cpp \
|
plugin/DoricModalPlugin.cpp \
|
||||||
plugin/DoricNetworkPlugin.cpp \
|
plugin/DoricNetworkPlugin.cpp \
|
||||||
|
plugin/DoricNotificationPlugin.cpp \
|
||||||
plugin/DoricPopoverPlugin.cpp \
|
plugin/DoricPopoverPlugin.cpp \
|
||||||
plugin/DoricShaderPlugin.cpp \
|
plugin/DoricShaderPlugin.cpp \
|
||||||
plugin/DoricStoragePlugin.cpp \
|
plugin/DoricStoragePlugin.cpp \
|
||||||
@ -124,6 +125,7 @@ HEADERS += \
|
|||||||
plugin/DoricModalPlugin.h \
|
plugin/DoricModalPlugin.h \
|
||||||
plugin/DoricNativePlugin.h \
|
plugin/DoricNativePlugin.h \
|
||||||
plugin/DoricNetworkPlugin.h \
|
plugin/DoricNetworkPlugin.h \
|
||||||
|
plugin/DoricNotificationPlugin.h \
|
||||||
plugin/DoricPopoverPlugin.h \
|
plugin/DoricPopoverPlugin.h \
|
||||||
plugin/DoricShaderPlugin.h \
|
plugin/DoricShaderPlugin.h \
|
||||||
plugin/DoricStoragePlugin.h \
|
plugin/DoricStoragePlugin.h \
|
||||||
|
46
doric-Qt/example/doric/plugin/DoricNotificationPlugin.cpp
Normal file
46
doric-Qt/example/doric/plugin/DoricNotificationPlugin.cpp
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
#include "DoricNotificationPlugin.h"
|
||||||
|
|
||||||
|
#include "engine/DoricPromise.h"
|
||||||
|
|
||||||
|
#include <QCoreApplication>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QJsonObject>
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
25
doric-Qt/example/doric/plugin/DoricNotificationPlugin.h
Normal file
25
doric-Qt/example/doric/plugin/DoricNotificationPlugin.h
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#ifndef DORICNOTIFICATIONPLUGIN_H
|
||||||
|
#define DORICNOTIFICATIONPLUGIN_H
|
||||||
|
|
||||||
|
#include "DoricExport.h"
|
||||||
|
|
||||||
|
#include "DoricNativePlugin.h"
|
||||||
|
|
||||||
|
#include <QUdpSocket>
|
||||||
|
|
||||||
|
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
|
Reference in New Issue
Block a user