Class CompanionConnection
- Namespace
- AppleTvControlLibrary.Connection
- Assembly
- AppleTvControlLibrary.dll
Frame-level protocol handling for a Companion Link connection: header framing, buffering of partial frames and transparent ChaCha20-Poly1305 encryption.
public class CompanionConnection
- Inheritance
-
CompanionConnection
- Inherited Members
Remarks
This type intentionally has no socket I/O of its own; a caller feeds inbound bytes via ReceiveData(byte[]) and consumes outbound bytes via BuildFrame(FrameType, byte[]), so it can be driven by any transport (Socket, SslStream over sockets not applicable here, etc.) on either target framework.
Properties
FaultException
Gets the exception that caused the connection to be faulted, if any.
public Exception? FaultException { get; }
Property Value
IsEncrypted
Gets a value indicating whether encryption has been enabled.
public bool IsEncrypted { get; }
Property Value
IsFaulted
Gets a value indicating whether this connection has been faulted.
public bool IsFaulted { get; }
Property Value
Methods
BuildFrame(FrameType, byte[])
Build a framed (and, if encryption is enabled, encrypted) message ready to send.
public byte[] BuildFrame(FrameType frameType, byte[] data)
Parameters
Returns
- byte[]
The bytes to write to the transport, including the 4-byte header.
EnableEncryption(byte[], byte[])
Enable encryption with the specified keys.
public void EnableEncryption(byte[] outputKey, byte[] inputKey)
Parameters
outputKeybyte[]The key used to encrypt outgoing data.
inputKeybyte[]The key used to decrypt incoming data.
Fault(Exception?)
Faults the connection, preventing any further frames from being processed or sent.
public void Fault(Exception? exception = null)
Parameters
exceptionExceptionThe exception that caused the fault, if any.
ReceiveData(byte[])
Feed newly received bytes into the reassembly buffer, raising FrameReceived for each complete frame that becomes available.
public void ReceiveData(byte[] data)
Parameters
databyte[]The bytes received from the transport.
Events
Faulted
Raised when this connection enters its terminal faulted state.
public event ConnectionFaultedCallback? Faulted
Event Type
FrameReceived
Raised when a complete frame has been received (and decrypted, if applicable).
public event FrameReceivedCallback? FrameReceived