Class NetworkEventBus

Class Documentation

class NetworkEventBus

Handles registration of interest, and dispatch of callbacks to interested parties, of events sent over the network to connected clients.

This object may be used to send arbitrary messages between clients, broadcasting messages to either all clients, or particular clients specified by a clientID. Particular messages are generic and may be defined as any arbitrary string, and may carry payloads of csp::common::ReplicatedValue.

Public Types

enum class NetworkEvent

Values:

enumerator AssetDetailBlobChanged
enumerator Conversation
enumerator SequenceChanged
enumerator AccessControlChanged
enumerator GeneralPurposeEvent
typedef std::function<void(csp::multiplayer::ErrorCode)> ErrorCodeCallbackHandler

Public Functions

void SendNetworkEvent(const csp::common::String &EventName, const csp::common::Array<csp::common::ReplicatedValue> &Args, ErrorCodeCallbackHandler Callback)

Sends a network event by EventName to all currently connected clients.

Parameters
async::task<std::optional<csp::multiplayer::ErrorCode>> SendNetworkEvent(const csp::common::String &EventName, const csp::common::Array<csp::common::ReplicatedValue> &Args)
void SendNetworkEventToClient(const csp::common::String &EventName, const csp::common::Array<csp::common::ReplicatedValue> &Args, uint64_t TargetClientId, ErrorCodeCallbackHandler Callback)

Sends a network event by EventName, to TargetClientId.

Parameters
void ListenNetworkEvent(NetworkEventRegistration Registration, NetworkEventCallback Callback)

Register interest in a network event, such that the NetworkEventBus will call the provided callback when it arrives.

Parameters
  • RegistrationNetworkEventRegistration : Registration information, containing a ReceiverID and an EventName. Will fail to register if identical callback registration already registered.

  • CallbackNetworkEventCallback : Callback to invoke when specified event is received. Will fail to register if null.

void StopListenNetworkEvent(NetworkEventRegistration Registration)

Deregister interest in a network event.

Parameters

RegistrationNetworkEventRegistration : Registration information of already registered event, containing a ReceiverID and an EventName.

void StopListenAllNetworkEvents(const csp::common::String &EventReceiverId)

Deregister interest in all network events registered to a particular EventReceiverId.

Parameters

EventReceiverId – const csp::common::String& : EventReceiverId to deregister.

csp::common::Array<NetworkEventRegistration> AllRegistrations() const

Get an array of all interests currently registered to the NetworkEventBus.

Returns

csp::common::Array<csp::multiplayer::NetworkEventRegistration> A container of all currently registered registrations.

bool StartEventMessageListening()

Instructs the event bus to start listening to messages.

Returns

True is successfully started listening, false if the connection is unavailable for some reason.

NetworkEventBus(MultiplayerConnection *InMultiplayerConnection, csp::common::LogSystem &LogSystem)

NetworkEventBus constructor.

Parameters

InMultiplayerConnection – MultiplayerConnection* : the multiplayer connection to construct the event bus with

~NetworkEventBus()

NetworkEventBus destructor.

Public Static Functions

static NetworkEvent NetworkEventFromString(const csp::common::String &EventString)
static csp::common::String StringFromNetworkEvent(NetworkEvent Event)