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