Showing the changes to interface/src/scripting/ScreenshareScriptingInterface.cpp (1 of 2 files). Show all
Unified · Split
| @@ -11,11 +11,13 @@ · 10 unmodified lines | |||
| 11 | 11 | ||
| 12 | #include <QCoreApplication> | 12 | #include <QCoreApplication> |
| 13 | #include <QDesktopServices> | 13 | #include <QDesktopServices> |
| 14 | #include <QJsonDocument> | ||
| 14 | #include <QThread> | 15 | #include <QThread> |
| 15 | #include <QUrl> | 16 | #include <QUrl> |
| 16 | 17 | ||
| 17 | #include <AddressManager.h> | 18 | #include <AddressManager.h> |
| 18 | 19 | ||
| 20 | #include "EntityScriptingInterface.h" | ||
| 19 | #include "ScreenshareScriptingInterface.h" | 21 | #include "ScreenshareScriptingInterface.h" |
| 20 | 22 | ||
| 21 | ScreenshareScriptingInterface::ScreenshareScriptingInterface() { | 23 | ScreenshareScriptingInterface::ScreenshareScriptingInterface() { |
| @@ -25,7 +27,11 @@ ScreenshareScriptingInterface::~ScreenshareScriptingInterface() { · 3 unmodified lines | |||
| 25 | stopScreenshare(); | 27 | stopScreenshare(); |
| 26 | } | 28 | } |
| 27 | 29 | ||
| 28 | void ScreenshareScriptingInterface::startScreenshare(const bool& isPresenter) { | 30 | static const EntityTypes::EntityType LOCAL_SCREENSHARE_WEB_ENTITY_TYPE = EntityTypes::Web; |
| 31 | static const uint8_t LOCAL_SCREENSHARE_WEB_ENTITY_FPS = 30; | ||
| 32 | static const glm::vec3 LOCAL_SCREENSHARE_WEB_ENTITY_LOCAL_POSITION(0.0f, 0.0f, 0.1f); | ||
| 33 | static const QString LOCAL_SCREENSHARE_WEB_ENTITY_URL = "https://s3.amazonaws.com/hifi-content/Experiences/Releases/usefulUtilities/smartBoard/screenshareViewer/screenshareClient.html"; | ||
| 34 | void ScreenshareScriptingInterface::startScreenshare(const QUuid& screenshareZoneID, const QUuid& smartboardEntityID, const bool& isPresenter) { | ||
| 29 | if (QThread::currentThread() != thread()) { | 35 | if (QThread::currentThread() != thread()) { |
| 30 | // We must start a new QProcess from the main thread. | 36 | // We must start a new QProcess from the main thread. |
| 31 | QMetaObject::invokeMethod( | 37 | QMetaObject::invokeMethod( |
| @@ -79,9 +85,57 @@ void ScreenshareScriptingInterface::startScreenshare(const bool& isPresenter) { · 47 unmodified lines | |||
| 79 | }); | 85 | }); |
| 80 | 86 | ||
| 81 | _screenshareProcess->start(SCREENSHARE_EXE_PATH, arguments); | 87 | _screenshareProcess->start(SCREENSHARE_EXE_PATH, arguments); |
| 82 | } else { | ||
| 83 | |||
| 84 | } | 88 | } |
| 89 | |||
| 90 | if (!_screenshareViewerLocalWebEntityUUID.isNull()) { | ||
| 91 | return; | ||
| 92 | } | ||
| 93 | |||
| 94 | auto esi = DependencyManager::get<EntityScriptingInterface>(); | ||
| 95 | if (!esi) { | ||
| 96 | return; | ||
| 97 | } | ||
| 98 | |||
| 99 | EntityItemProperties localScreenshareWebEntityProps; | ||
| 100 | localScreenshareWebEntityProps.setType(LOCAL_SCREENSHARE_WEB_ENTITY_TYPE); | ||
| 101 | localScreenshareWebEntityProps.setMaxFPS(LOCAL_SCREENSHARE_WEB_ENTITY_FPS); | ||
| 102 | localScreenshareWebEntityProps.setLocalPosition(LOCAL_SCREENSHARE_WEB_ENTITY_LOCAL_POSITION); | ||
| 103 | localScreenshareWebEntityProps.setSourceUrl(LOCAL_SCREENSHARE_WEB_ENTITY_URL); | ||
| 104 | localScreenshareWebEntityProps.setParentID(smartboardEntityID); | ||
| 105 | |||
| 106 | EntityPropertyFlags desiredSmartboardProperties; | ||
| 107 | desiredSmartboardProperties += PROP_POSITION; | ||
| 108 | desiredSmartboardProperties += PROP_DIMENSIONS; | ||
| 109 | EntityItemProperties smartboardProps = esi->getEntityProperties(smartboardEntityID, desiredSmartboardProperties); | ||
| 110 | |||
| 111 | localScreenshareWebEntityProps.setPosition(smartboardProps.getPosition()); | ||
| 112 | localScreenshareWebEntityProps.setDimensions(smartboardProps.getDimensions()); | ||
| 113 | |||
| 114 | _screenshareViewerLocalWebEntityUUID = esi->addEntity(localScreenshareWebEntityProps, "local"); | ||
| 115 | |||
| 116 | QObject::connect(esi.data(), &EntityScriptingInterface::webEventReceived, this, [&](const QUuid& entityID, const QVariant& message) { | ||
| 117 | if (entityID == _screenshareViewerLocalWebEntityUUID) { | ||
| 118 | auto esi = DependencyManager::get<EntityScriptingInterface>(); | ||
| 119 | if (!esi) { | ||
| 120 | return; | ||
| 121 | } | ||
| 122 | |||
| 123 | QJsonDocument jsonMessage = QJsonDocument::fromVariant(message); | ||
| 124 | QJsonObject jsonObject = jsonMessage.object(); | ||
| 125 | |||
| 126 | if (jsonObject["type"] == "eventbridge_ready") { | ||
| 127 | QJsonObject responseObject; | ||
| 128 | responseObject.insert("type", "receiveConnectionInfo"); | ||
| 129 | QJsonObject responseObjectData; | ||
| 130 | responseObjectData.insert("token", token); | ||
| 131 | responseObjectData.insert("projectAPIKey", apiKey); | ||
| 132 | responseObjectData.insert("sessionID", sessionID); | ||
| 133 | responseObject.insert("data", responseObjectData); | ||
| 134 | |||
| 135 | esi->emitScriptEvent(_screenshareViewerLocalWebEntityUUID, responseObject.toVariantMap()); | ||
| 136 | } | ||
| 137 | } | ||
| 138 | }); | ||
| 85 | }; | 139 | }; |
| 86 | 140 | ||
| 87 | void ScreenshareScriptingInterface::stopScreenshare() { | 141 | void ScreenshareScriptingInterface::stopScreenshare() { |
| @@ -93,4 +147,11 @@ void ScreenshareScriptingInterface::stopScreenshare() { · 5 unmodified lines | |||
| 93 | if (_screenshareProcess && _screenshareProcess->state() != QProcess::NotRunning) { | 147 | if (_screenshareProcess && _screenshareProcess->state() != QProcess::NotRunning) { |
| 94 | _screenshareProcess->terminate(); | 148 | _screenshareProcess->terminate(); |
| 95 | } | 149 | } |
| 150 | |||
| 151 | if (!_screenshareViewerLocalWebEntityUUID.isNull()) { | ||
| 152 | auto esi = DependencyManager::get<EntityScriptingInterface>(); | ||
| 153 | if (esi) { | ||
| 154 | esi->deleteEntity(_screenshareViewerLocalWebEntityUUID); | ||
| 155 | } | ||
| 156 | } | ||
| 96 | } | 157 | } |