Table of Contents

Class AbstractHapChannel

Namespace
AppleTvControlLibrary.Mrp.AirPlay.Channels
Assembly
AppleTvControlLibrary.Mrp.dll

Base class for a TCP connection using HAP encryption and length-based segmenting, as used by the AirPlay 2 event and data-stream channels.

public abstract class AbstractHapChannel : IDisposable
Inheritance
AbstractHapChannel
Implements
Derived
Inherited Members

Remarks

This is the transport-level piece; message-specific encode/decode and dispatch belong to subclasses (see DataStreamChannel).

Constructors

AbstractHapChannel(byte[], byte[])

Initializes a new instance of the AbstractHapChannel class.

protected AbstractHapChannel(byte[] outputKey, byte[] inputKey)

Parameters

outputKey byte[]

The key used to encrypt outgoing data.

inputKey byte[]

The key used to decrypt incoming data.

Properties

Buffer

Gets the accumulated, decrypted-but-not-yet-consumed receive buffer.

protected List<byte> Buffer { get; }

Property Value

List<byte>

Remarks

Subclasses drain this in HandleReceived() as complete messages become available.

Methods

ConnectAsync(string, int, CancellationToken)

Connect to the remote endpoint and start the background read loop.

public Task ConnectAsync(string address, int port, CancellationToken cancellationToken = default)

Parameters

address string

The remote address.

port int

The remote port.

cancellationToken CancellationToken

A token used to cancel the connection attempt.

Returns

Task

Dispose()

Closes the channel.

public void Dispose()

HandleReceived()

Handle data that has been decrypted and appended to Buffer.

protected abstract void HandleReceived()

OnConnectionLost(Exception?)

Called when the underlying connection is dropped, cleanly or otherwise.

protected virtual void OnConnectionLost(Exception? exception)

Parameters

exception Exception

The exception that caused the drop, or null for a clean close.

Send(byte[])

Send raw (pre-encryption) data to the remote device.

protected void Send(byte[] data)

Parameters

data byte[]

The plaintext to encrypt and send.