Symple module

Client

Symple v4 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:

Use packetSlot() with the specific type to filter.

Public Attributes

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

Announce

Signal< void(const int &)> Announce

Authentication response status (200 = success, 401 = failed).


PeerConnected

Signal< void(Peer &)> PeerConnected

A peer has come online.


PeerDisconnected

Signal< void(Peer &)> PeerDisconnected

A peer has gone offline.


CreatePresence

Signal< void(Peer &)> CreatePresence

Modify the outgoing peer object before presence broadcast.

Public Methods

ReturnNameDescription
Client
ClientDefault constructor with default Options.
voidstartStart the Symple client.
voidstopStop the Symple client.
ssize_tsend virtualSend a Symple message. Sets the from field automatically.
ssize_tsend virtualSend a string message (parsed as JSON).
ssize_trespond virtualSwap to/from and send.
ssize_tsendPresence virtualBroadcast presence to joined rooms.
ssize_tsendPresence virtualSend directed presence to a specific peer.
intjoinRoom virtualJoin a room on the server.
intleaveRoom virtualLeave a room on the server.
boolisOnline constReturn true if in Online state.
std::stringourID constReturn the session ID assigned by the server.
Peer *ourPeerReturn the local peer object (null if offline).
StringVecrooms constReturn joined rooms.
Roster &rosterReturn the roster of online peers.
const Options &options constReturn the current client options.
voidsetOptionsReplace the client options while the client is closed. This is the only supported way to reconfigure a default-constructed client.
voidsetErrorSet 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() const

Return true if in Online state.


ourID

const

std::string ourID() const

Return the session ID assigned by the server.


ourPeer

Peer * ourPeer()

Return the local peer object (null if offline).


rooms

const

StringVec rooms() const

Return joined rooms.


roster

Roster & roster()

Return the roster of online peers.


options

const

const Options & options() const

Return 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_error if 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

ReturnNameDescription
voidcreatePresence virtualUnderlying connection state changed. Inherits StateChange from Stateful.
voidonPresenceData 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

ReturnNameDescription
std::unique_ptr< ClientData >_data

_data

std::unique_ptr< ClientData > _data

Private Methods

ReturnNameDescription
voiddoConnect
voidonTransportError
voidonSocketRecv
voidonSocketClose
voidonSocketError
voidonWelcome
voidonServerMessage
voidstartReconnect
voidreset
voidsyncDesiredRooms
ssize_tsendJson
std::stringbuildUrl 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