Table of Contents

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

Exception

IsEncrypted

Gets a value indicating whether encryption has been enabled.

public bool IsEncrypted { get; }

Property Value

bool

IsFaulted

Gets a value indicating whether this connection has been faulted.

public bool IsFaulted { get; }

Property Value

bool

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

frameType FrameType

The type of frame being sent.

data byte[]

The frame payload.

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

outputKey byte[]

The key used to encrypt outgoing data.

inputKey byte[]

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

exception Exception

The 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

data byte[]

The bytes received from the transport.

Events

Faulted

Raised when this connection enters its terminal faulted state.

public event ConnectionFaultedCallback? Faulted

Event Type

ConnectionFaultedCallback

FrameReceived

Raised when a complete frame has been received (and decrypted, if applicable).

public event FrameReceivedCallback? FrameReceived

Event Type

FrameReceivedCallback