Table of Contents

Class AirPlayMrpConnection

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

MRP connection implemented as a channel/stream tunneled over an AirPlay 2 data-stream channel, rather than a raw TCP socket. This is the adapter that lets MrpProtocol be driven by an already-established Ap2Session instead of the retired raw-TCP TcpMrpTransport (see archive/mrp-tcp-transport).

public sealed class AirPlayMrpConnection : IMrpFrameConnection, IDataStreamListener, IDisposable
Inheritance
AirPlayMrpConnection
Implements
Inherited Members

Remarks

Initializes a new instance of the AirPlayMrpConnection class.

Constructors

AirPlayMrpConnection(Ap2Session)

MRP connection implemented as a channel/stream tunneled over an AirPlay 2 data-stream channel, rather than a raw TCP socket. This is the adapter that lets MrpProtocol be driven by an already-established Ap2Session instead of the retired raw-TCP TcpMrpTransport (see archive/mrp-tcp-transport).

public AirPlayMrpConnection(Ap2Session session)

Parameters

session Ap2Session

An Ap2Session for which SetupRemoteControlAsync(CancellationToken) has already completed.

Remarks

Initializes a new instance of the AirPlayMrpConnection class.

Properties

Listener

Gets or sets the listener for received MRP messages and connection events.

public IMrpConnectionListener? Listener { get; set; }

Property Value

IMrpConnectionListener

The connection listener, or null if none is assigned.

Methods

BuildMessage(byte[])

Passes the serialized protobuf message through for AirPlay framing.

public byte[] BuildMessage(byte[] data)

Parameters

data byte[]

The serialized protobuf message.

Returns

byte[]

The supplied byte array without modification.

Remarks

The AirPlay data channel does its own framing (see SendProtobuf(ProtocolMessage)), so this is an identity passthrough rather than the variant-length prefixing used by direct TCP MRP; the actual send happens in SendAsync(byte[]).

Connect()

Attach this adapter to the session's already-established data channel.

public void Connect()

Dispose()

Closes the underlying AirPlay session.

public void Dispose()

EnableEncryption(byte[], byte[])

Accepts encryption keys without changing the already encrypted AirPlay data channel.

public void EnableEncryption(byte[] outputKey, byte[] inputKey)

Parameters

outputKey byte[]

The outgoing encryption key; unused by this adapter.

inputKey byte[]

The incoming encryption key; unused by this adapter.

HandleConnectionLost(Exception?)

Device connection was dropped.

public void HandleConnectionLost(Exception? exception)

Parameters

exception Exception

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

HandleProtobuf(ProtocolMessage)

Handle an incoming protobuf message tunneled over the data channel.

public void HandleProtobuf(ProtocolMessage message)

Parameters

message ProtocolMessage

The decoded message.

SendAsync(byte[])

Gets or sets an asynchronous callback for transmitting a fully-built frame.

public Task SendAsync(byte[] frame)

Parameters

frame byte[]

The serialized MRP protobuf message to send through the AirPlay data channel.

Returns

Task

A task that completes when the message has been sent through the connection.

Remarks

Set by AsyncSender; this adapter re-parses the frame (produced by BuildMessage(byte[]) as a byte-identity passthrough) back into a ProtocolMessage so it can be handed to SendProtobuf(ProtocolMessage), which does its own AirPlay-specific framing rather than the variant-length framing used by direct TCP MRP.

Events

ConnectionLost

Raised when the underlying AirPlay data channel is dropped.

public event Action<Exception?>? ConnectionLost

Event Type

Action<Exception>