Home
Symple module

Client

Symple v4 client.

Client

#include <icy/symple/client.h>
class Client

Defined 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:

Use packetSlot() with the specific type to filter.

List of all members

NameKindOwner
AnnouncevariableDeclared here
PeerConnectedvariableDeclared here
PeerDisconnectedvariableDeclared here
CreatePresencevariableDeclared here
ClientfunctionDeclared here
ClientfunctionDeclared here
~ClientfunctionDeclared here
startfunctionDeclared here
stopfunctionDeclared here
sendfunctionDeclared here
sendfunctionDeclared here
respondfunctionDeclared here
sendPresencefunctionDeclared here
sendPresencefunctionDeclared here
joinRoomfunctionDeclared here
leaveRoomfunctionDeclared here
isOnlinefunctionDeclared here
ourIDfunctionDeclared here
ourPeerfunctionDeclared here
roomsfunctionDeclared here
rosterfunctionDeclared here
optionsfunctionDeclared here
setOptionsfunctionDeclared here
setErrorfunctionDeclared here
createPresencefunctionDeclared here
onPresenceDatafunctionDeclared here
_datavariableDeclared here
doConnectfunctionDeclared here
onTransportErrorfunctionDeclared here
onSocketRecvfunctionDeclared here
onSocketClosefunctionDeclared here
onSocketErrorfunctionDeclared here
onWelcomefunctionDeclared here
onServerMessagefunctionDeclared here
startReconnectfunctionDeclared here
resetfunctionDeclared here
syncDesiredRoomsfunctionDeclared here
sendJsonfunctionDeclared here
buildUrlfunctionDeclared here
StateChangevariableInherited from Stateful
StatefulfunctionInherited from Stateful
~StatefulfunctionInherited from Stateful
stateEqualsfunctionInherited from Stateful
stateBetweenfunctionInherited from Stateful
statefunctionInherited from Stateful
statefunctionInherited from Stateful
_statevariableInherited from Stateful
beforeStateChangefunctionInherited from Stateful
onStateChangefunctionInherited from Stateful
setStatefunctionInherited from Stateful
setStatefunctionInherited from Stateful

Inherited from Stateful

KindNameDescription
variableStateChangeSignals when the state changes.
functionStateful inline
function~Stateful virtual inline
functionstateEquals virtual const inlineReturns true if the current state ID equals the given ID.
functionstateBetween virtual const inlineReturns true if the current state ID is in the inclusive range [lid, rid].
functionstate virtual inlineReturns a mutable reference to the current state.
functionstate virtual const inlineReturns a copy of the current state.
variable_state
functionbeforeStateChange virtual inlineOverride to handle pre state change logic. Return false to prevent state change.
functiononStateChange virtual inlineOverride to handle post state change logic.
functionsetState virtual inlineSets the state and sends the state signal if the state change was successful.
functionsetState virtual inlineSets the state and sends the state signal if the state change was successful.

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

Defined in src/symple/include/icy/symple/client.h:174

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


PeerConnected

Signal< void(Peer &)> PeerConnected

Defined in src/symple/include/icy/symple/client.h:177

A peer has come online.


PeerDisconnected

Signal< void(Peer &)> PeerDisconnected

Defined in src/symple/include/icy/symple/client.h:180

A peer has gone offline.


CreatePresence

Signal< void(Peer &)> CreatePresence

Defined in src/symple/include/icy/symple/client.h:183

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 = 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() const

Defined in src/symple/include/icy/symple/client.h:144

Return true if in Online state.


ourID

const

std::string ourID() const

Defined 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() const

Defined 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() const

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

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

ReturnNameDescription
std::unique_ptr< ClientData >_data

_data

std::unique_ptr< ClientData > _data

Defined in src/symple/include/icy/symple/client.h:209

Private Methods

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

Defined in src/symple/include/icy/symple/client.h:207