History

Move the local web entity logic to c++ - might not be working

Zach Fox committed 7 years ago

Commit a41ae3d1 parent 40814f92 files · +66 −4Browse files

Showing the changes to interface/src/scripting/ScreenshareScriptingInterface.cpp (1 of 2 files). Show all

Unified · Split

interface/src/scripting/ScreenshareScriptingInterface.cpp+64−3
@@ -11,11 +11,13 @@ · 10 unmodified lines
1111
1212 #include <QCoreApplication>
1313 #include <QDesktopServices>
14+#include <QJsonDocument>
1415 #include <QThread>
1516 #include <QUrl>
1617
1718 #include <AddressManager.h>
1819
20+#include "EntityScriptingInterface.h"
1921 #include "ScreenshareScriptingInterface.h"
2022
2123 ScreenshareScriptingInterface::ScreenshareScriptingInterface() {
@@ -25,7 +27,11 @@ ScreenshareScriptingInterface::~ScreenshareScriptingInterface() { · 3 unmodified lines
2527 stopScreenshare();
2628 }
2729
28−void ScreenshareScriptingInterface::startScreenshare(const bool& isPresenter) {
30+static const EntityTypes::EntityType LOCAL_SCREENSHARE_WEB_ENTITY_TYPE = EntityTypes::Web;
31+static const uint8_t LOCAL_SCREENSHARE_WEB_ENTITY_FPS = 30;
32+static const glm::vec3 LOCAL_SCREENSHARE_WEB_ENTITY_LOCAL_POSITION(0.0f, 0.0f, 0.1f);
33+static const QString LOCAL_SCREENSHARE_WEB_ENTITY_URL = "https://s3.amazonaws.com/hifi-content/Experiences/Releases/usefulUtilities/smartBoard/screenshareViewer/screenshareClient.html";
34+void ScreenshareScriptingInterface::startScreenshare(const QUuid& screenshareZoneID, const QUuid& smartboardEntityID, const bool& isPresenter) {
2935 if (QThread::currentThread() != thread()) {
3036 // We must start a new QProcess from the main thread.
3137 QMetaObject::invokeMethod(
@@ -79,9 +85,57 @@ void ScreenshareScriptingInterface::startScreenshare(const bool& isPresenter) { · 47 unmodified lines
7985 });
8086
8187 _screenshareProcess->start(SCREENSHARE_EXE_PATH, arguments);
82− } else {
83−
8488 }
89+
90+ if (!_screenshareViewerLocalWebEntityUUID.isNull()) {
91+ return;
92+ }
93+
94+ auto esi = DependencyManager::get<EntityScriptingInterface>();
95+ if (!esi) {
96+ return;
97+ }
98+
99+ EntityItemProperties localScreenshareWebEntityProps;
100+ localScreenshareWebEntityProps.setType(LOCAL_SCREENSHARE_WEB_ENTITY_TYPE);
101+ localScreenshareWebEntityProps.setMaxFPS(LOCAL_SCREENSHARE_WEB_ENTITY_FPS);
102+ localScreenshareWebEntityProps.setLocalPosition(LOCAL_SCREENSHARE_WEB_ENTITY_LOCAL_POSITION);
103+ localScreenshareWebEntityProps.setSourceUrl(LOCAL_SCREENSHARE_WEB_ENTITY_URL);
104+ localScreenshareWebEntityProps.setParentID(smartboardEntityID);
105+
106+ EntityPropertyFlags desiredSmartboardProperties;
107+ desiredSmartboardProperties += PROP_POSITION;
108+ desiredSmartboardProperties += PROP_DIMENSIONS;
109+ EntityItemProperties smartboardProps = esi->getEntityProperties(smartboardEntityID, desiredSmartboardProperties);
110+
111+ localScreenshareWebEntityProps.setPosition(smartboardProps.getPosition());
112+ localScreenshareWebEntityProps.setDimensions(smartboardProps.getDimensions());
113+
114+ _screenshareViewerLocalWebEntityUUID = esi->addEntity(localScreenshareWebEntityProps, "local");
115+
116+ QObject::connect(esi.data(), &EntityScriptingInterface::webEventReceived, this, [&](const QUuid& entityID, const QVariant& message) {
117+ if (entityID == _screenshareViewerLocalWebEntityUUID) {
118+ auto esi = DependencyManager::get<EntityScriptingInterface>();
119+ if (!esi) {
120+ return;
121+ }
122+
123+ QJsonDocument jsonMessage = QJsonDocument::fromVariant(message);
124+ QJsonObject jsonObject = jsonMessage.object();
125+
126+ if (jsonObject["type"] == "eventbridge_ready") {
127+ QJsonObject responseObject;
128+ responseObject.insert("type", "receiveConnectionInfo");
129+ QJsonObject responseObjectData;
130+ responseObjectData.insert("token", token);
131+ responseObjectData.insert("projectAPIKey", apiKey);
132+ responseObjectData.insert("sessionID", sessionID);
133+ responseObject.insert("data", responseObjectData);
134+
135+ esi->emitScriptEvent(_screenshareViewerLocalWebEntityUUID, responseObject.toVariantMap());
136+ }
137+ }
138+ });
85139 };
86140
87141 void ScreenshareScriptingInterface::stopScreenshare() {
@@ -93,4 +147,11 @@ void ScreenshareScriptingInterface::stopScreenshare() { · 5 unmodified lines
93147 if (_screenshareProcess && _screenshareProcess->state() != QProcess::NotRunning) {
94148 _screenshareProcess->terminate();
95149 }
150+
151+ if (!_screenshareViewerLocalWebEntityUUID.isNull()) {
152+ auto esi = DependencyManager::get<EntityScriptingInterface>();
153+ if (esi) {
154+ esi->deleteEntity(_screenshareViewerLocalWebEntityUUID);
155+ }
156+ }
96157 }