SwitcherConnections
public protocol SwitcherConnections
Interact with connections to a switcher.
Used to send messages to all connected controllers and to attach message handlers to incoming Message
s.
Handlers are functions that will be executed when a certain type of Message is received by the Switcher
.
-
Queues a message to be sent to all connected controllers.
The message will be serialized immediately into a byte array and appended to the outgoing buffer of all the connected controllers. These buffers will be flushed after at most 20ms.
Declaration
Swift
func send(_ message: SerializableMessage)
-
Attaches a message handler to a concrete
Message
type. Every time a message of this type comes in, the providedhandler
will be called with two parameters: the message itself and the origin of the message. The handler takes one generic argumentmessage
. The type of this argument indicates the type that this message handler will be attached to.Declaration
Swift
func when<M>(_ handler: @escaping (_ message: M, _ context: ConnectionState) -> Void) where M : DeserializableMessage
Parameters
handler
The handler to attach
message
The message to which the handler is attached
context
The origin of the message. Use this parameter to reply directly to the sender of the message.