Showing the changes to interface/src/scripting/ScreenshareScriptingInterface.cpp (1 of 4 files). Show all
Unified · Split
| @@ -32,7 +32,14 @@ · 31 unmodified lines | ||
| 32 | 32 | #include <RenderableTextEntityItem.h> |
| 33 | 33 | #include <RenderableWebEntityItem.h> |
| 34 | 34 | |
| 35 | −ScreenshareScriptingInterface::ScreenshareScriptingInterface(){}; | |
| 35 | +ScreenshareScriptingInterface::ScreenshareScriptingInterface() { | |
| 36 | + auto esi = DependencyManager::get<EntityScriptingInterface>(); | |
| 37 | + if (!esi) { | |
| 38 | + return; | |
| 39 | + } | |
| 40 | + | |
| 41 | + QObject::connect(esi.data(), &EntityScriptingInterface::webEventReceived, this, &ScreenshareScriptingInterface::onWebEventReceived); | |
| 42 | +}; | |
| 36 | 43 | |
| 37 | 44 | ScreenshareScriptingInterface::~ScreenshareScriptingInterface() { |
| 38 | 45 | stopScreenshare(); |
| @@ -46,9 +53,6 @@ static const glm::vec3 LOCAL_SCREENSHARE_WEB_ENTITY_LOCAL_POSITION(0.0f, -0.0862 · 7 unmodified lines | ||
| 46 | 53 | static const glm::vec3 LOCAL_SCREENSHARE_WEB_ENTITY_DIMENSIONS(4.0419f, 2.2735f, 0.0100f); |
| 47 | 54 | static const QString LOCAL_SCREENSHARE_WEB_ENTITY_URL = |
| 48 | 55 | "https://hifi-content.s3.amazonaws.com/Experiences/Releases/usefulUtilities/smartBoard/screenshareViewer/screenshareClient.html"; |
| 49 | −QString token; | |
| 50 | −QString projectAPIKey; | |
| 51 | −QString sessionID; | |
| 52 | 56 | void ScreenshareScriptingInterface::startScreenshare(const QUuid& screenshareZoneID, |
| 53 | 57 | const QUuid& smartboardEntityID, |
| 54 | 58 | const bool& isPresenter) { |
| @@ -60,7 +64,6 @@ void ScreenshareScriptingInterface::startScreenshare(const QUuid& screenshareZon · 5 unmodified lines | ||
| 60 | 64 | } |
| 61 | 65 | |
| 62 | 66 | if (isPresenter && _screenshareProcess && _screenshareProcess->state() != QProcess::NotRunning) { |
| 63 | − qDebug() << "Screenshare process already running. Aborting..."; | |
| 64 | 67 | return; |
| 65 | 68 | } |
| 66 | 69 | |
| @@ -77,7 +80,7 @@ void ScreenshareScriptingInterface::startScreenshare(const QUuid& screenshareZon · 10 unmodified lines | ||
| 77 | 80 | QUuid currentDomainID = DependencyManager::get<AddressManager>()->getDomainID(); |
| 78 | 81 | // `https://metaverse.highfidelity.com/api/v1/domain/:domain_id/screenshare`, |
| 79 | 82 | // passing the Domain ID that the user is connected to, as well as the `roomName`. |
| 80 | − // The server will respond with the relevant OpenTok Token, Session ID, and API Key. | |
| 83 | + // The server will respond with the relevant OpenTok , Session ID, and API Key. | |
| 81 | 84 | // Upon error-free response, do the logic below, passing in that info as necessary. |
| 82 | 85 | QNetworkAccessManager* manager = new QNetworkAccessManager(); |
| 83 | 86 | QObject::connect(manager, &QNetworkAccessManager::finished, this, [=](QNetworkReply* reply) { |
| @@ -92,17 +95,17 @@ void ScreenshareScriptingInterface::startScreenshare(const QUuid& screenshareZon · 8 unmodified lines | ||
| 92 | 95 | QByteArray answerByteArray = answer.toUtf8(); |
| 93 | 96 | QJsonDocument answerJSONObject = QJsonDocument::fromJson(answerByteArray); |
| 94 | 97 | |
| 95 | − token = answerJSONObject["token"].toString(); | |
| 96 | − projectAPIKey = answerJSONObject["projectAPIKey"].toString(); | |
| 97 | − sessionID = answerJSONObject["sessionID"].toString(); | |
| 98 | − qDebug() << "token:" << token << " projectAPIKey:" << projectAPIKey << " sessionID: " << sessionID; | |
| 98 | + _token = answerJSONObject["token"].toString(); | |
| 99 | + _projectAPIKey = answerJSONObject["projectAPIKey"].toString(); | |
| 100 | + _sessionID = answerJSONObject["sessionID"].toString(); | |
| 101 | + qDebug() << "token:" << _token << " projectAPIKey:" << _projectAPIKey << " sessionID: " << _sessionID; | |
| 99 | 102 | |
| 100 | 103 | if (isPresenter) { |
| 101 | 104 | QStringList arguments; |
| 102 | 105 | arguments << " "; |
| 103 | − arguments << "--token=" + token << " "; | |
| 104 | − arguments << "--projectAPIKey=" + projectAPIKey << " "; | |
| 105 | − arguments << "--sessionID=" + sessionID << " "; | |
| 106 | + arguments << "--token=" + _token << " "; | |
| 107 | + arguments << "--projectAPIKey=" + _projectAPIKey << " "; | |
| 108 | + arguments << "--sessionID=" + _sessionID << " "; | |
| 106 | 109 | |
| 107 | 110 | connect(_screenshareProcess.get(), &QProcess::errorOccurred, |
| 108 | 111 | [=](QProcess::ProcessError error) { qDebug() << "ZRF QProcess::errorOccurred. `error`:" << error; }); |
| @@ -144,49 +147,6 @@ void ScreenshareScriptingInterface::startScreenshare(const QUuid& screenshareZon · 35 unmodified lines | ||
| 144 | 147 | QString hostType = "local"; |
| 145 | 148 | _screenshareViewerLocalWebEntityUUID = esi->addEntity(localScreenshareWebEntityProps, hostType); |
| 146 | 149 | |
| 147 | − QObject::connect(esi.data(), &EntityScriptingInterface::webEventReceived, this, | |
| 148 | − [&](const QUuid& entityID, const QVariant& message) { | |
| 149 | − if (entityID == _screenshareViewerLocalWebEntityUUID) { | |
| 150 | − qDebug() << "ZRF HERE! Inside `webEventReceived(). `entityID`:" << entityID | |
| 151 | − << "`_screenshareViewerLocalWebEntityUUID`:" << _screenshareViewerLocalWebEntityUUID; | |
| 152 | − | |
| 153 | − auto esi = DependencyManager::get<EntityScriptingInterface>(); | |
| 154 | − if (!esi) { | |
| 155 | − return; | |
| 156 | − } | |
| 157 | − | |
| 158 | − QByteArray jsonByteArray = QVariant(message).toString().toUtf8(); | |
| 159 | − QJsonDocument jsonObject = QJsonDocument::fromJson(jsonByteArray); | |
| 160 | − | |
| 161 | − qDebug() << "ZRF HERE! Inside `webEventReceived(). `message`:" << message | |
| 162 | − << "`jsonObject`:" << jsonObject; | |
| 163 | − qDebug() << jsonObject["app"]; | |
| 164 | − if (jsonObject["app"] != "screenshare") { | |
| 165 | − return; | |
| 166 | − } | |
| 167 | − | |
| 168 | − qDebug() << "ZRF HERE! Inside `webEventReceived(). we're still here!"; | |
| 169 | − | |
| 170 | − if (jsonObject["method"] == "eventBridgeReady") { | |
| 171 | − QJsonObject responseObject; | |
| 172 | − responseObject.insert("app", "screenshare"); | |
| 173 | − responseObject.insert("method", "receiveConnectionInfo"); | |
| 174 | − QJsonObject responseObjectData; | |
| 175 | − responseObjectData.insert("token", token); | |
| 176 | − responseObjectData.insert("projectAPIKey", projectAPIKey); | |
| 177 | − responseObjectData.insert("sessionID", sessionID); | |
| 178 | − responseObject.insert("data", responseObjectData); | |
| 179 | − | |
| 180 | − qDebug() << "ZRF HERE! Inside `webEventReceived(). `responseObject.toVariantMap()`:" | |
| 181 | − << responseObject.toVariantMap(); | |
| 182 | − | |
| 183 | − auto esi = DependencyManager::get<EntityScriptingInterface>(); | |
| 184 | − esi->emitScriptEvent(_screenshareViewerLocalWebEntityUUID, responseObject.toVariantMap()); | |
| 185 | − } | |
| 186 | − } | |
| 187 | − }); | |
| 188 | − }); | |
| 189 | − | |
| 190 | 150 | QNetworkRequest request; |
| 191 | 151 | QString tokboxURL = QProcessEnvironment::systemEnvironment().value("hifiScreenshareUrl"); |
| 192 | 152 | request.setUrl(QUrl(tokboxURL)); |
| @@ -210,4 +170,38 @@ void ScreenshareScriptingInterface::stopScreenshare() { · 17 unmodified lines | ||
| 210 | 170 | } |
| 211 | 171 | } |
| 212 | 172 | _screenshareViewerLocalWebEntityUUID = "{00000000-0000-0000-0000-000000000000}"; |
| 173 | + _token = ""; | |
| 174 | + _projectAPIKey = ""; | |
| 175 | + _sessionID = ""; | |
| 176 | +} | |
| 177 | + | |
| 178 | +void ScreenshareScriptingInterface::onWebEventReceived(const QUuid& entityID, const QVariant& message) { | |
| 179 | + if (entityID == _screenshareViewerLocalWebEntityUUID) { | |
| 180 | + auto esi = DependencyManager::get<EntityScriptingInterface>(); | |
| 181 | + if (!esi) { | |
| 182 | + return; | |
| 183 | + } | |
| 184 | + | |
| 185 | + QByteArray jsonByteArray = QVariant(message).toString().toUtf8(); | |
| 186 | + QJsonDocument jsonObject = QJsonDocument::fromJson(jsonByteArray); | |
| 187 | + | |
| 188 | + if (jsonObject["app"] != "screenshare") { | |
| 189 | + return; | |
| 190 | + } | |
| 191 | + | |
| 192 | + if (jsonObject["method"] == "eventBridgeReady") { | |
| 193 | + QJsonObject responseObject; | |
| 194 | + responseObject.insert("app", "screenshare"); | |
| 195 | + responseObject.insert("method", "receiveConnectionInfo"); | |
| 196 | + QJsonObject responseObjectData; | |
| 197 | + responseObjectData.insert("token", _token); | |
| 198 | + responseObjectData.insert("projectAPIKey", _projectAPIKey); | |
| 199 | + responseObjectData.insert("sessionID", _sessionID); | |
| 200 | + responseObject.insert("data", responseObjectData); | |
| 201 | + | |
| 202 | + auto esi = DependencyManager::get<EntityScriptingInterface>(); | |
| 203 | + esi->emitScriptEvent(_screenshareViewerLocalWebEntityUUID, responseObject.toVariantMap()); | |
| 204 | + } | |
| 205 | + } | |
| 206 | + } | |
| 213 | 207 | } |