WebSocket client for connecting to yaze-server. More...
#include <websocket_client.h>
Classes | |
class | Impl |
Public Types | |
using | MessageCallback = std::function< void(const nlohmann::json &)> |
using | ErrorCallback = std::function< void(const std::string &)> |
using | StateCallback = std::function< void(ConnectionState)> |
Public Member Functions | |
WebSocketClient () | |
~WebSocketClient () | |
absl::Status | Connect (const std::string &host, int port=8765) |
void | Disconnect () |
absl::StatusOr< SessionInfo > | HostSession (const std::string &session_name, const std::string &username, const std::string &rom_hash, bool ai_enabled=true) |
absl::StatusOr< SessionInfo > | JoinSession (const std::string &session_code, const std::string &username) |
absl::Status | LeaveSession () |
absl::Status | SendChatMessage (const std::string &message, const std::string &sender) |
absl::Status | SendRomSync (const std::string &diff_data, const std::string &rom_hash, const std::string &sender) |
absl::Status | ShareSnapshot (const std::string &snapshot_data, const std::string &snapshot_type, const std::string &sender) |
absl::Status | ShareProposal (const nlohmann::json &proposal_data, const std::string &sender) |
absl::Status | VoteOnProposal (const std::string &proposal_id, bool approved, const std::string &username) |
absl::Status | UpdateProposalStatus (const std::string &proposal_id, const std::string &status) |
absl::Status | SendAIQuery (const std::string &query, const std::string &username) |
void | OnMessage (const std::string &type, MessageCallback callback) |
void | OnError (ErrorCallback callback) |
void | OnStateChange (StateCallback callback) |
ConnectionState | GetState () const |
absl::StatusOr< SessionInfo > | GetSessionInfo () const |
bool | IsConnected () const |
bool | InSession () const |
Private Member Functions | |
void | HandleMessage (const std::string &message) |
void | HandleError (const std::string &error) |
void | SetState (ConnectionState state) |
absl::Status | SendRaw (const nlohmann::json &message) |
Private Attributes | |
std::unique_ptr< Impl > | impl_ |
ConnectionState | state_ |
SessionInfo | current_session_ |
std::map< std::string, std::vector< MessageCallback > > | message_callbacks_ |
std::vector< ErrorCallback > | error_callbacks_ |
std::vector< StateCallback > | state_callbacks_ |
WebSocket client for connecting to yaze-server.
Provides:
Definition at line 58 of file websocket_client.h.
using yaze::net::WebSocketClient::MessageCallback = std::function<void(const nlohmann::json&)> |
Definition at line 61 of file websocket_client.h.
using yaze::net::WebSocketClient::ErrorCallback = std::function<void(const std::string&)> |
Definition at line 62 of file websocket_client.h.
using yaze::net::WebSocketClient::StateCallback = std::function<void(ConnectionState)> |
Definition at line 63 of file websocket_client.h.
yaze::net::WebSocketClient::WebSocketClient | ( | ) |
Definition at line 176 of file websocket_client.cc.
yaze::net::WebSocketClient::~WebSocketClient | ( | ) |
Definition at line 181 of file websocket_client.cc.
References Disconnect().
absl::Status yaze::net::WebSocketClient::Connect | ( | const std::string & | host, |
int | port = 8765 |
||
) |
Connect to yaze-server
host | Server hostname/IP |
port | Server port (default: 8765) |
Definition at line 185 of file websocket_client.cc.
References impl_, yaze::net::kConnected, yaze::net::kError, and SetState().
void yaze::net::WebSocketClient::Disconnect | ( | ) |
Disconnect from server
Definition at line 197 of file websocket_client.cc.
References current_session_, impl_, yaze::net::kDisconnected, and SetState().
Referenced by ~WebSocketClient().
absl::StatusOr< SessionInfo > yaze::net::WebSocketClient::HostSession | ( | const std::string & | session_name, |
const std::string & | username, | ||
const std::string & | rom_hash, | ||
bool | ai_enabled = true |
||
) |
Host a new collaboration session
Definition at line 203 of file websocket_client.cc.
References yaze::net::SessionInfo::ai_enabled, current_session_, yaze::net::SessionInfo::host, IsConnected(), yaze::net::SessionInfo::rom_hash, SendRaw(), and yaze::net::SessionInfo::session_name.
absl::StatusOr< SessionInfo > yaze::net::WebSocketClient::JoinSession | ( | const std::string & | session_code, |
const std::string & | username | ||
) |
Join an existing session
Definition at line 244 of file websocket_client.cc.
References current_session_, IsConnected(), SendRaw(), and yaze::net::SessionInfo::session_code.
absl::Status yaze::net::WebSocketClient::LeaveSession | ( | ) |
Leave current session
Definition at line 277 of file websocket_client.cc.
References current_session_, InSession(), and SendRaw().
absl::Status yaze::net::WebSocketClient::SendChatMessage | ( | const std::string & | message, |
const std::string & | sender | ||
) |
Send chat message
Definition at line 296 of file websocket_client.cc.
References SendRaw().
absl::Status yaze::net::WebSocketClient::SendRomSync | ( | const std::string & | diff_data, |
const std::string & | rom_hash, | ||
const std::string & | sender | ||
) |
Send ROM sync
Definition at line 315 of file websocket_client.cc.
References SendRaw().
absl::Status yaze::net::WebSocketClient::ShareSnapshot | ( | const std::string & | snapshot_data, |
const std::string & | snapshot_type, | ||
const std::string & | sender | ||
) |
Share snapshot
absl::Status yaze::net::WebSocketClient::ShareProposal | ( | const nlohmann::json & | proposal_data, |
const std::string & | sender | ||
) |
Share proposal for approval
Definition at line 336 of file websocket_client.cc.
References SendRaw().
absl::Status yaze::net::WebSocketClient::VoteOnProposal | ( | const std::string & | proposal_id, |
bool | approved, | ||
const std::string & | username | ||
) |
Vote on proposal (approve/reject)
Definition at line 355 of file websocket_client.cc.
References SendRaw().
absl::Status yaze::net::WebSocketClient::UpdateProposalStatus | ( | const std::string & | proposal_id, |
const std::string & | status | ||
) |
Update proposal status
Definition at line 376 of file websocket_client.cc.
References SendRaw().
absl::Status yaze::net::WebSocketClient::SendAIQuery | ( | const std::string & | query, |
const std::string & | username | ||
) |
Send AI query
void yaze::net::WebSocketClient::OnMessage | ( | const std::string & | type, |
MessageCallback | callback | ||
) |
Register callback for specific message type
Definition at line 395 of file websocket_client.cc.
References message_callbacks_.
void yaze::net::WebSocketClient::OnError | ( | ErrorCallback | callback | ) |
Register callback for errors
Definition at line 399 of file websocket_client.cc.
References error_callbacks_.
void yaze::net::WebSocketClient::OnStateChange | ( | StateCallback | callback | ) |
Register callback for connection state changes
Definition at line 403 of file websocket_client.cc.
References state_callbacks_.
|
inline |
absl::StatusOr< SessionInfo > yaze::net::WebSocketClient::GetSessionInfo | ( | ) | const |
Get current session info (if in a session)
Definition at line 407 of file websocket_client.cc.
References current_session_, and InSession().
|
inline |
Check if connected
Definition at line 181 of file websocket_client.h.
References yaze::net::kConnected, and state_.
Referenced by HostSession(), and JoinSession().
|
inline |
Check if in a session
Definition at line 186 of file websocket_client.h.
References current_session_, and yaze::net::SessionInfo::session_id.
Referenced by GetSessionInfo(), and LeaveSession().
|
private |
Definition at line 416 of file websocket_client.cc.
References HandleError(), and message_callbacks_.
|
private |
Definition at line 434 of file websocket_client.cc.
References error_callbacks_.
Referenced by HandleMessage().
|
private |
Definition at line 440 of file websocket_client.cc.
References state_, and state_callbacks_.
Referenced by Connect(), and Disconnect().
|
private |
Definition at line 449 of file websocket_client.cc.
References impl_.
Referenced by HostSession(), JoinSession(), LeaveSession(), SendChatMessage(), SendRomSync(), ShareProposal(), UpdateProposalStatus(), and VoteOnProposal().
|
private |
Definition at line 191 of file websocket_client.h.
Referenced by Connect(), Disconnect(), and SendRaw().
|
private |
Definition at line 193 of file websocket_client.h.
Referenced by GetState(), IsConnected(), and SetState().
|
private |
Definition at line 194 of file websocket_client.h.
Referenced by Disconnect(), GetSessionInfo(), HostSession(), InSession(), JoinSession(), and LeaveSession().
|
private |
Definition at line 197 of file websocket_client.h.
Referenced by HandleMessage(), and OnMessage().
|
private |
Definition at line 198 of file websocket_client.h.
Referenced by HandleError(), and OnError().
|
private |
Definition at line 199 of file websocket_client.h.
Referenced by OnStateChange(), and SetState().