Skip to content

Commit

Permalink
fixed VRCollaboration connection issue induced by asnc changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor-Haefner committed Sep 8, 2022
1 parent 1c4d7a7 commit 1ffca98
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 15 deletions.
33 changes: 27 additions & 6 deletions src/core/networking/VRCollaboration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "core/utils/toString.h"

#include "tcp/VRICEclient.h"
#include "tcp/VRTCPClient.h"
#include "core/objects/sync/VRSyncNode.h"
#include "core/objects/geometry/sprite/VRSprite.h"
#include "core/objects/material/VRMaterial.h"
Expand Down Expand Up @@ -144,10 +145,27 @@ void VRCollaboration::setupAvatar(string rID, string name) {

void VRCollaboration::connectTCP(string origin) {
#ifndef WITHOUT_GTK
VRConsoleWidget::get("Collaboration")->write( " ..connect TCP sync node and audio, setup avatar, origin: "+origin+"\n");
VRConsoleWidget::get("Collaboration")->write( "Collab: connect TCP sync node and audio, setup avatar of origin "+origin+"'\n");
#endif

auto rID = syncNode->addTCPClient(ice->getClient(origin, VRICEClient::SCENEGRAPH));
auto cli = ice->getClient(origin, VRICEClient::SCENEGRAPH);
auto client = dynamic_pointer_cast<VRTCPClient>(cli);

if (!client) {
#ifndef WITHOUT_GTK
VRConsoleWidget::get("Collaboration")->write( "Collab: no TCP client found for origin '"+origin+"'\n", "red");
#endif
return;
}

if (!client->connected()) {
#ifndef WITHOUT_GTK
VRConsoleWidget::get("Collaboration")->write( "Collab: TCP client found for origin '"+origin+"' is not connected!\n", "red");
#endif
return;
}

auto rID = syncNode->addTCPClient(client);
auto name = ice->getUserName(origin);
setupAvatar(rID, name);

Expand Down Expand Up @@ -255,7 +273,7 @@ bool VRCollaboration::handleUI(VRDeviceWeakPtr wdev) {
userName = splitString(m, '|')[1];
userNameWidget->hide();
userlist->show();
ice->setName(userName);
ice->setName(userName, false);
updateUsersWidget();
}

Expand Down Expand Up @@ -296,22 +314,25 @@ vector<string> VRCollaboration::parseSubNet(string net) {
}

void VRCollaboration::acceptConnection() {
#ifndef WITHOUT_GTK
VRConsoleWidget::get("Collaboration")->write( "Collab: accepting incomming connection, connect ice to origin!\n");
#endif
string net = getSubnet();
for (auto node : connReqNet) {
sendUI("usersList", "setUserStats|"+node+"|#2c4");
ice->connectTo(node);
ice->connectTo(node, false);
ice->send(node, "CONACC$"+net);
connectTCP(node);
}
}

void VRCollaboration::finishConnection(string origin, vector<string> net) {
#ifndef WITHOUT_GTK
VRConsoleWidget::get("Collaboration")->write( " GOT CONACC connect ice to origin!\n");
VRConsoleWidget::get("Collaboration")->write( "Collab: got CONACC, connect ice to origin!\n");
#endif
for (auto node : net) {
sendUI("usersList", "setUserStats|"+node+"|#2c4");
ice->connectTo(node);
ice->connectTo(node, false);
connectTCP(node);
if (node != origin) ice->send(node, "CONACC$"+ice->getID());
}
Expand Down
16 changes: 11 additions & 5 deletions src/core/networking/tcp/VRICEclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ void VRICEClient::processNameset(string data) {

void VRICEClient::processRespNameset(VRRestResponsePtr r) { processNameset(r->getData()); }

void VRICEClient::setName(string n) {
void VRICEClient::setName(string n, bool async) {
name = n;
bool async = true;

if (!async) {
string data = broker->get(turnURL+"/regUser.php?NAME="+n)->getData();
Expand Down Expand Up @@ -230,7 +229,15 @@ void VRICEClient::processConnect(string data, string uid2) {
#ifndef WITHOUT_GTK
VRConsoleWidget::get("Collaboration")->write( " ICE "+name+"("+uid1+"): connect to "+users[uid2]+"("+uid2+") over "+turnIP+":"+toString(port1)+", received '"+data+"'\n");
#endif
getClient(uid2, SCENEGRAPH)->connect(turnIP, port1);
auto cli = getClient(uid2, SCENEGRAPH);
auto client = dynamic_pointer_cast<VRTCPClient>(cli);
client->connect(turnIP, port1);

if (!client->connected()) {
#ifndef WITHOUT_GTK
VRConsoleWidget::get("Collaboration")->write( " ICE "+name+"("+uid1+"): connection to "+users[uid2]+"("+uid2+") failed!\n", "red");
#endif
}

if (params.size() >= 3) {
int port2 = toInt( params[3] );
Expand All @@ -247,7 +254,7 @@ void VRICEClient::processConnect(string data, string uid2) {

void VRICEClient::processRespConnect(VRRestResponsePtr r, string uid2) { processConnect(r->getData(), uid2); }

void VRICEClient::connectTo(string otherID) {
void VRICEClient::connectTo(string otherID, bool async) {
if (uID == "" || otherID == "") {
cout << "VRICEClient::connectTo failed, empty ID" << endl;
#ifndef WITHOUT_GTK
Expand Down Expand Up @@ -276,7 +283,6 @@ void VRICEClient::connectTo(string otherID) {
return;
}

bool async = true;
if (!async) {
string data = broker->get(turnURL+"/getConnection.php?UID="+uid1+"&UID2="+uid2)->getData();
processConnect(data, uid2);
Expand Down
4 changes: 2 additions & 2 deletions src/core/networking/tcp/VRICEclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ class VRICEClient : public VRNetworkClient {
void onEvent( function<void(string)> f );
void onMessage( function<void(string)> f );

void setName(string name);
void connectTo(string other);
void setName(string name, bool async);
void connectTo(string other, bool async);
void sendTCP(string otherID, string msg, CHANNEL channel);
void send(string otherID, string msg);
void removeUser(string uid);
Expand Down
4 changes: 2 additions & 2 deletions src/core/scripting/VRPyNetworking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ PyMethodDef VRPyICEClient::methods[] = {
{"setTurnServer", PyWrap(ICEClient, setTurnServer, "Setup turn server address, something like http://my.server/PolyServ/", void, string) },
{"onEvent", PyWrap(ICEClient, onEvent, "Set onEvent callback", void, function<void(string)>) },
{"onMessage", PyWrap(ICEClient, onMessage, "Set onMessage callback", void, function<void(string)>) },
{"setName", PyWrap(ICEClient, setName, "Set your name and uID to register on broker", void, string) },
{"setName", PyWrapOpt(ICEClient, setName, "Set your name and uID to register on broker, optional async", "0", void, string, bool) },
{"sendTCP", PyWrap(ICEClient, sendTCP, "Send data over the TCP connection", void, string, string, VRICEClient::CHANNEL) },
{"send", PyWrap(ICEClient, send, "Send message to other: (uID, msg)", void, string, string) },
{"connectTo", PyWrap(ICEClient, connectTo, "Connect to another user", void, string) },
{"connectTo", PyWrapOpt(ICEClient, connectTo, "Connect to another user, optional async", "0", void, string, bool) },
{"getID", PyWrap(ICEClient, getID, "Get UID", string) },
{"getUserName", PyWrap(ICEClient, getUserName, "Get user name by UID", string, string) },
{"getUserID", PyWrap(ICEClient, getUserID, "Get UIDs of all users with certain name", vector<string>, string) },
Expand Down

0 comments on commit 1ffca98

Please sign in to comment.