mirror of
https://github.com/JulianGro/overte.git
synced 2025-05-07 08:20:13 +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 <QProcessEnvironment>
|
||||
|
||||
#include <AccountManager.h>
|
||||
#include <AddressManager.h>
|
||||
#include <EntityTreeRenderer.h>
|
||||
#include <EntityTree.h>
|
||||
#include <UUID.h>
|
||||
|
||||
#include "EntityScriptingInterface.h"
|
||||
#include "ScreenshareScriptingInterface.h"
|
||||
|
@ -63,11 +65,15 @@ void ScreenshareScriptingInterface::startScreenshare(const QUuid& screenshareZon
|
|||
return;
|
||||
}
|
||||
|
||||
if (isPresenter && _screenshareProcess && _screenshareProcess->state() != QProcess::NotRunning) {
|
||||
_screenshareZoneID = screenshareZoneID;
|
||||
_smartboardEntityID = smartboardEntityID;
|
||||
_isPresenter = isPresenter;
|
||||
|
||||
if (_isPresenter && _screenshareProcess && _screenshareProcess->state() != QProcess::NotRunning) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isPresenter) {
|
||||
if (_isPresenter) {
|
||||
_screenshareProcess.reset(new QProcess(this));
|
||||
|
||||
QFileInfo screenshareExecutable(SCREENSHARE_EXE_PATH);
|
||||
|
@ -77,30 +83,74 @@ void ScreenshareScriptingInterface::startScreenshare(const QUuid& screenshareZon
|
|||
}
|
||||
}
|
||||
|
||||
QUuid currentDomainID = DependencyManager::get<AddressManager>()->getDomainID();
|
||||
// `https://metaverse.highfidelity.com/api/v1/domain/:domain_id/screenshare`,
|
||||
// passing the Domain ID that the user is connected to, as well as the `roomName`.
|
||||
// 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.
|
||||
QNetworkAccessManager* manager = new QNetworkAccessManager();
|
||||
QObject::connect(manager, &QNetworkAccessManager::finished, this, [=](QNetworkReply* reply) {
|
||||
if (reply->error()) {
|
||||
qDebug() << "\n\n MN HERE: REPLY" << reply->errorString();
|
||||
auto accountManager = DependencyManager::get<AccountManager>();
|
||||
if (!accountManager) {
|
||||
return;
|
||||
}
|
||||
auto addressManager = DependencyManager::get<AddressManager>();
|
||||
if (!addressManager) {
|
||||
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();
|
||||
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) {
|
||||
if (_isPresenter) {
|
||||
QStringList arguments;
|
||||
arguments << " ";
|
||||
arguments << "--token=" + _token << " ";
|
||||
|
@ -136,9 +186,10 @@ void ScreenshareScriptingInterface::startScreenshare(const QUuid& screenshareZon
|
|||
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.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;
|
||||
|
@ -146,33 +197,10 @@ void ScreenshareScriptingInterface::startScreenshare(const QUuid& screenshareZon
|
|||
|
||||
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() {
|
||||
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 = "";
|
||||
void ScreenshareScriptingInterface::handleFailedScreenshareInfoGet(QNetworkReply* reply) {
|
||||
qDebug() << "\n\n MN HERE: handleFailedScreenshareInfoGet():" << reply->errorString();
|
||||
}
|
||||
|
||||
void ScreenshareScriptingInterface::onWebEventReceived(const QUuid& entityID, const QVariant& message) {
|
||||
|
@ -204,4 +232,3 @@ void ScreenshareScriptingInterface::onWebEventReceived(const QUuid& entityID, co
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,6 +36,8 @@ signals:
|
|||
|
||||
private slots:
|
||||
void onWebEventReceived(const QUuid& entityID, const QVariant& message);
|
||||
void handleSuccessfulScreenshareInfoGet(QNetworkReply* reply);
|
||||
void handleFailedScreenshareInfoGet(QNetworkReply* reply);
|
||||
|
||||
private:
|
||||
#if DEV_BUILD
|
||||
|
@ -63,6 +65,9 @@ private:
|
|||
QString _token{ "" };
|
||||
QString _projectAPIKey{ "" };
|
||||
QString _sessionID{ "" };
|
||||
QUuid _screenshareZoneID;
|
||||
QUuid _smartboardEntityID;
|
||||
bool _isPresenter{ false };
|
||||
};
|
||||
|
||||
#endif // hifi_ScreenshareScriptingInterface_h
|
Loading…
Reference in a new issue