working flow. Needs clean up and final ui tweaks

This commit is contained in:
milad 2019-11-11 20:13:23 -08:00
parent ae35ec0975
commit 7cce153b6d
3 changed files with 98 additions and 81 deletions

View file

@ -12,6 +12,7 @@
#include <QCoreApplication>
#include <QDesktopServices>
#include <QJsonDocument>
#include <QJsonObject>
#include <QThread>
#include <QUrl>
#include <QObject>
@ -31,8 +32,7 @@
#include <RenderableTextEntityItem.h>
#include <RenderableWebEntityItem.h>
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<int, QProcess::ExitStatus>::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<EntityScriptingInterface>();
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<EntityScriptingInterface>();
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<EntityScriptingInterface>();
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<EntityScriptingInterface>();
esi->emitScriptEvent(_screenshareViewerLocalWebEntityUUID, responseObject.toVariantMap());
// atempt 2, same outcome
auto entityTreeRenderer = DependencyManager::get<EntityTreeRenderer>();
auto webEntityRenderable = entityTreeRenderer->renderableForEntityId(_screenshareViewerLocalWebEntityUUID);
webEntityRenderable->emitScriptEvent(responseObject.toVariantMap());
}
}
});
// atempt 2, same outcome
//auto entityTreeRenderer = DependencyManager::get<EntityTreeRenderer>();
//auto webEntityRenderable =
// entityTreeRenderer->renderableForEntityId(_screenshareViewerLocalWebEntityUUID);
//webEntityRenderable->emitScriptEvent(responseObject.toVariantMap());
}
}
});
});
QNetworkRequest request;

View file

@ -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")

View file

@ -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))
});
});