mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-06 08:43:09 +02:00
Move the local web entity logic to c++ - might not be working
This commit is contained in:
parent
40814f9086
commit
a41ae3daa9
2 changed files with 66 additions and 4 deletions
|
@ -11,11 +11,13 @@
|
|||
|
||||
#include <QCoreApplication>
|
||||
#include <QDesktopServices>
|
||||
#include <QJsonDocument>
|
||||
#include <QThread>
|
||||
#include <QUrl>
|
||||
|
||||
#include <AddressManager.h>
|
||||
|
||||
#include "EntityScriptingInterface.h"
|
||||
#include "ScreenshareScriptingInterface.h"
|
||||
|
||||
ScreenshareScriptingInterface::ScreenshareScriptingInterface() {
|
||||
|
@ -25,7 +27,11 @@ ScreenshareScriptingInterface::~ScreenshareScriptingInterface() {
|
|||
stopScreenshare();
|
||||
}
|
||||
|
||||
void ScreenshareScriptingInterface::startScreenshare(const bool& isPresenter) {
|
||||
static const EntityTypes::EntityType LOCAL_SCREENSHARE_WEB_ENTITY_TYPE = EntityTypes::Web;
|
||||
static const uint8_t LOCAL_SCREENSHARE_WEB_ENTITY_FPS = 30;
|
||||
static const glm::vec3 LOCAL_SCREENSHARE_WEB_ENTITY_LOCAL_POSITION(0.0f, 0.0f, 0.1f);
|
||||
static const QString LOCAL_SCREENSHARE_WEB_ENTITY_URL = "https://s3.amazonaws.com/hifi-content/Experiences/Releases/usefulUtilities/smartBoard/screenshareViewer/screenshareClient.html";
|
||||
void ScreenshareScriptingInterface::startScreenshare(const QUuid& screenshareZoneID, const QUuid& smartboardEntityID, const bool& isPresenter) {
|
||||
if (QThread::currentThread() != thread()) {
|
||||
// We must start a new QProcess from the main thread.
|
||||
QMetaObject::invokeMethod(
|
||||
|
@ -79,9 +85,57 @@ void ScreenshareScriptingInterface::startScreenshare(const bool& isPresenter) {
|
|||
});
|
||||
|
||||
_screenshareProcess->start(SCREENSHARE_EXE_PATH, arguments);
|
||||
} else {
|
||||
|
||||
}
|
||||
|
||||
if (!_screenshareViewerLocalWebEntityUUID.isNull()) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto esi = DependencyManager::get<EntityScriptingInterface>();
|
||||
if (!esi) {
|
||||
return;
|
||||
}
|
||||
|
||||
EntityItemProperties localScreenshareWebEntityProps;
|
||||
localScreenshareWebEntityProps.setType(LOCAL_SCREENSHARE_WEB_ENTITY_TYPE);
|
||||
localScreenshareWebEntityProps.setMaxFPS(LOCAL_SCREENSHARE_WEB_ENTITY_FPS);
|
||||
localScreenshareWebEntityProps.setLocalPosition(LOCAL_SCREENSHARE_WEB_ENTITY_LOCAL_POSITION);
|
||||
localScreenshareWebEntityProps.setSourceUrl(LOCAL_SCREENSHARE_WEB_ENTITY_URL);
|
||||
localScreenshareWebEntityProps.setParentID(smartboardEntityID);
|
||||
|
||||
EntityPropertyFlags desiredSmartboardProperties;
|
||||
desiredSmartboardProperties += PROP_POSITION;
|
||||
desiredSmartboardProperties += PROP_DIMENSIONS;
|
||||
EntityItemProperties smartboardProps = esi->getEntityProperties(smartboardEntityID, desiredSmartboardProperties);
|
||||
|
||||
localScreenshareWebEntityProps.setPosition(smartboardProps.getPosition());
|
||||
localScreenshareWebEntityProps.setDimensions(smartboardProps.getDimensions());
|
||||
|
||||
_screenshareViewerLocalWebEntityUUID = esi->addEntity(localScreenshareWebEntityProps, "local");
|
||||
|
||||
QObject::connect(esi.data(), &EntityScriptingInterface::webEventReceived, this, [&](const QUuid& entityID, const QVariant& message) {
|
||||
if (entityID == _screenshareViewerLocalWebEntityUUID) {
|
||||
auto esi = DependencyManager::get<EntityScriptingInterface>();
|
||||
if (!esi) {
|
||||
return;
|
||||
}
|
||||
|
||||
QJsonDocument jsonMessage = QJsonDocument::fromVariant(message);
|
||||
QJsonObject jsonObject = jsonMessage.object();
|
||||
|
||||
if (jsonObject["type"] == "eventbridge_ready") {
|
||||
QJsonObject responseObject;
|
||||
responseObject.insert("type", "receiveConnectionInfo");
|
||||
QJsonObject responseObjectData;
|
||||
responseObjectData.insert("token", token);
|
||||
responseObjectData.insert("projectAPIKey", apiKey);
|
||||
responseObjectData.insert("sessionID", sessionID);
|
||||
responseObject.insert("data", responseObjectData);
|
||||
|
||||
esi->emitScriptEvent(_screenshareViewerLocalWebEntityUUID, responseObject.toVariantMap());
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
void ScreenshareScriptingInterface::stopScreenshare() {
|
||||
|
@ -93,4 +147,11 @@ void ScreenshareScriptingInterface::stopScreenshare() {
|
|||
if (_screenshareProcess && _screenshareProcess->state() != QProcess::NotRunning) {
|
||||
_screenshareProcess->terminate();
|
||||
}
|
||||
|
||||
if (!_screenshareViewerLocalWebEntityUUID.isNull()) {
|
||||
auto esi = DependencyManager::get<EntityScriptingInterface>();
|
||||
if (esi) {
|
||||
esi->deleteEntity(_screenshareViewerLocalWebEntityUUID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ public:
|
|||
ScreenshareScriptingInterface();
|
||||
~ScreenshareScriptingInterface();
|
||||
|
||||
Q_INVOKABLE void startScreenshare(const bool& isPresenter);
|
||||
Q_INVOKABLE void startScreenshare(const QUuid& screenshareZoneID, const QUuid& smartboardEntityID, const bool& isPresenter = false);
|
||||
Q_INVOKABLE void stopScreenshare();
|
||||
|
||||
signals:
|
||||
|
@ -43,6 +43,7 @@ private:
|
|||
#endif
|
||||
|
||||
std::unique_ptr<QProcess> _screenshareProcess{ nullptr };
|
||||
QUuid _screenshareViewerLocalWebEntityUUID;
|
||||
};
|
||||
|
||||
#endif // hifi_ScreenshareScriptingInterface_h
|
Loading…
Reference in a new issue