add notification plugin

This commit is contained in:
王劲鹏
2021-06-07 17:12:55 +08:00
committed by osborn
parent 8c0b4d0b11
commit bb48faaf47
3 changed files with 73 additions and 0 deletions

View 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);
}