ControllerConnection
public protocol ControllerConnection : AnyObject
A connection of a controller to a switcher. Use it to interact with the switcher: send messages and attach message handlers for incoming Message
s.
Message handlers are functions that will be executed when a certain type of Message is received by the Controller
.
Attach a handler to a certain type of Message
by calling
connection.when { message: <MessageType> in
// Handle your message here
}
Replace <MessageType>
with a concrete type that conforms to the Message
protocol (eg: ProgramBusChanged
).
-
Sends a message to the connected switcher.
Declaration
Swift
func send(_ message: SerializableMessage)
Parameters
message
the message that will be sent to the switcher
-
Undocumented
Declaration
Swift
func sendSeparately(messages: [UInt8])
-
A function that will be called when the connection is lost
Declaration
Swift
var whenDisconnected: (() -> Void)? { get set }
-
A function that will be called when an error occurs
Declaration
Swift
var whenError: (Error) -> Void { get set }
-
Attaches a message handler to a concrete
Message
type. Every time a message of this type comes in, the providedhandler
will be called. 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) -> Void) where M : DeserializableMessage
Parameters
handler
The handler to attach
message
The message to which the handler is attached