Client
Client
#include <icy/symple/client.h>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.
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 &)> AnnounceAuthentication response status (200 = success, 401 = failed).
PeerConnected
Signal< void(Peer &)> PeerConnectedA peer has come online.
PeerDisconnected
Signal< void(Peer &)> PeerDisconnectedA peer has gone offline.
CreatePresence
Signal< void(Peer &)> CreatePresenceModify 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)Client
Client()Default constructor with default Options.
start
void start()Start the Symple client.
stop
void stop()Stop the Symple client.
send
virtual
virtual ssize_t send(Message & message)Send a Symple message. Sets the from field automatically.
send
virtual
virtual ssize_t send(const std::string & message)Send a string message (parsed as JSON).
respond
virtual
virtual ssize_t respond(Message & message)Swap to/from and send.
sendPresence
virtual
virtual ssize_t sendPresence(bool probe)Broadcast presence to joined rooms.
sendPresence
virtual
virtual ssize_t sendPresence(const Address & to, bool probe)Send directed presence to a specific peer.
joinRoom
virtual
virtual int joinRoom(const std::string & room)Join a room on the server.
leaveRoom
virtual
virtual int leaveRoom(const std::string & room)Leave a room on the server.
isOnline
const
bool isOnline() constReturn true if in Online state.
ourID
const
std::string ourID() constReturn the session ID assigned by the server.
ourPeer
Peer * ourPeer()Return the local peer object (null if offline).
rooms
const
StringVec rooms() constReturn joined rooms.
roster
Roster & roster()Return the roster of online peers.
options
const
const Options & options() constReturn the current client options.
setOptions
void setOptions(Options options)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)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)Underlying connection state changed. Inherits StateChange from Stateful
onPresenceData
virtual
virtual void onPresenceData(const json::Value & data, bool whiny)Private Attributes
| Return | Name | Description |
|---|---|---|
std::unique_ptr< ClientData > | _data |
_data
std::unique_ptr< ClientData > _dataPrivate 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()onTransportError
void onTransportError(const icy::Error & error)onSocketRecv
void onSocketRecv(const std::string & data)onSocketClose
void onSocketClose()onSocketError
void onSocketError(const std::string & error)onWelcome
void onWelcome(const json::Value & msg)onServerMessage
void onServerMessage(const json::Value & msg)startReconnect
void startReconnect()reset
void reset()syncDesiredRooms
void syncDesiredRooms()sendJson
ssize_t sendJson(const json::Value & msg)buildUrl
const
std::string buildUrl() const