Skip to content

Commit

Permalink
Fix incoming messages on host side.
Browse files Browse the repository at this point in the history
  • Loading branch information
dchapyshev committed Apr 10, 2022
1 parent 96c3b9f commit 8776f54
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
9 changes: 0 additions & 9 deletions source/host/client_session_text_chat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,6 @@ bool ClientSessionTextChat::hasUser() const
void ClientSessionTextChat::setHasUser(bool enable)
{
has_user_ = enable;

if (has_user_)
{
sendStatus(proto::TextChatStatus::STATUS_USER_CONNECTED);
}
else
{
sendStatus(proto::TextChatStatus::STATUS_USER_DISCONNECTED);
}
}

void ClientSessionTextChat::onMessageReceived(const base::ByteArray& buffer)
Expand Down
26 changes: 22 additions & 4 deletions source/host/user_session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ void UserSession::start(const proto::internal::RouterState& router_state)
sendRouterState(FROM_HERE);
sendCredentials(FROM_HERE);

setTextChatHasUser(true);
onTextChatHasUser(FROM_HERE, true);
}
else
{
Expand Down Expand Up @@ -214,7 +214,7 @@ void UserSession::restart(std::unique_ptr<base::IpcChannel> channel)
sendRouterState(FROM_HERE);
sendCredentials(FROM_HERE);

setTextChatHasUser(true);
onTextChatHasUser(FROM_HERE, true);
}
else
{
Expand Down Expand Up @@ -963,7 +963,7 @@ void UserSession::onSessionDettached(const base::Location& location)
for (const auto& client : file_transfer_clients_)
client->stop();

setTextChatHasUser(false);
onTextChatHasUser(FROM_HERE, false);

setState(FROM_HERE, State::DETTACHED);

Expand Down Expand Up @@ -1217,7 +1217,18 @@ void UserSession::addNewClientSession(std::unique_ptr<ClientSession> client_sess
sendConnectEvent(*client_session_ptr);

if (client_session_ptr->sessionType() == proto::SESSION_TYPE_TEXT_CHAT)
{
onTextChatSessionStarted(client_session_ptr->id());

bool has_user = channel_ != nullptr;
for (const auto& client : text_chat_clients_)
{
ClientSessionTextChat* text_chat_client =
static_cast<ClientSessionTextChat*>(client.get());

text_chat_client->setHasUser(has_user);
}
}
}

void UserSession::setState(const base::Location& location, State state)
Expand All @@ -1227,14 +1238,21 @@ void UserSession::setState(const base::Location& location, State state)
state_ = state;
}

void UserSession::setTextChatHasUser(bool has_user)
void UserSession::onTextChatHasUser(const base::Location& location, bool has_user)
{
LOG(LS_INFO) << "User state changed: " << has_user << " (from: " << location.toString() << ")";

for (const auto& client : text_chat_clients_)
{
ClientSessionTextChat* text_chat_client =
static_cast<ClientSessionTextChat*>(client.get());

proto::TextChatStatus::Status status = proto::TextChatStatus::STATUS_USER_CONNECTED;
if (!has_user)
status = proto::TextChatStatus::STATUS_USER_DISCONNECTED;

text_chat_client->setHasUser(has_user);
text_chat_client->sendStatus(status);
}
}

Expand Down
2 changes: 1 addition & 1 deletion source/host/user_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class UserSession
void sendHostIdRequest(const base::Location& location);
void addNewClientSession(std::unique_ptr<ClientSession> client_session);
void setState(const base::Location& location, State state);
void setTextChatHasUser(bool has_user);
void onTextChatHasUser(const base::Location& location, bool has_user);
void onTextChatSessionStarted(uint32_t id);
void onTextChatSessionFinished(uint32_t id);

Expand Down

0 comments on commit 8776f54

Please sign in to comment.