diff --git a/interface/src/scripting/ScreenshareScriptingInterface.cpp b/interface/src/scripting/ScreenshareScriptingInterface.cpp index 62a1215d41..e8a7adfc6f 100644 --- a/interface/src/scripting/ScreenshareScriptingInterface.cpp +++ b/interface/src/scripting/ScreenshareScriptingInterface.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -31,8 +32,7 @@ #include #include -ScreenshareScriptingInterface::ScreenshareScriptingInterface() { -}; +ScreenshareScriptingInterface::ScreenshareScriptingInterface(){}; ScreenshareScriptingInterface::~ScreenshareScriptingInterface() { stopScreenshare(); @@ -40,18 +40,20 @@ ScreenshareScriptingInterface::~ScreenshareScriptingInterface() { 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.0862f, 0.0311f); -static const QString LOCAL_SCREENSHARE_WEB_ENTITY_URL = "https://hifi-content.s3.amazonaws.com/Experiences/Releases/usefulUtilities/smartBoard/screenshareViewer/screenshareClient.html?1"; +static const glm::vec3 LOCAL_SCREENSHARE_WEB_ENTITY_LOCAL_POSITION(0.0f, -0.0862f, 0.0711f); +static const QString LOCAL_SCREENSHARE_WEB_ENTITY_URL = + "https://hifi-content.s3.amazonaws.com/Experiences/Releases/usefulUtilities/smartBoard/screenshareViewer/screenshareClient.html"; static const glm::vec3 LOCAL_SCREENSHARE_WEB_ENTITY_DIMENSIONS(4.0419f, 2.2735f, 0.0100f); -void ScreenshareScriptingInterface::startScreenshare(const QUuid& screenshareZoneID, const QUuid& smartboardEntityID, const bool& isPresenter) { +QString token; +QString apiKey; +QString sessionID; +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( - this, "startScreenshare", - Q_ARG(const QUuid&, screenshareZoneID), - Q_ARG(const QUuid&, smartboardEntityID), - Q_ARG(const bool&, isPresenter) - ); + QMetaObject::invokeMethod(this, "startScreenshare", Q_ARG(const QUuid&, screenshareZoneID), + Q_ARG(const QUuid&, smartboardEntityID), Q_ARG(const bool&, isPresenter)); return; } @@ -76,7 +78,7 @@ void ScreenshareScriptingInterface::startScreenshare(const QUuid& screenshareZon // The server will respond with the relevant OpenTok Token, Session ID, and API Key. // Upon error-free response, do the logic below, passing in that info as necessary. QNetworkAccessManager* manager = new QNetworkAccessManager(); - QObject::connect(manager, &QNetworkAccessManager::finished, this, [=](QNetworkReply *reply) { + QObject::connect(manager, &QNetworkAccessManager::finished, this, [=](QNetworkReply* reply) { if (reply->error()) { qDebug() << "\n\n MN HERE: REPLY" << reply->errorString(); return; @@ -85,27 +87,31 @@ void ScreenshareScriptingInterface::startScreenshare(const QUuid& screenshareZon QString answer = reply->readAll(); qDebug() << "\n\n MN HERE: REPLY" << answer; - - QString token = ""; - QString apiKey = ""; - QString sessionID = ""; + QByteArray answerByteArray = answer.toUtf8(); + QJsonDocument answerJSONObject = QJsonDocument::fromJson(answerByteArray); + + token = answerJSONObject["token"].toString(); + apiKey = answerJSONObject["apiKey"].toString(); + sessionID = answerJSONObject["sessionId"].toString(); // hifi-test has Id camel-case. Change for metaverse. + qDebug() << "token:" << token << " apiKey:" << apiKey << " sessionID: " << sessionID; if (isPresenter) { QStringList arguments; - arguments << "--token=" + token; - arguments << "--apiKey=" + apiKey; + arguments << "--token=" + token; + arguments << "--apiKey=" + apiKey; arguments << "--sessionID=" + sessionID; - + connect(_screenshareProcess.get(), &QProcess::errorOccurred, - [=](QProcess::ProcessError error) { qDebug() << "ZRF QProcess::errorOccurred. `error`:" << error; }); + [=](QProcess::ProcessError error) { qDebug() << "ZRF QProcess::errorOccurred. `error`:" << error; }); connect(_screenshareProcess.get(), &QProcess::started, [=]() { qDebug() << "ZRF QProcess::started"; }); - connect(_screenshareProcess.get(), &QProcess::stateChanged, - [=](QProcess::ProcessState newState) { qDebug() << "ZRF QProcess::stateChanged. `newState`:" << newState; }); + connect(_screenshareProcess.get(), &QProcess::stateChanged, [=](QProcess::ProcessState newState) { + qDebug() << "ZRF QProcess::stateChanged. `newState`:" << newState; + }); connect(_screenshareProcess.get(), QOverload::of(&QProcess::finished), - [=](int exitCode, QProcess::ExitStatus exitStatus) { - qDebug() << "ZRF QProcess::finished. `exitCode`:" << exitCode << "`exitStatus`:" << exitStatus; - emit screenshareStopped(); - }); + [=](int exitCode, QProcess::ExitStatus exitStatus) { + qDebug() << "ZRF QProcess::finished. `exitCode`:" << exitCode << "`exitStatus`:" << exitStatus; + emit screenshareStopped(); + }); _screenshareProcess->start(SCREENSHARE_EXE_PATH, arguments); } @@ -135,50 +141,56 @@ void ScreenshareScriptingInterface::startScreenshare(const QUuid& screenshareZon QString hostType = "local"; _screenshareViewerLocalWebEntityUUID = esi->addEntity(localScreenshareWebEntityProps, hostType); - QObject::connect(esi.data(), &EntityScriptingInterface::webEventReceived, this, [&](const QUuid& entityID, const QVariant& message) { - if (entityID == _screenshareViewerLocalWebEntityUUID) { - qDebug() << "ZRF HERE! Inside `webEventReceived(). `entityID`:" << entityID << "`_screenshareViewerLocalWebEntityUUID`:" << _screenshareViewerLocalWebEntityUUID; - - auto esi = DependencyManager::get(); - if (!esi) { - return; - } + QObject::connect(esi.data(), &EntityScriptingInterface::webEventReceived, this, + [&](const QUuid& entityID, const QVariant& message) { + if (entityID == _screenshareViewerLocalWebEntityUUID) { + qDebug() << "ZRF HERE! Inside `webEventReceived(). `entityID`:" << entityID + << "`_screenshareViewerLocalWebEntityUUID`:" << _screenshareViewerLocalWebEntityUUID; - QJsonDocument jsonMessage = QJsonDocument::fromVariant(message); - QJsonObject jsonObject = jsonMessage.object(); + auto esi = DependencyManager::get(); + if (!esi) { + return; + } - qDebug() << "ZRF HERE! Inside `webEventReceived(). `message`:" << message << "`jsonMessage`:" << jsonMessage; + qDebug() << "MN HERE! message:" << message; + QByteArray jsonByteArray = QVariant(message).toString().toUtf8(); + QJsonDocument jsonObject = QJsonDocument::fromJson(jsonByteArray); - if (jsonObject["app"] != "screenshare") { - return; - } + qDebug() << "ZRF HERE! Inside `webEventReceived(). `message`:" << message + << "`jsonObject`:" << jsonObject; + qDebug() << jsonObject["app"]; + if (jsonObject["app"] != "screenshare") { + return; + } - qDebug() << "ZRF HERE! Inside `webEventReceived(). we're still here!"; + qDebug() << "ZRF HERE! Inside `webEventReceived(). we're still here!"; - if (jsonObject["method"] == "eventBridgeReady") { - QJsonObject responseObject; - responseObject.insert("app", "screenshare"); - responseObject.insert("method", "receiveConnectionInfo"); - QJsonObject responseObjectData; - responseObjectData.insert("token", token); - responseObjectData.insert("projectAPIKey", apiKey); - responseObjectData.insert("sessionID", sessionID); - responseObject.insert("data", responseObjectData); + if (jsonObject["method"] == "eventBridgeReady") { + QJsonObject responseObject; + responseObject.insert("app", "screenshare"); + responseObject.insert("method", "receiveConnectionInfo"); + QJsonObject responseObjectData; + responseObjectData.insert("token", token); + responseObjectData.insert("projectAPIKey", apiKey); + responseObjectData.insert("sessionID", sessionID); + responseObject.insert("data", responseObjectData); - qDebug() << "ZRF HERE! Inside `webEventReceived(). `responseObject.toVariantMap()`:" << responseObject.toVariantMap(); + qDebug() << "ZRF HERE! Inside `webEventReceived(). `responseObject.toVariantMap()`:" + << responseObject.toVariantMap(); - // Attempt 1, we receive the eventBridge message, but this won't send a message - // to that js - auto esi = DependencyManager::get(); - esi->emitScriptEvent(_screenshareViewerLocalWebEntityUUID, responseObject.toVariantMap()); + // Attempt 1, we receive the eventBridge message, but this won't send a message + // to that js + auto esi = DependencyManager::get(); + esi->emitScriptEvent(_screenshareViewerLocalWebEntityUUID, responseObject.toVariantMap()); - // atempt 2, same outcome - auto entityTreeRenderer = DependencyManager::get(); - auto webEntityRenderable = entityTreeRenderer->renderableForEntityId(_screenshareViewerLocalWebEntityUUID); - webEntityRenderable->emitScriptEvent(responseObject.toVariantMap()); - } - } - }); + // atempt 2, same outcome + //auto entityTreeRenderer = DependencyManager::get(); + //auto webEntityRenderable = + // entityTreeRenderer->renderableForEntityId(_screenshareViewerLocalWebEntityUUID); + //webEntityRenderable->emitScriptEvent(responseObject.toVariantMap()); + } + } + }); }); QNetworkRequest request; diff --git a/screenshare/src/app.js b/screenshare/src/app.js index 0fbddd4a2d..484e6d5829 100644 --- a/screenshare/src/app.js +++ b/screenshare/src/app.js @@ -243,20 +243,21 @@ function togglePage(){ // main TODO: - // const {ipcRenderer} = ipcRenderer; - // let apiKey; - // let sessionId; - // let token; - // let session; - // ipcRenderer.on('connectionInfo', function(event, message){ - // console.log("event", event); - // console.log("MESSAGE FROM MAIN", message); - // const connectionInfo = JSON.parse(message); + const ipcRenderer = electron.ipcRenderer; + let apiKey; + let sessionId; + let token; + let session; + + ipcRenderer.on('connectionInfo', function(event, message){ + console.log("event:" + event); + console.log("MESSAGE FROM MAIN:" + message); + // const connectionInfo = JSON.parse(message); // apiKey = connectionInfo.apiKey; // sessionId = connectionInfo.sessionId; // token = connectionInfo.token; // initializeTokboxSession(); - // }) + }) function startup(){ console.log("\n\n IN STARTUP \n\n") diff --git a/screenshare/src/main.js b/screenshare/src/main.js index 289a4c0ae3..e8fabc7bc6 100644 --- a/screenshare/src/main.js +++ b/screenshare/src/main.js @@ -6,7 +6,8 @@ const {app, BrowserWindow, ipcMain} = require('electron'); const gotTheLock = app.requestSingleInstanceLock() const argv = require('yargs').argv; // ./screenshare.exe --userName=miladN ... - +console.log("argV:", argv) +console.log("argV Username", argv.userName); const connectionInfo = { userName: argv.userName || "testName", displayName: argv.displayName || "displayName", @@ -23,6 +24,7 @@ if (!gotTheLock) { var window; function createWindow(){ + console.log("Creating window") const zoomFactor = 1.0; window = new BrowserWindow({ backgroundColor: "#000000", @@ -33,24 +35,26 @@ function createWindow(){ useContentSize: true, zoomFactor: zoomFactor, resizable: false, - alwaysOnTop: false, // TRY webPreferences: { nodeIntegration: true } }); window.loadURL('file://' + __dirname + '/index.html'); window.setMenu(null); + + window.webContents.on("did-finish-load", function(){ + console.log("connectionInfo:", connectionInfo) + console.log("in did finish loading"); + window.webContents.send('connectionInfo', JSON.stringify(connectionInfo)); + }); - window.once('ready-to-show', () => { - window.show(); - window.webContents.openDevTools() - }) } // This method will be called when Electron has finished // initialization and is ready to create browser windows. +console.log("setting up on ready"); app.on('ready', function() { + console.log("app ready"); createWindow(); - console.log("sending info"); - window.webContents.send('connectionInfo', JSON.stringify(connectionInfo)) -}); \ No newline at end of file +}); +