yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
yaze::net::WebSocketClient Class Reference

WebSocket client for connecting to yaze-server. More...

#include <websocket_client.h>

Collaboration diagram for yaze::net::WebSocketClient:

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< SessionInfoHostSession (const std::string &session_name, const std::string &username, const std::string &rom_hash, bool ai_enabled=true)
 
absl::StatusOr< SessionInfoJoinSession (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< SessionInfoGetSessionInfo () 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< Implimpl_
 
ConnectionState state_
 
SessionInfo current_session_
 
std::map< std::string, std::vector< MessageCallback > > message_callbacks_
 
std::vector< ErrorCallbackerror_callbacks_
 
std::vector< StateCallbackstate_callbacks_
 

Detailed Description

WebSocket client for connecting to yaze-server.

Provides:

  • Connection management with auto-reconnect
  • Session hosting and joining
  • Message sending/receiving
  • Event callbacks for different message types

Definition at line 58 of file websocket_client.h.

Member Typedef Documentation

◆ MessageCallback

using yaze::net::WebSocketClient::MessageCallback = std::function<void(const nlohmann::json&)>

Definition at line 61 of file websocket_client.h.

◆ ErrorCallback

using yaze::net::WebSocketClient::ErrorCallback = std::function<void(const std::string&)>

Definition at line 62 of file websocket_client.h.

◆ StateCallback

Definition at line 63 of file websocket_client.h.

Constructor & Destructor Documentation

◆ WebSocketClient()

yaze::net::WebSocketClient::WebSocketClient ( )

Definition at line 176 of file websocket_client.cc.

◆ ~WebSocketClient()

yaze::net::WebSocketClient::~WebSocketClient ( )

Definition at line 181 of file websocket_client.cc.

References Disconnect().

Here is the call graph for this function:

Member Function Documentation

◆ Connect()

absl::Status yaze::net::WebSocketClient::Connect ( const std::string &  host,
int  port = 8765 
)

Connect to yaze-server

Parameters
hostServer hostname/IP
portServer port (default: 8765)

Definition at line 185 of file websocket_client.cc.

References impl_, yaze::net::kConnected, yaze::net::kError, and SetState().

Here is the call graph for this function:

◆ Disconnect()

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().

Here is the call graph for this function:

◆ HostSession()

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.

Here is the call graph for this function:

◆ JoinSession()

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.

Here is the call graph for this function:

◆ LeaveSession()

absl::Status yaze::net::WebSocketClient::LeaveSession ( )

Leave current session

Definition at line 277 of file websocket_client.cc.

References current_session_, InSession(), and SendRaw().

Here is the call graph for this function:

◆ SendChatMessage()

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().

Here is the call graph for this function:

◆ SendRomSync()

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().

Here is the call graph for this function:

◆ ShareSnapshot()

absl::Status yaze::net::WebSocketClient::ShareSnapshot ( const std::string &  snapshot_data,
const std::string &  snapshot_type,
const std::string &  sender 
)

Share snapshot

◆ ShareProposal()

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().

Here is the call graph for this function:

◆ VoteOnProposal()

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().

Here is the call graph for this function:

◆ UpdateProposalStatus()

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().

Here is the call graph for this function:

◆ SendAIQuery()

absl::Status yaze::net::WebSocketClient::SendAIQuery ( const std::string &  query,
const std::string &  username 
)

Send AI query

◆ OnMessage()

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_.

◆ OnError()

void yaze::net::WebSocketClient::OnError ( ErrorCallback  callback)

Register callback for errors

Definition at line 399 of file websocket_client.cc.

References error_callbacks_.

◆ OnStateChange()

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_.

◆ GetState()

ConnectionState yaze::net::WebSocketClient::GetState ( ) const
inline

Get current connection state

Definition at line 171 of file websocket_client.h.

References state_.

◆ GetSessionInfo()

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().

Here is the call graph for this function:

◆ IsConnected()

bool yaze::net::WebSocketClient::IsConnected ( ) const
inline

Check if connected

Definition at line 181 of file websocket_client.h.

References yaze::net::kConnected, and state_.

Referenced by HostSession(), and JoinSession().

◆ InSession()

bool yaze::net::WebSocketClient::InSession ( ) const
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().

◆ HandleMessage()

void yaze::net::WebSocketClient::HandleMessage ( const std::string &  message)
private

Definition at line 416 of file websocket_client.cc.

References HandleError(), and message_callbacks_.

Here is the call graph for this function:

◆ HandleError()

void yaze::net::WebSocketClient::HandleError ( const std::string &  error)
private

Definition at line 434 of file websocket_client.cc.

References error_callbacks_.

Referenced by HandleMessage().

◆ SetState()

void yaze::net::WebSocketClient::SetState ( ConnectionState  state)
private

Definition at line 440 of file websocket_client.cc.

References state_, and state_callbacks_.

Referenced by Connect(), and Disconnect().

◆ SendRaw()

absl::Status yaze::net::WebSocketClient::SendRaw ( const nlohmann::json &  message)
private

Member Data Documentation

◆ impl_

std::unique_ptr<Impl> yaze::net::WebSocketClient::impl_
private

Definition at line 191 of file websocket_client.h.

Referenced by Connect(), Disconnect(), and SendRaw().

◆ state_

ConnectionState yaze::net::WebSocketClient::state_
private

Definition at line 193 of file websocket_client.h.

Referenced by GetState(), IsConnected(), and SetState().

◆ current_session_

SessionInfo yaze::net::WebSocketClient::current_session_
private

◆ message_callbacks_

std::map<std::string, std::vector<MessageCallback> > yaze::net::WebSocketClient::message_callbacks_
private

Definition at line 197 of file websocket_client.h.

Referenced by HandleMessage(), and OnMessage().

◆ error_callbacks_

std::vector<ErrorCallback> yaze::net::WebSocketClient::error_callbacks_
private

Definition at line 198 of file websocket_client.h.

Referenced by HandleError(), and OnError().

◆ state_callbacks_

std::vector<StateCallback> yaze::net::WebSocketClient::state_callbacks_
private

Definition at line 199 of file websocket_client.h.

Referenced by OnStateChange(), and SetState().


The documentation for this class was generated from the following files: