diff --git a/src/core/networking/VRCollaboration.cpp b/src/core/networking/VRCollaboration.cpp index 288f047b7..23aca7569 100644 --- a/src/core/networking/VRCollaboration.cpp +++ b/src/core/networking/VRCollaboration.cpp @@ -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" @@ -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(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); @@ -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(); } @@ -296,10 +314,13 @@ vector 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); } @@ -307,11 +328,11 @@ void VRCollaboration::acceptConnection() { void VRCollaboration::finishConnection(string origin, vector 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()); } diff --git a/src/core/networking/tcp/VRICEclient.cpp b/src/core/networking/tcp/VRICEclient.cpp index a826fc1ec..ecf932005 100644 --- a/src/core/networking/tcp/VRICEclient.cpp +++ b/src/core/networking/tcp/VRICEclient.cpp @@ -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(); @@ -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(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] ); @@ -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 @@ -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); diff --git a/src/core/networking/tcp/VRICEclient.h b/src/core/networking/tcp/VRICEclient.h index f09990005..3ad34c6de 100644 --- a/src/core/networking/tcp/VRICEclient.h +++ b/src/core/networking/tcp/VRICEclient.h @@ -65,8 +65,8 @@ class VRICEClient : public VRNetworkClient { void onEvent( function f ); void onMessage( function 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); diff --git a/src/core/scripting/VRPyNetworking.cpp b/src/core/scripting/VRPyNetworking.cpp index 9a8275bc7..fb027cf85 100644 --- a/src/core/scripting/VRPyNetworking.cpp +++ b/src/core/scripting/VRPyNetworking.cpp @@ -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) }, {"onMessage", PyWrap(ICEClient, onMessage, "Set onMessage callback", void, function) }, - {"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) },