Showing the changes to interface/src/scripting/ScreenshareScriptingInterface.cpp (1 of 3 files). Show all
Unified · Split
| @@ -12,6 +12,7 @@ · 11 unmodified lines | ||
| 12 | 12 | #include <QCoreApplication> |
| 13 | 13 | #include <QDesktopServices> |
| 14 | 14 | #include <QJsonDocument> |
| 15 | +#include <QJsonObject> | |
| 15 | 16 | #include <QThread> |
| 16 | 17 | #include <QUrl> |
| 17 | 18 | #include <QObject> |
| @@ -31,8 +32,7 @@ · 13 unmodified lines | ||
| 31 | 32 | #include <RenderableTextEntityItem.h> |
| 32 | 33 | #include <RenderableWebEntityItem.h> |
| 33 | 34 | |
| 34 | −ScreenshareScriptingInterface::ScreenshareScriptingInterface() { | |
| 35 | −}; | |
| 35 | +ScreenshareScriptingInterface::ScreenshareScriptingInterface(){}; | |
| 36 | 36 | |
| 37 | 37 | ScreenshareScriptingInterface::~ScreenshareScriptingInterface() { |
| 38 | 38 | stopScreenshare(); |
| @@ -40,18 +40,20 @@ ScreenshareScriptingInterface::~ScreenshareScriptingInterface() { · 1 unmodified line | ||
| 40 | 40 | |
| 41 | 41 | static const EntityTypes::EntityType LOCAL_SCREENSHARE_WEB_ENTITY_TYPE = EntityTypes::Web; |
| 42 | 42 | static const uint8_t LOCAL_SCREENSHARE_WEB_ENTITY_FPS = 30; |
| 43 | −static const glm::vec3 LOCAL_SCREENSHARE_WEB_ENTITY_LOCAL_POSITION(0.0f, -0.0862f, 0.0311f); | |
| 44 | −static const QString LOCAL_SCREENSHARE_WEB_ENTITY_URL = "https://hifi-content.s3.amazonaws.com/Experiences/Releases/usefulUtilities/smartBoard/screenshareViewer/screenshareClient.html?1"; | |
| 43 | +static const glm::vec3 LOCAL_SCREENSHARE_WEB_ENTITY_LOCAL_POSITION(0.0f, -0.0862f, 0.0711f); | |
| 44 | +static const QString LOCAL_SCREENSHARE_WEB_ENTITY_URL = | |
| 45 | + "https://hifi-content.s3.amazonaws.com/Experiences/Releases/usefulUtilities/smartBoard/screenshareViewer/screenshareClient.html"; | |
| 45 | 46 | static const glm::vec3 LOCAL_SCREENSHARE_WEB_ENTITY_DIMENSIONS(4.0419f, 2.2735f, 0.0100f); |
| 46 | −void ScreenshareScriptingInterface::startScreenshare(const QUuid& screenshareZoneID, const QUuid& smartboardEntityID, const bool& isPresenter) { | |
| 47 | +QString token; | |
| 48 | +QString apiKey; | |
| 49 | +QString sessionID; | |
| 50 | +void ScreenshareScriptingInterface::startScreenshare(const QUuid& screenshareZoneID, | |
| 51 | + const QUuid& smartboardEntityID, | |
| 52 | + const bool& isPresenter) { | |
| 47 | 53 | if (QThread::currentThread() != thread()) { |
| 48 | 54 | // We must start a new QProcess from the main thread. |
| 49 | − QMetaObject::invokeMethod( | |
| 50 | − this, "startScreenshare", | |
| 51 | − Q_ARG(const QUuid&, screenshareZoneID), | |
| 52 | − Q_ARG(const QUuid&, smartboardEntityID), | |
| 53 | − Q_ARG(const bool&, isPresenter) | |
| 54 | − ); | |
| 55 | + QMetaObject::invokeMethod(this, "startScreenshare", Q_ARG(const QUuid&, screenshareZoneID), | |
| 56 | + Q_ARG(const QUuid&, smartboardEntityID), Q_ARG(const bool&, isPresenter)); | |
| 55 | 57 | return; |
| 56 | 58 | } |
| 57 | 59 | |
| @@ -76,7 +78,7 @@ void ScreenshareScriptingInterface::startScreenshare(const QUuid& screenshareZon · 18 unmodified lines | ||
| 76 | 78 | // The server will respond with the relevant OpenTok Token, Session ID, and API Key. |
| 77 | 79 | // Upon error-free response, do the logic below, passing in that info as necessary. |
| 78 | 80 | QNetworkAccessManager* manager = new QNetworkAccessManager(); |
| 79 | − QObject::connect(manager, &QNetworkAccessManager::finished, this, [=](QNetworkReply *reply) { | |
| 81 | + QObject::connect(manager, &QNetworkAccessManager::finished, this, [=](QNetworkReply* reply) { | |
| 80 | 82 | if (reply->error()) { |
| 81 | 83 | qDebug() << "\n\n MN HERE: REPLY" << reply->errorString(); |
| 82 | 84 | return; |
| @@ -85,27 +87,31 @@ void ScreenshareScriptingInterface::startScreenshare(const QUuid& screenshareZon · 2 unmodified lines | ||
| 85 | 87 | QString answer = reply->readAll(); |
| 86 | 88 | qDebug() << "\n\n MN HERE: REPLY" << answer; |
| 87 | 89 | |
| 88 | − | |
| 89 | − QString token = ""; | |
| 90 | − QString apiKey = ""; | |
| 91 | − QString sessionID = ""; | |
| 90 | + QByteArray answerByteArray = answer.toUtf8(); | |
| 91 | + QJsonDocument answerJSONObject = QJsonDocument::fromJson(answerByteArray); | |
| 92 | + | |
| 93 | + token = answerJSONObject["token"].toString(); | |
| 94 | + apiKey = answerJSONObject["apiKey"].toString(); | |
| 95 | + sessionID = answerJSONObject["sessionId"].toString(); // hifi-test has Id camel-case. Change for metaverse. | |
| 96 | + qDebug() << "token:" << token << " apiKey:" << apiKey << " sessionID: " << sessionID; | |
| 92 | 97 | |
| 93 | 98 | if (isPresenter) { |
| 94 | 99 | QStringList arguments; |
| 95 | − arguments << "--token=" + token; | |
| 96 | − arguments << "--apiKey=" + apiKey; | |
| 100 | + arguments << "--token=" + token; | |
| 101 | + arguments << "--apiKey=" + apiKey; | |
| 97 | 102 | arguments << "--sessionID=" + sessionID; |
| 98 | − | |
| 103 | + | |
| 99 | 104 | connect(_screenshareProcess.get(), &QProcess::errorOccurred, |
| 100 | − [=](QProcess::ProcessError error) { qDebug() << "ZRF QProcess::errorOccurred. `error`:" << error; }); | |
| 105 | + [=](QProcess::ProcessError error) { qDebug() << "ZRF QProcess::errorOccurred. `error`:" << error; }); | |
| 101 | 106 | connect(_screenshareProcess.get(), &QProcess::started, [=]() { qDebug() << "ZRF QProcess::started"; }); |
| 102 | − connect(_screenshareProcess.get(), &QProcess::stateChanged, | |
| 103 | − [=](QProcess::ProcessState newState) { qDebug() << "ZRF QProcess::stateChanged. `newState`:" << newState; }); | |
| 107 | + connect(_screenshareProcess.get(), &QProcess::stateChanged, [=](QProcess::ProcessState newState) { | |
| 108 | + qDebug() << "ZRF QProcess::stateChanged. `newState`:" << newState; | |
| 109 | + }); | |
| 104 | 110 | connect(_screenshareProcess.get(), QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), |
| 105 | − [=](int exitCode, QProcess::ExitStatus exitStatus) { | |
| 106 | − qDebug() << "ZRF QProcess::finished. `exitCode`:" << exitCode << "`exitStatus`:" << exitStatus; | |
| 107 | − emit screenshareStopped(); | |
| 108 | − }); | |
| 111 | + [=](int exitCode, QProcess::ExitStatus exitStatus) { | |
| 112 | + qDebug() << "ZRF QProcess::finished. `exitCode`:" << exitCode << "`exitStatus`:" << exitStatus; | |
| 113 | + emit screenshareStopped(); | |
| 114 | + }); | |
| 109 | 115 | |
| 110 | 116 | _screenshareProcess->start(SCREENSHARE_EXE_PATH, arguments); |
| 111 | 117 | } |
| @@ -135,50 +141,56 @@ void ScreenshareScriptingInterface::startScreenshare(const QUuid& screenshareZon · 23 unmodified lines | ||
| 135 | 141 | QString hostType = "local"; |
| 136 | 142 | _screenshareViewerLocalWebEntityUUID = esi->addEntity(localScreenshareWebEntityProps, hostType); |
| 137 | 143 | |
| 138 | − QObject::connect(esi.data(), &EntityScriptingInterface::webEventReceived, this, [&](const QUuid& entityID, const QVariant& message) { | |
| 139 | − if (entityID == _screenshareViewerLocalWebEntityUUID) { | |
| 140 | − qDebug() << "ZRF HERE! Inside `webEventReceived(). `entityID`:" << entityID << "`_screenshareViewerLocalWebEntityUUID`:" << _screenshareViewerLocalWebEntityUUID; | |
| 141 | − | |
| 142 | − auto esi = DependencyManager::get<EntityScriptingInterface>(); | |
| 143 | − if (!esi) { | |
| 144 | − return; | |
| 145 | − } | |
| 146 | − | |
| 147 | − QJsonDocument jsonMessage = QJsonDocument::fromVariant(message); | |
| 148 | − QJsonObject jsonObject = jsonMessage.object(); | |
| 149 | − | |
| 150 | − qDebug() << "ZRF HERE! Inside `webEventReceived(). `message`:" << message << "`jsonMessage`:" << jsonMessage; | |
| 151 | − | |
| 152 | − if (jsonObject["app"] != "screenshare") { | |
| 153 | − return; | |
| 154 | − } | |
| 155 | − | |
| 156 | − qDebug() << "ZRF HERE! Inside `webEventReceived(). we're still here!"; | |
| 157 | − | |
| 158 | − if (jsonObject["method"] == "eventBridgeReady") { | |
| 159 | − QJsonObject responseObject; | |
| 160 | − responseObject.insert("app", "screenshare"); | |
| 161 | − responseObject.insert("method", "receiveConnectionInfo"); | |
| 162 | − QJsonObject responseObjectData; | |
| 163 | − responseObjectData.insert("token", token); | |
| 164 | − responseObjectData.insert("projectAPIKey", apiKey); | |
| 165 | − responseObjectData.insert("sessionID", sessionID); | |
| 166 | − responseObject.insert("data", responseObjectData); | |
| 167 | − | |
| 168 | − qDebug() << "ZRF HERE! Inside `webEventReceived(). `responseObject.toVariantMap()`:" << responseObject.toVariantMap(); | |
| 169 | − | |
| 170 | − // Attempt 1, we receive the eventBridge message, but this won't send a message | |
| 171 | − // to that js | |
| 172 | − auto esi = DependencyManager::get<EntityScriptingInterface>(); | |
| 173 | − esi->emitScriptEvent(_screenshareViewerLocalWebEntityUUID, responseObject.toVariantMap()); | |
| 174 | − | |
| 175 | − // atempt 2, same outcome | |
| 176 | − auto entityTreeRenderer = DependencyManager::get<EntityTreeRenderer>(); | |
| 177 | − auto webEntityRenderable = entityTreeRenderer->renderableForEntityId(_screenshareViewerLocalWebEntityUUID); | |
| 178 | − webEntityRenderable->emitScriptEvent(responseObject.toVariantMap()); | |
| 179 | − } | |
| 180 | − } | |
| 181 | − }); | |
| 144 | + QObject::connect(esi.data(), &EntityScriptingInterface::webEventReceived, this, | |
| 145 | + [&](const QUuid& entityID, const QVariant& message) { | |
| 146 | + if (entityID == _screenshareViewerLocalWebEntityUUID) { | |
| 147 | + qDebug() << "ZRF HERE! Inside `webEventReceived(). `entityID`:" << entityID | |
| 148 | + << "`_screenshareViewerLocalWebEntityUUID`:" << _screenshareViewerLocalWebEntityUUID; | |
| 149 | + | |
| 150 | + auto esi = DependencyManager::get<EntityScriptingInterface>(); | |
| 151 | + if (!esi) { | |
| 152 | + return; | |
| 153 | + } | |
| 154 | + | |
| 155 | + qDebug() << "MN HERE! message:" << message; | |
| 156 | + QByteArray jsonByteArray = QVariant(message).toString().toUtf8(); | |
| 157 | + QJsonDocument jsonObject = QJsonDocument::fromJson(jsonByteArray); | |
| 158 | + | |
| 159 | + qDebug() << "ZRF HERE! Inside `webEventReceived(). `message`:" << message | |
| 160 | + << "`jsonObject`:" << jsonObject; | |
| 161 | + qDebug() << jsonObject["app"]; | |
| 162 | + if (jsonObject["app"] != "screenshare") { | |
| 163 | + return; | |
| 164 | + } | |
| 165 | + | |
| 166 | + qDebug() << "ZRF HERE! Inside `webEventReceived(). we're still here!"; | |
| 167 | + | |
| 168 | + if (jsonObject["method"] == "eventBridgeReady") { | |
| 169 | + QJsonObject responseObject; | |
| 170 | + responseObject.insert("app", "screenshare"); | |
| 171 | + responseObject.insert("method", "receiveConnectionInfo"); | |
| 172 | + QJsonObject responseObjectData; | |
| 173 | + responseObjectData.insert("token", token); | |
| 174 | + responseObjectData.insert("projectAPIKey", apiKey); | |
| 175 | + responseObjectData.insert("sessionID", sessionID); | |
| 176 | + responseObject.insert("data", responseObjectData); | |
| 177 | + | |
| 178 | + qDebug() << "ZRF HERE! Inside `webEventReceived(). `responseObject.toVariantMap()`:" | |
| 179 | + << responseObject.toVariantMap(); | |
| 180 | + | |
| 181 | + // Attempt 1, we receive the eventBridge message, but this won't send a message | |
| 182 | + // to that js | |
| 183 | + auto esi = DependencyManager::get<EntityScriptingInterface>(); | |
| 184 | + esi->emitScriptEvent(_screenshareViewerLocalWebEntityUUID, responseObject.toVariantMap()); | |
| 185 | + | |
| 186 | + // atempt 2, same outcome | |
| 187 | + //auto entityTreeRenderer = DependencyManager::get<EntityTreeRenderer>(); | |
| 188 | + //auto webEntityRenderable = | |
| 189 | + // entityTreeRenderer->renderableForEntityId(_screenshareViewerLocalWebEntityUUID); | |
| 190 | + //webEntityRenderable->emitScriptEvent(responseObject.toVariantMap()); | |
| 191 | + } | |
| 192 | + } | |
| 193 | + }); | |
| 182 | 194 | }); |
| 183 | 195 | |
| 184 | 196 | QNetworkRequest request; |