From a41ae3daa921beb07aa9996396812ae3a2f8c248 Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Wed, 6 Nov 2019 15:45:48 -0800 Subject: [PATCH] Move the local web entity logic to c++ - might not be working --- .../ScreenshareScriptingInterface.cpp | 67 ++++++++++++++++++- .../scripting/ScreenshareScriptingInterface.h | 3 +- 2 files changed, 66 insertions(+), 4 deletions(-) diff --git a/interface/src/scripting/ScreenshareScriptingInterface.cpp b/interface/src/scripting/ScreenshareScriptingInterface.cpp index c165ae4937..f9a269728a 100644 --- a/interface/src/scripting/ScreenshareScriptingInterface.cpp +++ b/interface/src/scripting/ScreenshareScriptingInterface.cpp @@ -11,11 +11,13 @@ #include #include +#include #include #include #include +#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(); + 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(); + 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(); + if (esi) { + esi->deleteEntity(_screenshareViewerLocalWebEntityUUID); + } + } } diff --git a/interface/src/scripting/ScreenshareScriptingInterface.h b/interface/src/scripting/ScreenshareScriptingInterface.h index f369f39f26..671390932f 100644 --- a/interface/src/scripting/ScreenshareScriptingInterface.h +++ b/interface/src/scripting/ScreenshareScriptingInterface.h @@ -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 _screenshareProcess{ nullptr }; + QUuid _screenshareViewerLocalWebEntityUUID; }; #endif // hifi_ScreenshareScriptingInterface_h \ No newline at end of file