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
enumerator AsyncCallCompleted
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
  • EventName – : The identifying name for the event.

  • Args – : An array of arguments (csp::common::ReplicatedValue) to be passed as part of the event payload.

  • Callback – : a callback with failure state.

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
  • EventName – : The identifying name for the event.

  • Args – : An array of arguments (csp::common::ReplicatedValue) to be passed as part of the event payload.

  • TargetClientId – : The client ID to send the event to.

  • Callback – : a callback with failure state.

void ListenCustomNetworkEvent(csp::common::String EventReceiverId, csp::common::String EventName, CustomNetworkEventCallback Callback)

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

Note

This is for registration of custom events. To register for an event specializations, please use one of the dedicated listen methods. Registration will fail if a callback has already been registered with the same ReceiverId and EventName.

Parameters
  • ReceiverId – : The identifying name for the event receiver, used for management purposes. Allows clients to register multiple receivers for the same event if they choose.

  • EventName – : The identifying name for the event. May be any arbitrary string.

  • Callback – : Callback to invoke when the custom event is received. Will fail to register if the callback is null.

void ListenAccessControlChangedEvent(csp::common::String EventReceiverId, AccessControlChangedEventCallback Callback)

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

Note

Registration will fail if a callback has already been registered with the same ReceiverId.

Parameters
  • EventReceiverId – : The identifying name for the event receiver, used for management purposes. Allows clients to register multiple receivers for the same event if they choose.

  • Callback – : Callback to invoke when a access control changed event is received. Will fail to register if the callback is null.

void ListenAssetDetailBlobChangedEvent(csp::common::String EventReceiverId, AssetDetailBlobChangedEventCallback Callback)

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

Note

Registration will fail if a callback has already been registered with the same ReceiverId.

Parameters
  • EventReceiverId – : The identifying name for the event receiver, used for management purposes. Allows clients to register multiple receivers for the same event if they choose.

  • Callback – : Callback to invoke when a asset detail blob changed event is received. Will fail to register if the callback is null.

void ListenAsyncCallCompletedEvent(csp::common::String EventReceiverId, csp::common::String OperationName, AsyncCallCompletedEventCallback Callback)

Register interest in a async call completed network event for a specific operation, such that the NetworkEventBus will call the provided callback when it arrives.

Note

Registration will fail if a callback has already been registered with the same ReceiverId and OperationName.

Parameters
  • EventReceiverId – : The identifying name for the event receiver, used for management purposes. Allows clients to register multiple receivers for the same event if they choose.

  • OperationName – : The name of the async call completed operation, eg: ‘DuplicateSpaceAsync’ or ‘CreateSnapshotAsync’.

  • Callback – : Callback to invoke when a async call completed event is received with a specific operation name. Will fail to register if the callback is null.

void ListenConversationEvent(csp::common::String EventReceiverId, ConversationEventCallback Callback)

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

Note

Registration will fail if a callback has already been registered with the same ReceiverId.

Parameters
  • EventReceiverId – : The identifying name for the event receiver, used for management purposes. Allows clients to register multiple receivers for the same event if they choose.

  • Callback – : Callback to invoke when a conversation event is received. Will fail to register if the callback is null.

void ListenSequenceChangedEvent(csp::common::String EventReceiverId, SequenceChangedEventCallback Callback)

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

Note

Registration will fail if a callback has already been registered with the same ReceiverId.

Parameters
  • EventReceiverId – : The identifying name for the event receiver, used for management purposes. Allows clients to register multiple receivers for the same event if they choose.

  • Callback – : Callback to invoke when a sequence changed event is received. Will fail to register if the callback is null.

void StopListenCustomNetworkEvent(csp::common::String EventReceiverId, csp::common::String EventName)

Deregister interest in a custom network event.

Parameters
  • ReceiverId – : The identifying name for the event receiver.

  • EventName – : The identifying name for the event.

void StopListenAccessControlChangedEvent(csp::common::String EventReceiverId)

Deregister interest in a access control changed network event.

Parameters

ReceiverId – : The identifying name for the event receiver.

void StopListenAssetDetailBlobChangedEvent(csp::common::String EventReceiverId)

Deregister interest in a asset detail blob changed network event.

Parameters

ReceiverId – : The identifying name for the event receiver.

void StopListenAsyncCallCompletedEvent(csp::common::String EventReceiverId, csp::common::String OperationName)

Deregister interest in a async call completed network event.

Parameters

ReceiverId – : The identifying name for the event receiver.

void StopListenConversationEvent(csp::common::String EventReceiverId)

Deregister interest in a conversation network event.

Parameters

ReceiverId – : The identifying name for the event receiver.

void StopListenSequenceChangedEvent(csp::common::String EventReceiverId)

Deregister interest in a sequence changed network event.

Parameters

ReceiverId – : The identifying name for the event receiver.

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

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

Parameters

EventReceiverId – : EventReceiverId to deregister.

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

Get an array of all network event registrations currently registered with the NetworkEventBus.

Returns

An array of all current network event 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 – : the multiplayer connection to construct the event bus with

  • LogSystem – : Logger such that this system can print status and debug output

~NetworkEventBus()

NetworkEventBus destructor.

Public Static Functions

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