mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-12-18 21:29:09 +08:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f6eda34dbd | ||
|
|
5d9a0a3ea5 |
@@ -79,24 +79,38 @@ int Render::RemoteWindow() {
|
|||||||
enter_pressed) {
|
enter_pressed) {
|
||||||
connect_button_pressed_ = true;
|
connect_button_pressed_ = true;
|
||||||
bool found = false;
|
bool found = false;
|
||||||
|
std::string target_remote_id;
|
||||||
|
std::string target_password;
|
||||||
|
bool should_connect = false;
|
||||||
|
bool already_connected = false;
|
||||||
|
|
||||||
for (auto& [id, props] : recent_connections_) {
|
for (auto& [id, props] : recent_connections_) {
|
||||||
if (id.find(remote_id) != std::string::npos) {
|
if (id.find(remote_id) != std::string::npos) {
|
||||||
found = true;
|
found = true;
|
||||||
std::shared_lock lock(client_properties_mutex_);
|
target_remote_id = props.remote_id;
|
||||||
if (client_properties_.find(remote_id) !=
|
target_password = props.password;
|
||||||
client_properties_.end()) {
|
{
|
||||||
if (!client_properties_[remote_id]->connection_established_) {
|
std::shared_lock lock(client_properties_mutex_);
|
||||||
ConnectTo(props.remote_id, props.password.c_str(), false);
|
if (client_properties_.find(remote_id) !=
|
||||||
|
client_properties_.end()) {
|
||||||
|
if (!client_properties_[remote_id]->connection_established_) {
|
||||||
|
should_connect = true;
|
||||||
|
} else {
|
||||||
|
already_connected = true;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// todo: show warning message
|
should_connect = true;
|
||||||
LOG_INFO("Already connected to [{}]", remote_id);
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
ConnectTo(props.remote_id, props.password.c_str(), false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (should_connect) {
|
||||||
|
ConnectTo(target_remote_id, target_password.c_str(), false);
|
||||||
|
} else if (already_connected) {
|
||||||
|
LOG_INFO("Already connected to [{}]", remote_id);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!found) {
|
if (!found) {
|
||||||
ConnectTo(remote_id, "", false);
|
ConnectTo(remote_id, "", false);
|
||||||
}
|
}
|
||||||
@@ -153,39 +167,44 @@ int Render::ConnectTo(const std::string& remote_id, const char* password,
|
|||||||
shared_lock.unlock();
|
shared_lock.unlock();
|
||||||
|
|
||||||
if (!exists) {
|
if (!exists) {
|
||||||
std::unique_lock unique_lock(client_properties_mutex_);
|
PeerPtr* peer_to_init = nullptr;
|
||||||
if (client_properties_.find(remote_id) == client_properties_.end()) {
|
std::string local_id;
|
||||||
client_properties_[remote_id] =
|
|
||||||
std::make_shared<SubStreamWindowProperties>();
|
|
||||||
auto props = client_properties_[remote_id];
|
|
||||||
props->local_id_ = "C-" + std::string(client_id_);
|
|
||||||
props->remote_id_ = remote_id;
|
|
||||||
memcpy(&props->params_, ¶ms_, sizeof(Params));
|
|
||||||
props->params_.user_id = props->local_id_.c_str();
|
|
||||||
props->peer_ = CreatePeer(&props->params_);
|
|
||||||
|
|
||||||
if (!props->peer_) {
|
{
|
||||||
LOG_INFO("Create peer [{}] instance failed", props->local_id_);
|
std::unique_lock unique_lock(client_properties_mutex_);
|
||||||
return -1;
|
if (client_properties_.find(remote_id) == client_properties_.end()) {
|
||||||
|
client_properties_[remote_id] =
|
||||||
|
std::make_shared<SubStreamWindowProperties>();
|
||||||
|
auto props = client_properties_[remote_id];
|
||||||
|
props->local_id_ = "C-" + std::string(client_id_);
|
||||||
|
props->remote_id_ = remote_id;
|
||||||
|
memcpy(&props->params_, ¶ms_, sizeof(Params));
|
||||||
|
props->params_.user_id = props->local_id_.c_str();
|
||||||
|
props->peer_ = CreatePeer(&props->params_);
|
||||||
|
|
||||||
|
if (!props->peer_) {
|
||||||
|
LOG_INFO("Create peer [{}] instance failed", props->local_id_);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto& display_info : display_info_list_) {
|
||||||
|
AddVideoStream(props->peer_, display_info.name.c_str());
|
||||||
|
}
|
||||||
|
AddAudioStream(props->peer_, props->audio_label_.c_str());
|
||||||
|
AddDataStream(props->peer_, props->data_label_.c_str());
|
||||||
|
|
||||||
|
props->connection_status_ = ConnectionStatus::Connecting;
|
||||||
|
|
||||||
|
peer_to_init = props->peer_;
|
||||||
|
local_id = props->local_id_;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& display_info : display_info_list_) {
|
|
||||||
AddVideoStream(props->peer_, display_info.name.c_str());
|
|
||||||
}
|
|
||||||
AddAudioStream(props->peer_, props->audio_label_.c_str());
|
|
||||||
AddDataStream(props->peer_, props->data_label_.c_str());
|
|
||||||
|
|
||||||
if (props->peer_) {
|
|
||||||
LOG_INFO("[{}] Create peer instance successful", props->local_id_);
|
|
||||||
Init(props->peer_);
|
|
||||||
LOG_INFO("[{}] Peer init finish", props->local_id_);
|
|
||||||
} else {
|
|
||||||
LOG_INFO("Create peer [{}] instance failed", props->local_id_);
|
|
||||||
}
|
|
||||||
|
|
||||||
props->connection_status_ = ConnectionStatus::Connecting;
|
|
||||||
}
|
}
|
||||||
unique_lock.unlock();
|
|
||||||
|
if (peer_to_init) {
|
||||||
|
LOG_INFO("[{}] Create peer instance successful", local_id);
|
||||||
|
Init(peer_to_init);
|
||||||
|
LOG_INFO("[{}] Peer init finish", local_id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|||||||
Reference in New Issue
Block a user