Improved HTTP request to proper endpoint - won't work until PR16459 is merged

This commit is contained in:
Zach Fox 2019-11-12 17:06:35 -08:00
parent ea8e285793
commit b0c578aa7f
2 changed files with 131 additions and 99 deletions

View file

@ -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,30 +83,74 @@ 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) {
if (reply->error()) {
qDebug() << "\n\n MN HERE: REPLY" << reply->errorString();
return; return;
} }
QString currentDomainID = uuidStringWithoutCurlyBraces(addressManager->getDomainID());
QString requestURLPath = "api/v1/domains";
requestURLPath = requestURLPath.append(currentDomainID);
requestURLPath = requestURLPath.append("/screenshare");
JSONCallbackParameters callbackParams;
callbackParams.callbackReceiver = this;
callbackParams.jsonCallbackMethod = "handleSuccessfulScreenshareInfoGet";
callbackParams.errorCallbackMethod = "handleFailedScreenshareInfoGet";
accountManager->sendRequest(
requestURLPath,
AccountManagerAuth::Required,
QNetworkAccessManager::PutOperation,
callbackParams
);
}
void ScreenshareScriptingInterface::stopScreenshare() {
if (QThread::currentThread() != thread()) {
QMetaObject::invokeMethod(this, "stopScreenshare");
return;
}
if (_screenshareProcess && _screenshareProcess->state() != QProcess::NotRunning) {
_screenshareProcess->terminate();
}
if (!_screenshareViewerLocalWebEntityUUID.isNull()) {
auto esi = DependencyManager::get<EntityScriptingInterface>();
if (esi) {
esi->deleteEntity(_screenshareViewerLocalWebEntityUUID);
}
}
_screenshareViewerLocalWebEntityUUID = "{00000000-0000-0000-0000-000000000000}";
_token = "";
_projectAPIKey = "";
_sessionID = "";
_isPresenter = false;
}
void ScreenshareScriptingInterface::handleSuccessfulScreenshareInfoGet(QNetworkReply* reply) {
QString answer = reply->readAll(); QString answer = reply->readAll();
qDebug() << "\n\n MN HERE: REPLY" << answer; qDebug() << "\n\n MN HERE: REPLY" << answer;
QByteArray answerByteArray = answer.toUtf8(); QByteArray answerByteArray = answer.toUtf8();
QJsonDocument answerJSONObject = QJsonDocument::fromJson(answerByteArray); 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(); _token = answerJSONObject["token"].toString();
_projectAPIKey = answerJSONObject["projectAPIKey"].toString(); _projectAPIKey = answerJSONObject["projectAPIKey"].toString();
_sessionID = answerJSONObject["sessionID"].toString(); _sessionID = answerJSONObject["sessionID"].toString();
qDebug() << "token:" << _token << " projectAPIKey:" << _projectAPIKey << " sessionID: " << _sessionID; qDebug() << "token:" << _token << " projectAPIKey:" << _projectAPIKey << " sessionID: " << _sessionID;
if (isPresenter) { if (_isPresenter) {
QStringList arguments; QStringList arguments;
arguments << " "; arguments << " ";
arguments << "--token=" + _token << " "; arguments << "--token=" + _token << " ";
@ -136,9 +186,10 @@ void ScreenshareScriptingInterface::startScreenshare(const QUuid& screenshareZon
localScreenshareWebEntityProps.setMaxFPS(LOCAL_SCREENSHARE_WEB_ENTITY_FPS); localScreenshareWebEntityProps.setMaxFPS(LOCAL_SCREENSHARE_WEB_ENTITY_FPS);
localScreenshareWebEntityProps.setLocalPosition(LOCAL_SCREENSHARE_WEB_ENTITY_LOCAL_POSITION); localScreenshareWebEntityProps.setLocalPosition(LOCAL_SCREENSHARE_WEB_ENTITY_LOCAL_POSITION);
localScreenshareWebEntityProps.setSourceUrl(LOCAL_SCREENSHARE_WEB_ENTITY_URL); localScreenshareWebEntityProps.setSourceUrl(LOCAL_SCREENSHARE_WEB_ENTITY_URL);
localScreenshareWebEntityProps.setParentID(smartboardEntityID); localScreenshareWebEntityProps.setParentID(_smartboardEntityID);
localScreenshareWebEntityProps.setDimensions(LOCAL_SCREENSHARE_WEB_ENTITY_DIMENSIONS); 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; //EntityPropertyFlags desiredSmartboardProperties;
//desiredSmartboardProperties += PROP_POSITION; //desiredSmartboardProperties += PROP_POSITION;
//desiredSmartboardProperties += PROP_DIMENSIONS; //desiredSmartboardProperties += PROP_DIMENSIONS;
@ -146,33 +197,10 @@ void ScreenshareScriptingInterface::startScreenshare(const QUuid& screenshareZon
QString hostType = "local"; QString hostType = "local";
_screenshareViewerLocalWebEntityUUID = esi->addEntity(localScreenshareWebEntityProps, hostType); _screenshareViewerLocalWebEntityUUID = esi->addEntity(localScreenshareWebEntityProps, hostType);
QNetworkRequest request;
QString tokboxURL = QProcessEnvironment::systemEnvironment().value("hifiScreenshareUrl");
request.setUrl(QUrl(tokboxURL));
manager->get(request);
};
void ScreenshareScriptingInterface::stopScreenshare() {
if (QThread::currentThread() != thread()) {
QMetaObject::invokeMethod(this, "stopScreenshare");
return;
} }
if (_screenshareProcess && _screenshareProcess->state() != QProcess::NotRunning) { void ScreenshareScriptingInterface::handleFailedScreenshareInfoGet(QNetworkReply* reply) {
_screenshareProcess->terminate(); qDebug() << "\n\n MN HERE: handleFailedScreenshareInfoGet():" << reply->errorString();
}
if (!_screenshareViewerLocalWebEntityUUID.isNull()) {
auto esi = DependencyManager::get<EntityScriptingInterface>();
if (esi) {
esi->deleteEntity(_screenshareViewerLocalWebEntityUUID);
}
}
_screenshareViewerLocalWebEntityUUID = "{00000000-0000-0000-0000-000000000000}";
_token = "";
_projectAPIKey = "";
_sessionID = "";
} }
void ScreenshareScriptingInterface::onWebEventReceived(const QUuid& entityID, const QVariant& message) { void ScreenshareScriptingInterface::onWebEventReceived(const QUuid& entityID, const QVariant& message) {
@ -204,4 +232,3 @@ void ScreenshareScriptingInterface::onWebEventReceived(const QUuid& entityID, co
} }
} }
} }
}

View file

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