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