mirror of
https://github.com/overte-org/overte.git
synced 2025-08-07 18:10:37 +02:00
Improved HTTP request to proper endpoint - won't work until PR16459 is merged
This commit is contained in:
parent
ea8e285793
commit
b0c578aa7f
2 changed files with 131 additions and 99 deletions
|
@ -21,9 +21,11 @@
|
||||||
#include <QNetworkRequest>
|
#include <QNetworkRequest>
|
||||||
#include <QProcessEnvironment>
|
#include <QProcessEnvironment>
|
||||||
|
|
||||||
|
#include <AccountManager.h>
|
||||||
#include <AddressManager.h>
|
#include <AddressManager.h>
|
||||||
#include <EntityTreeRenderer.h>
|
#include <EntityTreeRenderer.h>
|
||||||
#include <EntityTree.h>
|
#include <EntityTree.h>
|
||||||
|
#include <UUID.h>
|
||||||
|
|
||||||
#include "EntityScriptingInterface.h"
|
#include "EntityScriptingInterface.h"
|
||||||
#include "ScreenshareScriptingInterface.h"
|
#include "ScreenshareScriptingInterface.h"
|
||||||
|
@ -63,11 +65,15 @@ void ScreenshareScriptingInterface::startScreenshare(const QUuid& screenshareZon
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isPresenter && _screenshareProcess && _screenshareProcess->state() != QProcess::NotRunning) {
|
_screenshareZoneID = screenshareZoneID;
|
||||||
|
_smartboardEntityID = smartboardEntityID;
|
||||||
|
_isPresenter = isPresenter;
|
||||||
|
|
||||||
|
if (_isPresenter && _screenshareProcess && _screenshareProcess->state() != QProcess::NotRunning) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isPresenter) {
|
if (_isPresenter) {
|
||||||
_screenshareProcess.reset(new QProcess(this));
|
_screenshareProcess.reset(new QProcess(this));
|
||||||
|
|
||||||
QFileInfo screenshareExecutable(SCREENSHARE_EXE_PATH);
|
QFileInfo screenshareExecutable(SCREENSHARE_EXE_PATH);
|
||||||
|
@ -77,81 +83,31 @@ void ScreenshareScriptingInterface::startScreenshare(const QUuid& screenshareZon
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QUuid currentDomainID = DependencyManager::get<AddressManager>()->getDomainID();
|
auto accountManager = DependencyManager::get<AccountManager>();
|
||||||
// `https://metaverse.highfidelity.com/api/v1/domain/:domain_id/screenshare`,
|
if (!accountManager) {
|
||||||
// passing the Domain ID that the user is connected to, as well as the `roomName`.
|
return;
|
||||||
// The server will respond with the relevant OpenTok , Session ID, and API Key.
|
}
|
||||||
// Upon error-free response, do the logic below, passing in that info as necessary.
|
auto addressManager = DependencyManager::get<AddressManager>();
|
||||||
QNetworkAccessManager* manager = new QNetworkAccessManager();
|
if (!addressManager) {
|
||||||
QObject::connect(manager, &QNetworkAccessManager::finished, this, [=](QNetworkReply* reply) {
|
return;
|
||||||
if (reply->error()) {
|
}
|
||||||
qDebug() << "\n\n MN HERE: REPLY" << reply->errorString();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString answer = reply->readAll();
|
QString currentDomainID = uuidStringWithoutCurlyBraces(addressManager->getDomainID());
|
||||||
qDebug() << "\n\n MN HERE: REPLY" << answer;
|
QString requestURLPath = "api/v1/domains";
|
||||||
|
requestURLPath = requestURLPath.append(currentDomainID);
|
||||||
|
requestURLPath = requestURLPath.append("/screenshare");
|
||||||
|
|
||||||
QByteArray answerByteArray = answer.toUtf8();
|
JSONCallbackParameters callbackParams;
|
||||||
QJsonDocument answerJSONObject = QJsonDocument::fromJson(answerByteArray);
|
callbackParams.callbackReceiver = this;
|
||||||
|
callbackParams.jsonCallbackMethod = "handleSuccessfulScreenshareInfoGet";
|
||||||
_token = answerJSONObject["token"].toString();
|
callbackParams.errorCallbackMethod = "handleFailedScreenshareInfoGet";
|
||||||
_projectAPIKey = answerJSONObject["projectAPIKey"].toString();
|
accountManager->sendRequest(
|
||||||
_sessionID = answerJSONObject["sessionID"].toString();
|
requestURLPath,
|
||||||
qDebug() << "token:" << _token << " projectAPIKey:" << _projectAPIKey << " sessionID: " << _sessionID;
|
AccountManagerAuth::Required,
|
||||||
|
QNetworkAccessManager::PutOperation,
|
||||||
if (isPresenter) {
|
callbackParams
|
||||||
QStringList arguments;
|
);
|
||||||
arguments << " ";
|
}
|
||||||
arguments << "--token=" + _token << " ";
|
|
||||||
arguments << "--projectAPIKey=" + _projectAPIKey << " ";
|
|
||||||
arguments << "--sessionID=" + _sessionID << " ";
|
|
||||||
|
|
||||||
connect(_screenshareProcess.get(), &QProcess::errorOccurred,
|
|
||||||
[=](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(), QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
|
|
||||||
[=](int exitCode, QProcess::ExitStatus exitStatus) {
|
|
||||||
qDebug() << "ZRF QProcess::finished. `exitCode`:" << exitCode << "`exitStatus`:" << exitStatus;
|
|
||||||
emit screenshareStopped();
|
|
||||||
});
|
|
||||||
|
|
||||||
_screenshareProcess->start(SCREENSHARE_EXE_PATH, arguments);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!_screenshareViewerLocalWebEntityUUID.isNull()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto esi = DependencyManager::get<EntityScriptingInterface>();
|
|
||||||
if (!esi) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
EntityItemProperties localScreenshareWebEntityProps;
|
|
||||||
localScreenshareWebEntityProps.setType(LOCAL_SCREENSHARE_WEB_ENTITY_TYPE);
|
|
||||||
localScreenshareWebEntityProps.setMaxFPS(LOCAL_SCREENSHARE_WEB_ENTITY_FPS);
|
|
||||||
localScreenshareWebEntityProps.setLocalPosition(LOCAL_SCREENSHARE_WEB_ENTITY_LOCAL_POSITION);
|
|
||||||
localScreenshareWebEntityProps.setSourceUrl(LOCAL_SCREENSHARE_WEB_ENTITY_URL);
|
|
||||||
localScreenshareWebEntityProps.setParentID(smartboardEntityID);
|
|
||||||
localScreenshareWebEntityProps.setDimensions(LOCAL_SCREENSHARE_WEB_ENTITY_DIMENSIONS);
|
|
||||||
|
|
||||||
// EntityPropertyFlags desiredSmartboardProperties;
|
|
||||||
// desiredSmartboardProperties += PROP_POSITION;
|
|
||||||
// desiredSmartboardProperties += PROP_DIMENSIONS;
|
|
||||||
// EntityItemProperties smartboardProps = esi->getEntityProperties(smartboardEntityID, desiredSmartboardProperties);
|
|
||||||
|
|
||||||
QString hostType = "local";
|
|
||||||
_screenshareViewerLocalWebEntityUUID = esi->addEntity(localScreenshareWebEntityProps, hostType);
|
|
||||||
|
|
||||||
QNetworkRequest request;
|
|
||||||
QString tokboxURL = QProcessEnvironment::systemEnvironment().value("hifiScreenshareUrl");
|
|
||||||
request.setUrl(QUrl(tokboxURL));
|
|
||||||
manager->get(request);
|
|
||||||
};
|
|
||||||
|
|
||||||
void ScreenshareScriptingInterface::stopScreenshare() {
|
void ScreenshareScriptingInterface::stopScreenshare() {
|
||||||
if (QThread::currentThread() != thread()) {
|
if (QThread::currentThread() != thread()) {
|
||||||
|
@ -173,35 +129,106 @@ void ScreenshareScriptingInterface::stopScreenshare() {
|
||||||
_token = "";
|
_token = "";
|
||||||
_projectAPIKey = "";
|
_projectAPIKey = "";
|
||||||
_sessionID = "";
|
_sessionID = "";
|
||||||
|
_isPresenter = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScreenshareScriptingInterface::handleSuccessfulScreenshareInfoGet(QNetworkReply* reply) {
|
||||||
|
QString answer = reply->readAll();
|
||||||
|
qDebug() << "\n\n MN HERE: REPLY" << answer;
|
||||||
|
|
||||||
|
QByteArray answerByteArray = answer.toUtf8();
|
||||||
|
QJsonDocument answerJSONObject = QJsonDocument::fromJson(answerByteArray);
|
||||||
|
|
||||||
|
QString status = answerJSONObject["status"].toString();
|
||||||
|
if (status == "fail") {
|
||||||
|
qDebug() << "\n\n MN HERE: SCREENSHARE REPLY FAIL";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_token = answerJSONObject["token"].toString();
|
||||||
|
_projectAPIKey = answerJSONObject["projectAPIKey"].toString();
|
||||||
|
_sessionID = answerJSONObject["sessionID"].toString();
|
||||||
|
qDebug() << "token:" << _token << " projectAPIKey:" << _projectAPIKey << " sessionID: " << _sessionID;
|
||||||
|
|
||||||
|
if (_isPresenter) {
|
||||||
|
QStringList arguments;
|
||||||
|
arguments << " ";
|
||||||
|
arguments << "--token=" + _token << " ";
|
||||||
|
arguments << "--projectAPIKey=" + _projectAPIKey << " ";
|
||||||
|
arguments << "--sessionID=" + _sessionID << " ";
|
||||||
|
|
||||||
|
connect(_screenshareProcess.get(), &QProcess::errorOccurred,
|
||||||
|
[=](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(), QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
|
||||||
|
[=](int exitCode, QProcess::ExitStatus exitStatus) {
|
||||||
|
qDebug() << "ZRF QProcess::finished. `exitCode`:" << exitCode << "`exitStatus`:" << exitStatus;
|
||||||
|
emit screenshareStopped();
|
||||||
|
});
|
||||||
|
|
||||||
|
_screenshareProcess->start(SCREENSHARE_EXE_PATH, arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!_screenshareViewerLocalWebEntityUUID.isNull()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto esi = DependencyManager::get<EntityScriptingInterface>();
|
||||||
|
if (!esi) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
EntityItemProperties localScreenshareWebEntityProps;
|
||||||
|
localScreenshareWebEntityProps.setType(LOCAL_SCREENSHARE_WEB_ENTITY_TYPE);
|
||||||
|
localScreenshareWebEntityProps.setMaxFPS(LOCAL_SCREENSHARE_WEB_ENTITY_FPS);
|
||||||
|
localScreenshareWebEntityProps.setLocalPosition(LOCAL_SCREENSHARE_WEB_ENTITY_LOCAL_POSITION);
|
||||||
|
localScreenshareWebEntityProps.setSourceUrl(LOCAL_SCREENSHARE_WEB_ENTITY_URL);
|
||||||
|
localScreenshareWebEntityProps.setParentID(_smartboardEntityID);
|
||||||
|
localScreenshareWebEntityProps.setDimensions(LOCAL_SCREENSHARE_WEB_ENTITY_DIMENSIONS);
|
||||||
|
|
||||||
|
// The lines below will be used when writing the feature to ensure that the smartboard can be of any arbitrary size.
|
||||||
|
//EntityPropertyFlags desiredSmartboardProperties;
|
||||||
|
//desiredSmartboardProperties += PROP_POSITION;
|
||||||
|
//desiredSmartboardProperties += PROP_DIMENSIONS;
|
||||||
|
//EntityItemProperties smartboardProps = esi->getEntityProperties(smartboardEntityID, desiredSmartboardProperties);
|
||||||
|
|
||||||
|
QString hostType = "local";
|
||||||
|
_screenshareViewerLocalWebEntityUUID = esi->addEntity(localScreenshareWebEntityProps, hostType);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScreenshareScriptingInterface::handleFailedScreenshareInfoGet(QNetworkReply* reply) {
|
||||||
|
qDebug() << "\n\n MN HERE: handleFailedScreenshareInfoGet():" << reply->errorString();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenshareScriptingInterface::onWebEventReceived(const QUuid& entityID, const QVariant& message) {
|
void ScreenshareScriptingInterface::onWebEventReceived(const QUuid& entityID, const QVariant& message) {
|
||||||
if (entityID == _screenshareViewerLocalWebEntityUUID) {
|
if (entityID == _screenshareViewerLocalWebEntityUUID) {
|
||||||
|
auto esi = DependencyManager::get<EntityScriptingInterface>();
|
||||||
|
if (!esi) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QByteArray jsonByteArray = QVariant(message).toString().toUtf8();
|
||||||
|
QJsonDocument jsonObject = QJsonDocument::fromJson(jsonByteArray);
|
||||||
|
|
||||||
|
if (jsonObject["app"] != "screenshare") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (jsonObject["method"] == "eventBridgeReady") {
|
||||||
|
QJsonObject responseObject;
|
||||||
|
responseObject.insert("app", "screenshare");
|
||||||
|
responseObject.insert("method", "receiveConnectionInfo");
|
||||||
|
QJsonObject responseObjectData;
|
||||||
|
responseObjectData.insert("token", _token);
|
||||||
|
responseObjectData.insert("projectAPIKey", _projectAPIKey);
|
||||||
|
responseObjectData.insert("sessionID", _sessionID);
|
||||||
|
responseObject.insert("data", responseObjectData);
|
||||||
|
|
||||||
auto esi = DependencyManager::get<EntityScriptingInterface>();
|
auto esi = DependencyManager::get<EntityScriptingInterface>();
|
||||||
if (!esi) {
|
esi->emitScriptEvent(_screenshareViewerLocalWebEntityUUID, responseObject.toVariantMap());
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QByteArray jsonByteArray = QVariant(message).toString().toUtf8();
|
|
||||||
QJsonDocument jsonObject = QJsonDocument::fromJson(jsonByteArray);
|
|
||||||
|
|
||||||
if (jsonObject["app"] != "screenshare") {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (jsonObject["method"] == "eventBridgeReady") {
|
|
||||||
QJsonObject responseObject;
|
|
||||||
responseObject.insert("app", "screenshare");
|
|
||||||
responseObject.insert("method", "receiveConnectionInfo");
|
|
||||||
QJsonObject responseObjectData;
|
|
||||||
responseObjectData.insert("token", _token);
|
|
||||||
responseObjectData.insert("projectAPIKey", _projectAPIKey);
|
|
||||||
responseObjectData.insert("sessionID", _sessionID);
|
|
||||||
responseObject.insert("data", responseObjectData);
|
|
||||||
|
|
||||||
auto esi = DependencyManager::get<EntityScriptingInterface>();
|
|
||||||
esi->emitScriptEvent(_screenshareViewerLocalWebEntityUUID, responseObject.toVariantMap());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,8 @@ signals:
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onWebEventReceived(const QUuid& entityID, const QVariant& message);
|
void onWebEventReceived(const QUuid& entityID, const QVariant& message);
|
||||||
|
void handleSuccessfulScreenshareInfoGet(QNetworkReply* reply);
|
||||||
|
void handleFailedScreenshareInfoGet(QNetworkReply* reply);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
#if DEV_BUILD
|
#if DEV_BUILD
|
||||||
|
@ -63,6 +65,9 @@ private:
|
||||||
QString _token{ "" };
|
QString _token{ "" };
|
||||||
QString _projectAPIKey{ "" };
|
QString _projectAPIKey{ "" };
|
||||||
QString _sessionID{ "" };
|
QString _sessionID{ "" };
|
||||||
|
QUuid _screenshareZoneID;
|
||||||
|
QUuid _smartboardEntityID;
|
||||||
|
bool _isPresenter{ false };
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_ScreenshareScriptingInterface_h
|
#endif // hifi_ScreenshareScriptingInterface_h
|
Loading…
Reference in a new issue