Client
Client
#include <icy/symple/client.h>class ClientDefined in src/symple/include/icy/symple/client.h:88
Inherits:
Stateful< ClientState >,Signal< void(IPacket &)>
Symple v4 client.
Connects to a Symple server over plain WebSocket (no Socket.IO). Handles authentication, presence, roster management, rooms, and message routing.
Usage: smpl::Client client({ .host = "localhost", .port = 4500, .user = "alice", .name = "Alice" }); client.start();
client += packetSlot(&handler, &Handler::onMessage); client.Announce += slot(&handler, &Handler::onAnnounce);
Messages are emitted as polymorphic IPacket via PacketSignal:
smpl::Message (type "message")
smpl::Presence (type "presence")
smpl::Event (type "event")
smpl::Command (type "command")
Use packetSlot() with the specific type to filter.
List of all members
| Name | Kind | Owner |
|---|---|---|
Announce | variable | Declared here |
PeerConnected | variable | Declared here |
PeerDisconnected | variable | Declared here |
CreatePresence | variable | Declared here |
Client | function | Declared here |
Client | function | Declared here |
~Client | function | Declared here |
start | function | Declared here |
stop | function | Declared here |
send | function | Declared here |
send | function | Declared here |
respond | function | Declared here |
sendPresence | function | Declared here |
sendPresence | function | Declared here |
joinRoom | function | Declared here |
leaveRoom | function | Declared here |
isOnline | function | Declared here |
ourID | function | Declared here |
ourPeer | function | Declared here |
rooms | function | Declared here |
roster | function | Declared here |
options | function | Declared here |
setOptions | function | Declared here |
setError | function | Declared here |
createPresence | function | Declared here |
onPresenceData | function | Declared here |
_data | variable | Declared here |
doConnect | function | Declared here |
onTransportError | function | Declared here |
onSocketRecv | function | Declared here |
onSocketClose | function | Declared here |
onSocketError | function | Declared here |
onWelcome | function | Declared here |
onServerMessage | function | Declared here |
startReconnect | function | Declared here |
reset | function | Declared here |
syncDesiredRooms | function | Declared here |
sendJson | function | Declared here |
buildUrl | function | Declared here |
StateChange | variable | Inherited from Stateful |
Stateful | function | Inherited from Stateful |
~Stateful | function | Inherited from Stateful |
stateEquals | function | Inherited from Stateful |
stateBetween | function | Inherited from Stateful |
state | function | Inherited from Stateful |
state | function | Inherited from Stateful |
_state | variable | Inherited from Stateful |
beforeStateChange | function | Inherited from Stateful |
onStateChange | function | Inherited from Stateful |
setState | function | Inherited from Stateful |
setState | function | Inherited from Stateful |
Inherited from Stateful
| Kind | Name | Description |
|---|---|---|
variable | StateChange | Signals when the state changes. |
function | Stateful inline | |
function | ~Stateful virtual inline | |
function | stateEquals virtual const inline | Returns true if the current state ID equals the given ID. |
function | stateBetween virtual const inline | Returns true if the current state ID is in the inclusive range [lid, rid]. |
function | state virtual inline | Returns a mutable reference to the current state. |
function | state virtual const inline | Returns a copy of the current state. |
variable | _state | |
function | beforeStateChange virtual inline | Override to handle pre state change logic. Return false to prevent state change. |
function | onStateChange virtual inline | Override to handle post state change logic. |
function | setState virtual inline | Sets the state and sends the state signal if the state change was successful. |
function | setState virtual inline | Sets the state and sends the state signal if the state change was successful. |
Public Attributes
| Return | Name | Description |
|---|---|---|
Signal< void(const int &)> | Announce | Authentication response status (200 = success, 401 = failed). |
Signal< void(Peer &)> | PeerConnected | A peer has come online. |
Signal< void(Peer &)> | PeerDisconnected | A peer has gone offline. |
Signal< void(Peer &)> | CreatePresence | Modify the outgoing peer object before presence broadcast. |
Announce
Signal< void(const int &)> AnnounceDefined in src/symple/include/icy/symple/client.h:174
Authentication response status (200 = success, 401 = failed).
PeerConnected
Signal< void(Peer &)> PeerConnectedDefined in src/symple/include/icy/symple/client.h:177
A peer has come online.
PeerDisconnected
Signal< void(Peer &)> PeerDisconnectedDefined in src/symple/include/icy/symple/client.h:180
A peer has gone offline.
CreatePresence
Signal< void(Peer &)> CreatePresenceDefined in src/symple/include/icy/symple/client.h:183
Modify the outgoing peer object before presence broadcast.
Public Methods
| Return | Name | Description |
|---|---|---|
Client | ||
Client | Default constructor with default Options. | |
void | start | Start the Symple client. |
void | stop | Stop the Symple client. |
ssize_t | send virtual | Send a Symple message. Sets the from field automatically. |
ssize_t | send virtual | Send a string message (parsed as JSON). |
ssize_t | respond virtual | Swap to/from and send. |
ssize_t | sendPresence virtual | Broadcast presence to joined rooms. |
ssize_t | sendPresence virtual | Send directed presence to a specific peer. |
int | joinRoom virtual | Join a room on the server. |
int | leaveRoom virtual | Leave a room on the server. |
bool | isOnline const | Return true if in Online state. |
std::string | ourID const | Return the session ID assigned by the server. |
Peer * | ourPeer | Return the local peer object (null if offline). |
StringVec | rooms const | Return joined rooms. |
Roster & | roster | Return the roster of online peers. |
const Options & | options const | Return the current client options. |
void | setOptions | Replace the client options while the client is closed. This is the only supported way to reconfigure a default-constructed client. |
void | setError | Set an error and transition to Error state. |
Client
Client(const Options & options, uv::Loop * loop = uv::defaultLoop())Defined in src/symple/include/icy/symple/client.h:110
Client
Client()Defined in src/symple/include/icy/symple/client.h:112
Default constructor with default Options.
start
void start()Defined in src/symple/include/icy/symple/client.h:116
Start the Symple client.
stop
void stop()Defined in src/symple/include/icy/symple/client.h:119
Stop the Symple client.
send
virtual
virtual ssize_t send(Message & message)Defined in src/symple/include/icy/symple/client.h:123
Send a Symple message. Sets the from field automatically.
send
virtual
virtual ssize_t send(const std::string & message)Defined in src/symple/include/icy/symple/client.h:126
Send a string message (parsed as JSON).
respond
virtual
virtual ssize_t respond(Message & message)Defined in src/symple/include/icy/symple/client.h:129
Swap to/from and send.
sendPresence
virtual
virtual ssize_t sendPresence(bool probe = false)Defined in src/symple/include/icy/symple/client.h:132
Broadcast presence to joined rooms.
sendPresence
virtual
virtual ssize_t sendPresence(const Address & to, bool probe = false)Defined in src/symple/include/icy/symple/client.h:135
Send directed presence to a specific peer.
joinRoom
virtual
virtual int joinRoom(const std::string & room)Defined in src/symple/include/icy/symple/client.h:138
Join a room on the server.
leaveRoom
virtual
virtual int leaveRoom(const std::string & room)Defined in src/symple/include/icy/symple/client.h:141
Leave a room on the server.
isOnline
const
bool isOnline() constDefined in src/symple/include/icy/symple/client.h:144
Return true if in Online state.
ourID
const
std::string ourID() constDefined in src/symple/include/icy/symple/client.h:147
Return the session ID assigned by the server.
ourPeer
Peer * ourPeer()Defined in src/symple/include/icy/symple/client.h:150
Return the local peer object (null if offline).
rooms
const
StringVec rooms() constDefined in src/symple/include/icy/symple/client.h:153
Return joined rooms.
roster
Roster & roster()Defined in src/symple/include/icy/symple/client.h:156
Return the roster of online peers.
options
const
const Options & options() constDefined in src/symple/include/icy/symple/client.h:159
Return the current client options.
setOptions
void setOptions(Options options)Defined in src/symple/include/icy/symple/client.h:164
Replace the client options while the client is closed. This is the only supported way to reconfigure a default-constructed client.
Exceptions
std::logic_errorif the client is currently connecting, online, or reconnecting.
setError
void setError(const std::string & error)Defined in src/symple/include/icy/symple/client.h:167
Set an error and transition to Error state.
Protected Methods
| Return | Name | Description |
|---|---|---|
void | createPresence virtual | Underlying connection state changed. Inherits StateChange from Stateful |
void | onPresenceData virtual |
createPresence
virtual
virtual void createPresence(Presence & p)Defined in src/symple/include/icy/symple/client.h:189
Underlying connection state changed. Inherits StateChange from Stateful
onPresenceData
virtual
virtual void onPresenceData(const json::Value & data, bool whiny = false)Defined in src/symple/include/icy/symple/client.h:190
Private Attributes
| Return | Name | Description |
|---|---|---|
std::unique_ptr< ClientData > | _data |
_data
std::unique_ptr< ClientData > _dataDefined in src/symple/include/icy/symple/client.h:209
Private Methods
| Return | Name | Description |
|---|---|---|
void | doConnect | |
void | onTransportError | |
void | onSocketRecv | |
void | onSocketClose | |
void | onSocketError | |
void | onWelcome | |
void | onServerMessage | |
void | startReconnect | |
void | reset | |
void | syncDesiredRooms | |
ssize_t | sendJson | |
std::string | buildUrl const |
doConnect
void doConnect()Defined in src/symple/include/icy/symple/client.h:195
onTransportError
void onTransportError(const icy::Error & error)Defined in src/symple/include/icy/symple/client.h:196
onSocketRecv
void onSocketRecv(const std::string & data)Defined in src/symple/include/icy/symple/client.h:197
onSocketClose
void onSocketClose()Defined in src/symple/include/icy/symple/client.h:198
onSocketError
void onSocketError(const std::string & error)Defined in src/symple/include/icy/symple/client.h:199
onWelcome
void onWelcome(const json::Value & msg)Defined in src/symple/include/icy/symple/client.h:200
onServerMessage
void onServerMessage(const json::Value & msg)Defined in src/symple/include/icy/symple/client.h:201
startReconnect
void startReconnect()Defined in src/symple/include/icy/symple/client.h:202
reset
void reset()Defined in src/symple/include/icy/symple/client.h:203
syncDesiredRooms
void syncDesiredRooms()Defined in src/symple/include/icy/symple/client.h:204
sendJson
ssize_t sendJson(const json::Value & msg)Defined in src/symple/include/icy/symple/client.h:206
buildUrl
const
std::string buildUrl() const