History

Initial path to fixing screenshare auth race condition

Zach Fox committed 6 years ago

Commit c96c6841 parent f01a39a6 files · +86 −12Browse files

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

Unified · Split

interface/src/scripting/ScreenshareScriptingInterface.cpp+28−0
@@ -37,14 +37,41 @@ ScreenshareScriptingInterface::ScreenshareScriptingInterface() { · 36 unmodified lines
3737 _requestScreenshareInfoRetryTimer->setSingleShot(true);
3838 _requestScreenshareInfoRetryTimer->setInterval(SCREENSHARE_INFO_REQUEST_RETRY_TIMEOUT_MS);
3939 connect(_requestScreenshareInfoRetryTimer, &QTimer::timeout, this, &ScreenshareScriptingInterface::requestScreenshareInfo);
40+
41+ auto nodeList = DependencyManager::get<NodeList>();
42+ PacketReceiver& packetReceiver = nodeList->getPacketReceiver();
43+ packetReceiver.registerListener(PacketType::AvatarZonePresence, this, "processAvatarZonePresencePacketOnClient");
4044 };
4145
4246 ScreenshareScriptingInterface::~ScreenshareScriptingInterface() {
4347 stopScreenshare();
4448 }
4549
50+void ScreenshareScriptingInterface::processAvatarZonePresencePacketOnClient(QSharedPointer<ReceivedMessage> message, SharedNodePointer senderNode) {
51+ QUuid zone = QUuid::fromRfc4122(message->readWithoutCopy(NUM_BYTES_RFC4122_UUID));
52+
53+ if (zone.isNull()) {
54+ qWarning() << "Ignoring avatar zone presence packet that doesn't specify a zone.";
55+ return;
56+ }
57+
58+ _lastAuthorizedZoneID = zone;
59+
60+ if (_waitingForAuthorization) {
61+ requestScreenshareInfo();
62+ }
63+}
64+
4665 static const int MAX_NUM_SCREENSHARE_INFO_REQUEST_RETRIES = 5;
4766 void ScreenshareScriptingInterface::requestScreenshareInfo() {
67+ if (_screenshareZoneID != _lastAuthorizedZoneID) {
68+ qDebug() << "Client not yet authorized to screenshare. Waiting for authorization message from domain server...";
69+ _waitingForAuthorization = true;
70+ return;
71+ }
72+
73+ _waitingForAuthorization = false;
74+
4875 _requestScreenshareInfoRetries++;
4976
5077 if (_requestScreenshareInfoRetries >= MAX_NUM_SCREENSHARE_INFO_REQUEST_RETRIES) {
@@ -174,6 +201,7 @@ void ScreenshareScriptingInterface::stopScreenshare() { · 123 unmodified lines
174201 _projectAPIKey = "";
175202 _sessionID = "";
176203 _isPresenter = false;
204+ _waitingForAuthorization = false;
177205 }
178206
179207 // Called when the Metaverse returns the information necessary to start/view a screen share.