@basmilius/apple-airplay 0.0.30 → 0.0.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js.map CHANGED
@@ -82,7 +82,7 @@
82
82
  "// @generated by protoc-gen-es v2.10.0 with parameter \"target=ts\"\n// @generated from file VolumeControlCapabilitiesDidChangeMessage.proto (syntax proto2)\n/* eslint-disable */\n\nimport type { GenExtension, GenFile, GenMessage } from \"@bufbuild/protobuf/codegenv2\";\nimport { extDesc, fileDesc, messageDesc } from \"@bufbuild/protobuf/codegenv2\";\nimport type { ProtocolMessage } from \"./ProtocolMessage_pb\";\nimport { file_ProtocolMessage } from \"./ProtocolMessage_pb\";\nimport type { VolumeControlAvailabilityMessage } from \"./VolumeControlAvailabilityMessage_pb\";\nimport { file_VolumeControlAvailabilityMessage } from \"./VolumeControlAvailabilityMessage_pb\";\nimport type { Message } from \"@bufbuild/protobuf\";\n\n/**\n * Describes the file VolumeControlCapabilitiesDidChangeMessage.proto.\n */\nexport const file_VolumeControlCapabilitiesDidChangeMessage: GenFile = /*@__PURE__*/\n fileDesc(\"Ci9Wb2x1bWVDb250cm9sQ2FwYWJpbGl0aWVzRGlkQ2hhbmdlTWVzc2FnZS5wcm90byKSAQopVm9sdW1lQ29udHJvbENhcGFiaWxpdGllc0RpZENoYW5nZU1lc3NhZ2USNwoMY2FwYWJpbGl0aWVzGAEgASgLMiEuVm9sdW1lQ29udHJvbEF2YWlsYWJpbGl0eU1lc3NhZ2USEwoLZW5kcG9pbnRVSUQYAyABKAkSFwoPb3V0cHV0RGV2aWNlVUlEGAQgASgJOpoBCil2b2x1bWVDb250cm9sQ2FwYWJpbGl0aWVzRGlkQ2hhbmdlTWVzc2FnZRIQLlByb3RvY29sTWVzc2FnZRhEIAEoCzIqLlZvbHVtZUNvbnRyb2xDYXBhYmlsaXRpZXNEaWRDaGFuZ2VNZXNzYWdlUil2b2x1bWVDb250cm9sQ2FwYWJpbGl0aWVzRGlkQ2hhbmdlTWVzc2FnZQ\", [file_ProtocolMessage, file_VolumeControlAvailabilityMessage]);\n\n/**\n * @generated from message VolumeControlCapabilitiesDidChangeMessage\n */\nexport type VolumeControlCapabilitiesDidChangeMessage = Message<\"VolumeControlCapabilitiesDidChangeMessage\"> & {\n /**\n * @generated from field: optional VolumeControlAvailabilityMessage capabilities = 1;\n */\n capabilities?: VolumeControlAvailabilityMessage;\n\n /**\n * @generated from field: optional string endpointUID = 3;\n */\n endpointUID: string;\n\n /**\n * @generated from field: optional string outputDeviceUID = 4;\n */\n outputDeviceUID: string;\n};\n\n/**\n * Describes the message VolumeControlCapabilitiesDidChangeMessage.\n * Use `create(VolumeControlCapabilitiesDidChangeMessageSchema)` to create a new message.\n */\nexport const VolumeControlCapabilitiesDidChangeMessageSchema: GenMessage<VolumeControlCapabilitiesDidChangeMessage> = /*@__PURE__*/\n messageDesc(file_VolumeControlCapabilitiesDidChangeMessage, 0);\n\n/**\n * @generated from extension: optional VolumeControlCapabilitiesDidChangeMessage volumeControlCapabilitiesDidChangeMessage = 68;\n */\nexport const volumeControlCapabilitiesDidChangeMessage: GenExtension<ProtocolMessage, VolumeControlCapabilitiesDidChangeMessage> = /*@__PURE__*/\n extDesc(file_VolumeControlCapabilitiesDidChangeMessage, 0);\n\n",
83
83
  "// @generated by protoc-gen-es v2.10.0 with parameter \"target=ts\"\n// @generated from file VolumeDidChangeMessage.proto (syntax proto2)\n/* eslint-disable */\n\nimport type { GenExtension, GenFile, GenMessage } from \"@bufbuild/protobuf/codegenv2\";\nimport { extDesc, fileDesc, messageDesc } from \"@bufbuild/protobuf/codegenv2\";\nimport type { ProtocolMessage } from \"./ProtocolMessage_pb\";\nimport { file_ProtocolMessage } from \"./ProtocolMessage_pb\";\nimport type { Message } from \"@bufbuild/protobuf\";\n\n/**\n * Describes the file VolumeDidChangeMessage.proto.\n */\nexport const file_VolumeDidChangeMessage: GenFile = /*@__PURE__*/\n fileDesc(\"ChxWb2x1bWVEaWRDaGFuZ2VNZXNzYWdlLnByb3RvIlYKFlZvbHVtZURpZENoYW5nZU1lc3NhZ2USDgoGdm9sdW1lGAEgASgCEhMKC2VuZHBvaW50VUlEGAIgASgJEhcKD291dHB1dERldmljZVVJRBgDIAEoCTphChZ2b2x1bWVEaWRDaGFuZ2VNZXNzYWdlEhAuUHJvdG9jb2xNZXNzYWdlGDggASgLMhcuVm9sdW1lRGlkQ2hhbmdlTWVzc2FnZVIWdm9sdW1lRGlkQ2hhbmdlTWVzc2FnZQ\", [file_ProtocolMessage]);\n\n/**\n * @generated from message VolumeDidChangeMessage\n */\nexport type VolumeDidChangeMessage = Message<\"VolumeDidChangeMessage\"> & {\n /**\n * @generated from field: optional float volume = 1;\n */\n volume: number;\n\n /**\n * @generated from field: optional string endpointUID = 2;\n */\n endpointUID: string;\n\n /**\n * @generated from field: optional string outputDeviceUID = 3;\n */\n outputDeviceUID: string;\n};\n\n/**\n * Describes the message VolumeDidChangeMessage.\n * Use `create(VolumeDidChangeMessageSchema)` to create a new message.\n */\nexport const VolumeDidChangeMessageSchema: GenMessage<VolumeDidChangeMessage> = /*@__PURE__*/\n messageDesc(file_VolumeDidChangeMessage, 0);\n\n/**\n * @generated from extension: optional VolumeDidChangeMessage volumeDidChangeMessage = 56;\n */\nexport const volumeDidChangeMessage: GenExtension<ProtocolMessage, VolumeDidChangeMessage> = /*@__PURE__*/\n extDesc(file_VolumeDidChangeMessage, 0);\n\n",
84
84
  "// @generated by protoc-gen-es v2.10.0 with parameter \"target=ts\"\n// @generated from file WakeDeviceMessage.proto (syntax proto2)\n/* eslint-disable */\n\nimport type { GenExtension, GenFile, GenMessage } from \"@bufbuild/protobuf/codegenv2\";\nimport { extDesc, fileDesc, messageDesc } from \"@bufbuild/protobuf/codegenv2\";\nimport type { ProtocolMessage } from \"./ProtocolMessage_pb\";\nimport { file_ProtocolMessage } from \"./ProtocolMessage_pb\";\nimport type { Message } from \"@bufbuild/protobuf\";\n\n/**\n * Describes the file WakeDeviceMessage.proto.\n */\nexport const file_WakeDeviceMessage: GenFile = /*@__PURE__*/\n fileDesc(\"ChdXYWtlRGV2aWNlTWVzc2FnZS5wcm90byITChFXYWtlRGV2aWNlTWVzc2FnZTpSChF3YWtlRGV2aWNlTWVzc2FnZRIQLlByb3RvY29sTWVzc2FnZRgtIAEoCzISLldha2VEZXZpY2VNZXNzYWdlUhF3YWtlRGV2aWNlTWVzc2FnZQ\", [file_ProtocolMessage]);\n\n/**\n * @generated from message WakeDeviceMessage\n */\nexport type WakeDeviceMessage = Message<\"WakeDeviceMessage\"> & {\n};\n\n/**\n * Describes the message WakeDeviceMessage.\n * Use `create(WakeDeviceMessageSchema)` to create a new message.\n */\nexport const WakeDeviceMessageSchema: GenMessage<WakeDeviceMessage> = /*@__PURE__*/\n messageDesc(file_WakeDeviceMessage, 0);\n\n/**\n * @generated from extension: optional WakeDeviceMessage wakeDeviceMessage = 45;\n */\nexport const wakeDeviceMessage: GenExtension<ProtocolMessage, WakeDeviceMessage> = /*@__PURE__*/\n extDesc(file_WakeDeviceMessage, 0);\n\n",
85
- "import { uuid } from '@basmilius/apple-common';\nimport { create, setExtension } from '@bufbuild/protobuf';\nimport * as Proto from '@/proto';\n\nexport default class {\n clientUpdatesConfig(): Proto.ProtocolMessage {\n const protocolMessage = this.protocol(Proto.ProtocolMessage_Type.CLIENT_UPDATES_CONFIG_MESSAGE);\n const message = create(Proto.ClientUpdatesConfigMessageSchema, {\n artworkUpdates: true,\n nowPlayingUpdates: true,\n volumeUpdates: true,\n keyboardUpdates: false,\n outputDeviceUpdates: true,\n Unknown1: false\n });\n\n setExtension(protocolMessage, Proto.clientUpdatesConfigMessage, message);\n\n return protocolMessage;\n }\n\n configureConnection(groupId: string): Proto.ProtocolMessage {\n const protocolMessage = this.protocol(Proto.ProtocolMessage_Type.CONFIGURE_CONNECTION_MESSAGE);\n const message = create(Proto.ConfigureConnectionMessageSchema, {\n groupID: groupId\n });\n\n setExtension(protocolMessage, Proto.configureConnectionMessage, message);\n\n return protocolMessage;\n }\n\n deviceInfo(pairingId: Buffer): Proto.ProtocolMessage {\n const protocolMessage = this.protocol(Proto.ProtocolMessage_Type.DEVICE_INFO_MESSAGE);\n const message = create(Proto.DeviceInfoMessageSchema, {\n uniqueIdentifier: pairingId.toString(),\n name: 'iPhone van Bas',\n localizedModelName: 'iPhone',\n systemBuildVersion: '23C5027f',\n applicationBundleIdentifier: 'com.apple.mediaremoted',\n protocolVersion: 1,\n lastSupportedMessageType: 139,\n supportsSystemPairing: true,\n allowsPairing: true,\n systemMediaApplication: 'com.apple.Music',\n supportsACL: true,\n supportsSharedQueue: true,\n sharedQueueVersion: 3,\n managedConfigDeviceID: 'c4:c1:7d:93:d2:13',\n deviceClass: Proto.DeviceClass_Enum.iPhone,\n logicalDeviceCount: 1,\n isProxyGroupPlayer: false,\n groupUID: uuid().toUpperCase(),\n isGroupLeader: true,\n isAirplayActive: false,\n systemPodcastApplication: 'com.apple.podcasts',\n senderDefaultGroupUID: uuid().toUpperCase(),\n clusterType: 0,\n isClusterAware: true,\n modelID: 'iPhone16,2',\n supportsMultiplayer: false,\n routingContextID: uuid().toUpperCase(),\n airPlayGroupID: uuid().toUpperCase(),\n systemBooksApplication: 'com.apple.iBooks',\n parentGroupContainsDiscoverableGroupLeader: 1,\n groupContainsDiscoverableGroupLeader: 1,\n lastKnownClusterType: 2,\n supportsOutputContextSync: true,\n computerName: 'iPhone van Bas',\n configuredClusterSize: 0\n // applicationBundleVersion: '344.28',\n // protocolVersion: 1,\n // lastSupportedMessageType: 108,\n // supportsSystemPairing: true,\n // allowsPairing: true,\n // systemMediaApplication: 'com.apple.TVMusic',\n // supportsACL: true,\n // supportsSharedQueue: true,\n // supportsExtendedMotion: true,\n // sharedQueueVersion: 2,\n // deviceClass: 1,\n // logicalDeviceCount: 1\n });\n\n setExtension(protocolMessage, Proto.deviceInfoMessage, message);\n\n return protocolMessage;\n }\n\n notification(notification: string[]): Proto.ProtocolMessage {\n const protocolMessage = this.protocol(Proto.ProtocolMessage_Type.NOTIFICATION_MESSAGE);\n const message = create(Proto.NotificationMessageSchema, {\n notification\n });\n\n setExtension(protocolMessage, Proto.notificationMessage, message);\n\n return protocolMessage;\n }\n\n protocol(type: Proto.ProtocolMessage_Type, errorCode: Proto.ErrorCode_Enum = Proto.ErrorCode_Enum.NoError): Proto.ProtocolMessage {\n return create(Proto.ProtocolMessageSchema, {\n type,\n errorCode,\n identifier: uuid().toUpperCase(),\n uniqueIdentifier: uuid().toUpperCase()\n });\n }\n\n sendButtonEvent(usagePage: number, usage: number, buttonDown: boolean): Proto.ProtocolMessage {\n const protocolMessage = this.protocol(Proto.ProtocolMessage_Type.SEND_BUTTON_EVENT_MESSAGE);\n const message = create(Proto.SendButtonEventMessageSchema, {\n usagePage,\n usage,\n buttonDown\n });\n\n setExtension(protocolMessage, Proto.sendButtonEventMessage, message);\n\n return protocolMessage;\n }\n\n sendCommand(command: Proto.Command, options?: Proto.CommandOptions): Proto.ProtocolMessage {\n const protocolMessage = this.protocol(Proto.ProtocolMessage_Type.SEND_COMMAND_MESSAGE);\n const message = create(Proto.SendCommandMessageSchema, {\n command,\n options\n });\n\n setExtension(protocolMessage, Proto.sendCommandMessage, message);\n\n return protocolMessage;\n }\n\n setConnectionState(state: Proto.SetConnectionStateMessage_ConnectionState = Proto.SetConnectionStateMessage_ConnectionState.Connected): Proto.ProtocolMessage {\n const protocolMessage = this.protocol(Proto.ProtocolMessage_Type.SET_CONNECTION_STATE_MESSAGE);\n const message = create(Proto.SetConnectionStateMessageSchema, {\n state\n });\n\n setExtension(protocolMessage, Proto.setConnectionStateMessage, message);\n\n return protocolMessage;\n }\n\n setVolume(volume: number): Proto.ProtocolMessage {\n const protocolMessage = this.protocol(Proto.ProtocolMessage_Type.SET_VOLUME_MESSAGE);\n const message = create(Proto.SetVolumeMessageSchema, {\n volume\n });\n\n setExtension(protocolMessage, Proto.setVolumeMessage, message);\n\n return protocolMessage;\n }\n}\n",
85
+ "import { uuid } from '@basmilius/apple-common';\nimport { create, setExtension } from '@bufbuild/protobuf';\nimport * as Proto from '../proto';\n\nexport default class {\n clientUpdatesConfig(): Proto.ProtocolMessage {\n const protocolMessage = this.protocol(Proto.ProtocolMessage_Type.CLIENT_UPDATES_CONFIG_MESSAGE);\n const message = create(Proto.ClientUpdatesConfigMessageSchema, {\n artworkUpdates: true,\n nowPlayingUpdates: true,\n volumeUpdates: true,\n keyboardUpdates: false,\n outputDeviceUpdates: true,\n Unknown1: false\n });\n\n setExtension(protocolMessage, Proto.clientUpdatesConfigMessage, message);\n\n return protocolMessage;\n }\n\n configureConnection(groupId: string): Proto.ProtocolMessage {\n const protocolMessage = this.protocol(Proto.ProtocolMessage_Type.CONFIGURE_CONNECTION_MESSAGE);\n const message = create(Proto.ConfigureConnectionMessageSchema, {\n groupID: groupId\n });\n\n setExtension(protocolMessage, Proto.configureConnectionMessage, message);\n\n return protocolMessage;\n }\n\n deviceInfo(pairingId: Buffer): Proto.ProtocolMessage {\n const protocolMessage = this.protocol(Proto.ProtocolMessage_Type.DEVICE_INFO_MESSAGE);\n const message = create(Proto.DeviceInfoMessageSchema, {\n uniqueIdentifier: pairingId.toString(),\n name: 'iPhone van Bas',\n localizedModelName: 'iPhone',\n systemBuildVersion: '23C5027f',\n applicationBundleIdentifier: 'com.apple.mediaremoted',\n protocolVersion: 1,\n lastSupportedMessageType: 139,\n supportsSystemPairing: true,\n allowsPairing: true,\n systemMediaApplication: 'com.apple.Music',\n supportsACL: true,\n supportsSharedQueue: true,\n sharedQueueVersion: 3,\n managedConfigDeviceID: 'c4:c1:7d:93:d2:13',\n deviceClass: Proto.DeviceClass_Enum.iPhone,\n logicalDeviceCount: 1,\n isProxyGroupPlayer: false,\n groupUID: uuid().toUpperCase(),\n isGroupLeader: true,\n isAirplayActive: false,\n systemPodcastApplication: 'com.apple.podcasts',\n senderDefaultGroupUID: uuid().toUpperCase(),\n clusterType: 0,\n isClusterAware: true,\n modelID: 'iPhone16,2',\n supportsMultiplayer: false,\n routingContextID: uuid().toUpperCase(),\n airPlayGroupID: uuid().toUpperCase(),\n systemBooksApplication: 'com.apple.iBooks',\n parentGroupContainsDiscoverableGroupLeader: 1,\n groupContainsDiscoverableGroupLeader: 1,\n lastKnownClusterType: 2,\n supportsOutputContextSync: true,\n computerName: 'iPhone van Bas',\n configuredClusterSize: 0\n // applicationBundleVersion: '344.28',\n // protocolVersion: 1,\n // lastSupportedMessageType: 108,\n // supportsSystemPairing: true,\n // allowsPairing: true,\n // systemMediaApplication: 'com.apple.TVMusic',\n // supportsACL: true,\n // supportsSharedQueue: true,\n // supportsExtendedMotion: true,\n // sharedQueueVersion: 2,\n // deviceClass: 1,\n // logicalDeviceCount: 1\n });\n\n setExtension(protocolMessage, Proto.deviceInfoMessage, message);\n\n return protocolMessage;\n }\n\n notification(notification: string[]): Proto.ProtocolMessage {\n const protocolMessage = this.protocol(Proto.ProtocolMessage_Type.NOTIFICATION_MESSAGE);\n const message = create(Proto.NotificationMessageSchema, {\n notification\n });\n\n setExtension(protocolMessage, Proto.notificationMessage, message);\n\n return protocolMessage;\n }\n\n protocol(type: Proto.ProtocolMessage_Type, errorCode: Proto.ErrorCode_Enum = Proto.ErrorCode_Enum.NoError): Proto.ProtocolMessage {\n return create(Proto.ProtocolMessageSchema, {\n type,\n errorCode,\n identifier: uuid().toUpperCase(),\n uniqueIdentifier: uuid().toUpperCase()\n });\n }\n\n sendButtonEvent(usagePage: number, usage: number, buttonDown: boolean): Proto.ProtocolMessage {\n const protocolMessage = this.protocol(Proto.ProtocolMessage_Type.SEND_BUTTON_EVENT_MESSAGE);\n const message = create(Proto.SendButtonEventMessageSchema, {\n usagePage,\n usage,\n buttonDown\n });\n\n setExtension(protocolMessage, Proto.sendButtonEventMessage, message);\n\n return protocolMessage;\n }\n\n sendCommand(command: Proto.Command, options?: Proto.CommandOptions): Proto.ProtocolMessage {\n const protocolMessage = this.protocol(Proto.ProtocolMessage_Type.SEND_COMMAND_MESSAGE);\n const message = create(Proto.SendCommandMessageSchema, {\n command,\n options\n });\n\n setExtension(protocolMessage, Proto.sendCommandMessage, message);\n\n return protocolMessage;\n }\n\n setConnectionState(state: Proto.SetConnectionStateMessage_ConnectionState = Proto.SetConnectionStateMessage_ConnectionState.Connected): Proto.ProtocolMessage {\n const protocolMessage = this.protocol(Proto.ProtocolMessage_Type.SET_CONNECTION_STATE_MESSAGE);\n const message = create(Proto.SetConnectionStateMessageSchema, {\n state\n });\n\n setExtension(protocolMessage, Proto.setConnectionStateMessage, message);\n\n return protocolMessage;\n }\n\n setVolume(volume: number): Proto.ProtocolMessage {\n const protocolMessage = this.protocol(Proto.ProtocolMessage_Type.SET_VOLUME_MESSAGE);\n const message = create(Proto.SetVolumeMessageSchema, {\n volume\n });\n\n setExtension(protocolMessage, Proto.setVolumeMessage, message);\n\n return protocolMessage;\n }\n}\n",
86
86
  "import { Socket } from 'node:net';\nimport { BaseSocket, debug, decryptChacha20, encryptChacha20 } from '@basmilius/apple-common';\n\nexport default class AirPlayStream<TEventMap extends Record<string, any>> extends BaseSocket<TEventMap> {\n get isConnected(): boolean {\n return this.#socket.readyState === 'open';\n }\n\n get isEncrypted(): boolean {\n return !!this.#readKey && !!this.#writeKey;\n }\n\n get socket(): Socket {\n return this.#socket;\n }\n\n get readKey(): Buffer {\n return this.#readKey;\n }\n\n get writeKey(): Buffer {\n return this.#writeKey;\n }\n\n readonly #socket: Socket;\n #buffer: Buffer = Buffer.alloc(0);\n #readCount: number;\n #readKey?: Buffer;\n #writeCount: number;\n #writeKey?: Buffer;\n\n constructor(address: string, port: number) {\n super(address, port);\n\n this.onClose = this.onClose.bind(this);\n this.onConnect = this.onConnect.bind(this);\n this.onData = this.onData.bind(this);\n this.onEnd = this.onEnd.bind(this);\n this.onError = this.onError.bind(this);\n\n this.#socket = new Socket();\n this.#socket.on('close', this.onClose);\n this.#socket.on('connect', this.onConnect);\n this.#socket.on('data', this.onData);\n this.#socket.on('end', this.onEnd);\n this.#socket.on('error', this.onError);\n }\n\n async connect(): Promise<void> {\n debug(`Connecting to ${this.address}:${this.port}...`);\n\n return await new Promise(resolve => {\n this.#socket.connect({\n host: this.address,\n port: this.port,\n keepAlive: true\n }, resolve);\n });\n }\n\n async disconnect(): Promise<void> {\n this.#socket.destroy();\n }\n\n async enableEncryption(readKey: Buffer, writeKey: Buffer): Promise<void> {\n this.#readKey = readKey;\n this.#writeKey = writeKey;\n this.#readCount = 0;\n this.#writeCount = 0;\n }\n\n async decrypt(data: Buffer): Promise<Buffer> {\n if (this.#buffer) {\n data = Buffer.concat([this.#buffer, data]);\n this.#buffer = undefined;\n }\n\n let result = Buffer.alloc(0);\n let offset = 0;\n\n while (offset + 2 <= data.length) {\n const length = data.readUInt16LE(offset);\n\n const totalChunkLength = 2 + length + 16;\n\n if (offset + totalChunkLength > data.length) {\n this.#buffer = data.subarray(offset);\n break;\n }\n\n const aad = data.subarray(offset, offset + 2);\n const ciphertext = data.subarray(offset + 2, offset + 2 + length);\n const authTag = data.subarray(offset + 2 + length, offset + 2 + length + 16);\n\n const nonce = Buffer.alloc(12);\n nonce.writeBigUInt64LE(BigInt(this.#readCount++), 4);\n\n const plaintext = decryptChacha20(\n this.#readKey,\n nonce,\n aad,\n ciphertext,\n authTag\n );\n\n result = Buffer.concat([result, plaintext]);\n offset += totalChunkLength;\n }\n\n return result;\n }\n\n async encrypt(data: Buffer): Promise<Buffer> {\n const total = data.length;\n let result = Buffer.alloc(0);\n\n for (let offset = 0; offset < total;) {\n const length = Math.min(total - offset, 0x400);\n const leLength = Buffer.alloc(2);\n leLength.writeUInt16LE(length, 0);\n\n const nonce = Buffer.alloc(12);\n nonce.writeBigUInt64LE(BigInt(this.#writeCount++), 4);\n\n const encrypted = encryptChacha20(\n this.#writeKey,\n nonce,\n leLength,\n data.subarray(offset, offset + length)\n );\n\n offset += length;\n result = Buffer.concat([result, leLength, encrypted.ciphertext, encrypted.authTag]);\n }\n\n return result;\n }\n\n async onClose(): Promise<void> {\n await super.onClose();\n\n debug(`Connection closed from ${this.address}:${this.port}`);\n }\n\n async onConnect(): Promise<void> {\n await super.onConnect();\n\n debug(`Connected to ${this.address}:${this.port}`);\n }\n\n async onData(buffer: Buffer): Promise<void> {\n debug('Data frame received', buffer.toString());\n }\n\n async onEnd(): Promise<void> {\n debug('Connection ended');\n }\n\n async onError(err: Error): Promise<void> {\n await super.onError(err);\n\n debug('Error received', err);\n }\n}\n",
87
87
  "import { debug, hkdf, parseBinaryPlist } from '@basmilius/apple-common';\nimport type { RTSPMethod } from './types';\nimport { makeHttpRequest } from './utils';\nimport AirPlayStream from './stream';\n\nexport default class AirPlayEventStream extends AirPlayStream<never> {\n #buffer: Buffer = Buffer.alloc(0);\n\n async respond(response: Response): Promise<void> {\n const body = Buffer.from(await response.arrayBuffer());\n\n const header = [];\n header.push(`RTSP/1.0 ${response.status} ${response.statusText}`);\n\n for (const [name, value] of Object.entries(response.headers)) {\n header.push(`${name}: ${value}`);\n }\n\n if (body.byteLength > 0) {\n header.push(`Content-Length: ${body.byteLength}`);\n } else {\n header.push('Content-Length: 0');\n }\n\n header.push('');\n header.push('');\n\n const headers = header.join('\\r\\n');\n let data: Buffer;\n\n if (response.body) {\n data = Buffer.concat([\n Buffer.from(headers),\n body\n ]);\n } else {\n data = Buffer.from(headers);\n }\n\n if (this.isEncrypted) {\n data = await this.encrypt(data);\n }\n\n this.socket.write(data);\n }\n\n async setup(sharedSecret: Buffer): Promise<void> {\n const readKey = hkdf({\n hash: 'sha512',\n key: sharedSecret,\n length: 32,\n salt: Buffer.from('Events-Salt'),\n info: Buffer.from('Events-Read-Encryption-Key')\n });\n\n const writeKey = hkdf({\n hash: 'sha512',\n key: sharedSecret,\n length: 32,\n salt: Buffer.from('Events-Salt'),\n info: Buffer.from('Events-Write-Encryption-Key')\n });\n\n await this.enableEncryption(writeKey, readKey);\n }\n\n async onData(buffer: Buffer): Promise<void> {\n this.#buffer = Buffer.concat([this.#buffer, buffer]);\n\n if (this.isEncrypted) {\n this.#buffer = await this.decrypt(this.#buffer);\n }\n\n // debug('Event stream received data', this.#buffer.toString());\n\n while (this.#buffer.byteLength > 0) {\n const result = makeHttpRequest(this.#buffer);\n\n if (result === null) {\n return;\n }\n\n this.#buffer = this.#buffer.subarray(result.requestLength);\n\n await this.#handle(result.method, result.path, result.headers, result.body);\n }\n }\n\n async #handle(method: RTSPMethod, path: string, headers: Record<string, string>, body: Buffer): Promise<void> {\n const key = `${method} ${path}`;\n\n debug(key);\n\n switch (key) {\n case 'POST /command':\n const data = parseBinaryPlist(body.buffer.slice(body.byteOffset, body.byteOffset + body.byteLength) as any) as any;\n\n debug(data);\n\n const response = new Response(null, {\n status: 200,\n statusText: 'OK',\n headers: {\n 'Audio-Latency': '0',\n 'CSeq': (headers['CSeq'] ?? 0).toString()\n }\n });\n\n await this.respond(response);\n break;\n\n default:\n debug('No handler for url', key);\n break;\n }\n }\n}\n",
88
88
  "import { type AccessoryCredentials, type AccessoryKeys, AccessoryPair } from '@basmilius/apple-common';\nimport type AirPlay from './protocol';\nimport type AirPlayRTSP from './rtsp';\n\nexport default class AirPlayPairing {\n get internal(): AccessoryPair {\n return this.#internal;\n }\n\n get rtsp(): AirPlayRTSP {\n return this.#protocol.rtsp;\n }\n\n readonly #internal: AccessoryPair;\n readonly #protocol: AirPlay;\n #hkp: 3 | 4;\n\n constructor(protocol: AirPlay) {\n this.#internal = new AccessoryPair(this.#request.bind(this));\n this.#protocol = protocol;\n }\n\n async start(): Promise<void> {\n await this.#internal.start();\n }\n\n async pin(askPin: () => Promise<string>): Promise<AccessoryCredentials> {\n this.#hkp = 3;\n\n await this.#pinStart();\n\n return this.#internal.pin(askPin);\n }\n\n async pinStart(): Promise<void> {\n this.#hkp = 3;\n\n await this.#pinStart();\n }\n\n async transient(): Promise<AccessoryKeys> {\n this.#hkp = 4;\n\n await this.#pinStart();\n\n return this.#internal.transient();\n }\n\n async #pinStart(): Promise<void> {\n const response = await this.rtsp.post('/pair-pin-start', null, {\n 'Content-Type': 'application/octet-stream',\n 'X-Apple-HKP': this.#hkp.toString()\n });\n\n if (response.status !== 200) {\n throw new Error('Cannot start pairing session.');\n }\n }\n\n async #request(_: 'm1' | 'm3' | 'm5', data: Buffer): Promise<Buffer> {\n const response = await this.rtsp.post('/pair-setup', data, {\n 'Content-Type': 'application/octet-stream',\n 'X-Apple-HKP': this.#hkp.toString()\n });\n\n return Buffer.from(await response.arrayBuffer());\n }\n}\n",
@@ -1,4 +1,4 @@
1
- import * as Proto from "@/proto";
1
+ import * as Proto from "../proto";
2
2
  export default class {
3
3
  clientUpdatesConfig(): Proto.ProtocolMessage;
4
4
  configureConnection(groupId: string): Proto.ProtocolMessage;
package/dist/test.js.map CHANGED
@@ -2,7 +2,7 @@
2
2
  "version": 3,
3
3
  "sources": ["../src/test.ts", "../src/protocol/protocol.ts", "../src/protocol/utils.ts", "../src/protocol/dataStream.ts", "../src/proto/AudioFadeMessage_pb.ts", "../src/proto/ProtocolMessage_pb.ts", "../src/proto/PlayerPath_pb.ts", "../src/proto/Origin_pb.ts", "../src/proto/DeviceInfoMessage_pb.ts", "../src/proto/Common_pb.ts", "../src/proto/NowPlayingClient_pb.ts", "../src/proto/NowPlayingPlayer_pb.ts", "../src/proto/AudioFadeResponseMessage_pb.ts", "../src/proto/AudioFormatSettingsMessage_pb.ts", "../src/proto/ClientUpdatesConfigMessage_pb.ts", "../src/proto/CommandInfo_pb.ts", "../src/proto/CommandOptions_pb.ts", "../src/proto/ConfigureConnectionMessage_pb.ts", "../src/proto/ContentItem_pb.ts", "../src/proto/ContentItemMetadata_pb.ts", "../src/proto/LanguageOption_pb.ts", "../src/proto/CryptoPairingMessage_pb.ts", "../src/proto/GenericMessage_pb.ts", "../src/proto/GetKeyboardSessionMessage_pb.ts", "../src/proto/GetRemoteTextInputSessionMessage_pb.ts", "../src/proto/GetVolumeMessage_pb.ts", "../src/proto/GetVolumeResultMessage_pb.ts", "../src/proto/KeyboardMessage_pb.ts", "../src/proto/ModifyOutputContextRequestMessage_pb.ts", "../src/proto/NotificationMessage_pb.ts", "../src/proto/NowPlayingInfo_pb.ts", "../src/proto/OriginClientPropertiesMessage_pb.ts", "../src/proto/PlaybackQueue_pb.ts", "../src/proto/PlaybackQueueContext_pb.ts", "../src/proto/PlaybackQueueCapabilities_pb.ts", "../src/proto/PlaybackQueueRequestMessage_pb.ts", "../src/proto/PlayerClientPropertiesMessage_pb.ts", "../src/proto/RegisterForGameControllerEventsMessage_pb.ts", "../src/proto/RegisterHIDDeviceMessage_pb.ts", "../src/proto/VirtualTouchDeviceDescriptorMessage_pb.ts", "../src/proto/RegisterHIDDeviceResultMessage_pb.ts", "../src/proto/RegisterVoiceInputDeviceMessage_pb.ts", "../src/proto/VoiceInputDeviceDescriptorMessage_pb.ts", "../src/proto/RegisterVoiceInputDeviceResponseMessage_pb.ts", "../src/proto/RemoteTextInputMessage_pb.ts", "../src/proto/RemoveClientMessage_pb.ts", "../src/proto/RemoveEndpointsMessage_pb.ts", "../src/proto/RemoveOutputDevicesMessage_pb.ts", "../src/proto/RemovePlayerMessage_pb.ts", "../src/proto/SendButtonEventMessage_pb.ts", "../src/proto/SendCommandMessage_pb.ts", "../src/proto/SendCommandResultMessage_pb.ts", "../src/proto/SendHIDEventMessage_pb.ts", "../src/proto/SendPackedVirtualTouchEventMessage_pb.ts", "../src/proto/SendVoiceInputMessage_pb.ts", "../src/proto/SetArtworkMessage_pb.ts", "../src/proto/SetConnectionStateMessage_pb.ts", "../src/proto/SetDefaultSupportedCommandsMessage_pb.ts", "../src/proto/SupportedCommands_pb.ts", "../src/proto/SetDiscoveryModeMessage_pb.ts", "../src/proto/SetHiliteModeMessage_pb.ts", "../src/proto/SetNowPlayingClientMessage_pb.ts", "../src/proto/SetNowPlayingPlayerMessage_pb.ts", "../src/proto/SetRecordingStateMessage_pb.ts", "../src/proto/SetStateMessage_pb.ts", "../src/proto/SetVolumeMessage_pb.ts", "../src/proto/TextInputMessage_pb.ts", "../src/proto/TransactionKey_pb.ts", "../src/proto/TransactionMessage_pb.ts", "../src/proto/TransactionPackets_pb.ts", "../src/proto/TransactionPacket_pb.ts", "../src/proto/UpdateClientMessage_pb.ts", "../src/proto/UpdateContentItemArtworkMessage_pb.ts", "../src/proto/UpdateContentItemMessage_pb.ts", "../src/proto/UpdateEndPointsMessage_pb.ts", "../src/proto/UpdateOutputDeviceMessage_pb.ts", "../src/proto/UpdatePlayerPath_pb.ts", "../src/proto/VolumeControlAvailabilityMessage_pb.ts", "../src/proto/VolumeControlCapabilitiesDidChangeMessage_pb.ts", "../src/proto/VolumeDidChangeMessage_pb.ts", "../src/proto/WakeDeviceMessage_pb.ts", "../src/protocol/dataStreamMessages.ts", "../src/protocol/stream.ts", "../src/protocol/eventStream.ts", "../src/protocol/pairing.ts", "../src/protocol/rtsp.ts", "../src/protocol/verify.ts"],
4
4
  "sourcesContent": [
5
- "import { Discovery, enableDebug, prompt } from '@basmilius/apple-common';\nimport { AirPlay } from '@/protocol';\n\nenableDebug();\n\nasync function homepod(): Promise<void> {\n const discovery = Discovery.airplay();\n const discoveryResult = await discovery.findUntil('Slaapkamer HomePod._airplay._tcp.local');\n const protocol = new AirPlay(discoveryResult);\n\n await protocol.connect();\n\n await protocol.pairing.start();\n const keys = await protocol.pairing.transient();\n\n await protocol.rtsp.enableEncryption(\n keys.accessoryToControllerKey,\n keys.controllerToAccessoryKey\n );\n\n await protocol.setupEventStream(keys.pairingId, keys.sharedSecret);\n await protocol.setupDataStream(keys.sharedSecret);\n\n setInterval(() => protocol.feedback(), 2000);\n\n // await protocol.dataStream.exchange(protocol.dataStream.messages.configureConnection(``));\n await protocol.dataStream.exchange(protocol.dataStream.messages.deviceInfo(keys.pairingId));\n\n protocol.dataStream.addListener('deviceInfo', async () => {\n await protocol.dataStream.exchange(protocol.dataStream.messages.setConnectionState());\n await protocol.dataStream.exchange(protocol.dataStream.messages.clientUpdatesConfig());\n\n // await protocol.dataStream.exchange(protocol.dataStream.messages.sendCommand(Proto.Command.Play));\n\n // await protocol.dataStream.exchange(protocol.dataStream.messages.notification([\n // 'Hallo wereld!'\n // ]));\n });\n}\n\nasync function tv(): Promise<void> {\n const discovery = Discovery.airplay();\n const device = await discovery.findUntil('Woonkamer TV._airplay._tcp.local');\n const protocol = new AirPlay(device);\n\n await protocol.connect();\n\n const keys = await protocol.verify.start({\n accessoryIdentifier: '7EEEA518-06CC-486C-A8B8-4A07CDBE6267',\n accessoryLongTermPublicKey: Buffer.from('cfb3fb0e0eb494d9058d5051c94400b35251e3faad66542b9551a1496570628d', 'hex'),\n pairingId: Buffer.from('38393044453445352d463738442d344131332d393231392d434231433237304438323341', 'hex'),\n publicKey: Buffer.from('a3dfd6e3956006afd91204d68ddf9c26c7d9d77eee5506c69e7fe3af1288d0f4', 'hex'),\n secretKey: Buffer.from('6961e16b52f5f0be1b7723c9436356d498b4f9629f0227706a1465c5d18dbf0ba3dfd6e3956006afd91204d68ddf9c26c7d9d77eee5506c69e7fe3af1288d0f4', 'hex')\n });\n\n await protocol.rtsp.enableEncryption(\n keys.accessoryToControllerKey,\n keys.controllerToAccessoryKey\n );\n\n await protocol.setupEventStream(keys.pairingId, keys.sharedSecret);\n await protocol.setupDataStream(keys.sharedSecret);\n\n setInterval(() => protocol.feedback(), 2000);\n\n await protocol.dataStream.exchange(protocol.dataStream.messages.deviceInfo(keys.pairingId));\n\n protocol.dataStream.addListener('deviceInfo', async () => {\n await protocol.dataStream.exchange(protocol.dataStream.messages.setConnectionState());\n await protocol.dataStream.exchange(protocol.dataStream.messages.clientUpdatesConfig());\n // await protocol.dataStream.exchange(protocol.dataStream.messages.sendCommand(Proto.Command.Rewind15Seconds));\n\n // await waitFor(1000);\n\n // const options = create(Proto.CommandOptionsSchema, {\n // stationURL: 'https://bmcdn.nl/doorbell.ogg'\n // });\n\n // await protocol.dataStream.exchange(protocol.dataStream.messages.sendCommand(Proto.Command.Play, options));\n\n // await protocol.dataStream.exchange(protocol.dataStream.messages.sendButtonEvent(12, 0x40, true));\n // await protocol.dataStream.exchange(protocol.dataStream.messages.sendButtonEvent(12, 0x40, false));\n });\n\n /*\n \"up\": (1, 0x8C),\n \"down\": (1, 0x8D),\n \"left\": (1, 0x8B),\n \"right\": (1, 0x8A),\n \"stop\": (12, 0xB7),\n \"next\": (12, 0xB5),\n \"previous\": (12, 0xB6),\n \"select\": (1, 0x89),\n \"menu\": (1, 0x86),\n \"topmenu\": (12, 0x60),\n \"home\": (12, 0x40),\n \"suspend\": (1, 0x82),\n \"wakeup\": (1, 0x83),\n \"volume_up\": (12, 0xE9),\n \"volume_down\": (12, 0xEA),\n 'mic': (12, 0x04),\n */\n}\n\nasync function tvPair(): Promise<void> {\n const discovery = Discovery.airplay();\n const device = await discovery.findUntil('Woonkamer TV._airplay._tcp.local');\n const protocol = new AirPlay(device);\n\n await protocol.connect();\n await protocol.pairing.start();\n\n const credentials = await protocol.pairing.pin(async () => await prompt('Enter PIN'));\n\n console.log({\n accessoryIdentifier: credentials.accessoryIdentifier,\n accessoryLongTermPublicKey: credentials.accessoryLongTermPublicKey.toString('hex'),\n pairingId: credentials.pairingId.toString('hex'),\n publicKey: credentials.publicKey.toString('hex'),\n secretKey: credentials.secretKey.toString('hex')\n });\n}\n\nconst what = process.argv[2] ?? null;\n\nswitch (what) {\n case 'homepod':\n await homepod();\n break;\n\n case 'tv':\n await tv();\n break;\n\n case 'tvPair':\n await tvPair();\n break;\n\n default:\n console.error(`Unknown test ${what}, please use specify either homepod, tv or tvPair.`);\n break;\n}\n",
5
+ "import { Discovery, enableDebug, prompt } from '@basmilius/apple-common';\nimport { AirPlay } from './protocol';\n\nenableDebug();\n\nasync function homepod(): Promise<void> {\n const discovery = Discovery.airplay();\n const discoveryResult = await discovery.findUntil('Slaapkamer HomePod._airplay._tcp.local');\n const protocol = new AirPlay(discoveryResult);\n\n await protocol.connect();\n\n await protocol.pairing.start();\n const keys = await protocol.pairing.transient();\n\n await protocol.rtsp.enableEncryption(\n keys.accessoryToControllerKey,\n keys.controllerToAccessoryKey\n );\n\n await protocol.setupEventStream(keys.pairingId, keys.sharedSecret);\n await protocol.setupDataStream(keys.sharedSecret);\n\n setInterval(() => protocol.feedback(), 2000);\n\n // await protocol.dataStream.exchange(protocol.dataStream.messages.configureConnection(``));\n await protocol.dataStream.exchange(protocol.dataStream.messages.deviceInfo(keys.pairingId));\n\n protocol.dataStream.addListener('deviceInfo', async () => {\n await protocol.dataStream.exchange(protocol.dataStream.messages.setConnectionState());\n await protocol.dataStream.exchange(protocol.dataStream.messages.clientUpdatesConfig());\n\n // await protocol.dataStream.exchange(protocol.dataStream.messages.sendCommand(Proto.Command.Play));\n\n // await protocol.dataStream.exchange(protocol.dataStream.messages.notification([\n // 'Hallo wereld!'\n // ]));\n });\n}\n\nasync function tv(): Promise<void> {\n const discovery = Discovery.airplay();\n const device = await discovery.findUntil('Woonkamer TV._airplay._tcp.local');\n const protocol = new AirPlay(device);\n\n await protocol.connect();\n\n const keys = await protocol.verify.start({\n accessoryIdentifier: '7EEEA518-06CC-486C-A8B8-4A07CDBE6267',\n accessoryLongTermPublicKey: Buffer.from('cfb3fb0e0eb494d9058d5051c94400b35251e3faad66542b9551a1496570628d', 'hex'),\n pairingId: Buffer.from('38393044453445352d463738442d344131332d393231392d434231433237304438323341', 'hex'),\n publicKey: Buffer.from('a3dfd6e3956006afd91204d68ddf9c26c7d9d77eee5506c69e7fe3af1288d0f4', 'hex'),\n secretKey: Buffer.from('6961e16b52f5f0be1b7723c9436356d498b4f9629f0227706a1465c5d18dbf0ba3dfd6e3956006afd91204d68ddf9c26c7d9d77eee5506c69e7fe3af1288d0f4', 'hex')\n });\n\n await protocol.rtsp.enableEncryption(\n keys.accessoryToControllerKey,\n keys.controllerToAccessoryKey\n );\n\n await protocol.setupEventStream(keys.pairingId, keys.sharedSecret);\n await protocol.setupDataStream(keys.sharedSecret);\n\n setInterval(() => protocol.feedback(), 2000);\n\n await protocol.dataStream.exchange(protocol.dataStream.messages.deviceInfo(keys.pairingId));\n\n protocol.dataStream.addListener('deviceInfo', async () => {\n await protocol.dataStream.exchange(protocol.dataStream.messages.setConnectionState());\n await protocol.dataStream.exchange(protocol.dataStream.messages.clientUpdatesConfig());\n // await protocol.dataStream.exchange(protocol.dataStream.messages.sendCommand(Proto.Command.Rewind15Seconds));\n\n // await waitFor(1000);\n\n // const options = create(Proto.CommandOptionsSchema, {\n // stationURL: 'https://bmcdn.nl/doorbell.ogg'\n // });\n\n // await protocol.dataStream.exchange(protocol.dataStream.messages.sendCommand(Proto.Command.Play, options));\n\n // await protocol.dataStream.exchange(protocol.dataStream.messages.sendButtonEvent(12, 0x40, true));\n // await protocol.dataStream.exchange(protocol.dataStream.messages.sendButtonEvent(12, 0x40, false));\n });\n\n /*\n \"up\": (1, 0x8C),\n \"down\": (1, 0x8D),\n \"left\": (1, 0x8B),\n \"right\": (1, 0x8A),\n \"stop\": (12, 0xB7),\n \"next\": (12, 0xB5),\n \"previous\": (12, 0xB6),\n \"select\": (1, 0x89),\n \"menu\": (1, 0x86),\n \"topmenu\": (12, 0x60),\n \"home\": (12, 0x40),\n \"suspend\": (1, 0x82),\n \"wakeup\": (1, 0x83),\n \"volume_up\": (12, 0xE9),\n \"volume_down\": (12, 0xEA),\n 'mic': (12, 0x04),\n */\n}\n\nasync function tvPair(): Promise<void> {\n const discovery = Discovery.airplay();\n const device = await discovery.findUntil('Woonkamer TV._airplay._tcp.local');\n const protocol = new AirPlay(device);\n\n await protocol.connect();\n await protocol.pairing.start();\n\n const credentials = await protocol.pairing.pin(async () => await prompt('Enter PIN'));\n\n console.log({\n accessoryIdentifier: credentials.accessoryIdentifier,\n accessoryLongTermPublicKey: credentials.accessoryLongTermPublicKey.toString('hex'),\n pairingId: credentials.pairingId.toString('hex'),\n publicKey: credentials.publicKey.toString('hex'),\n secretKey: credentials.secretKey.toString('hex')\n });\n}\n\nconst what = process.argv[2] ?? null;\n\nswitch (what) {\n case 'homepod':\n await homepod();\n break;\n\n case 'tv':\n await tv();\n break;\n\n case 'tvPair':\n await tvPair();\n break;\n\n default:\n console.error(`Unknown test ${what}, please use specify either homepod, tv or tvPair.`);\n break;\n}\n",
6
6
  "import { debug, type DiscoveryResult, getMacAddress, parseBinaryPlist, serializeBinaryPlist, uuid } from '@basmilius/apple-common';\nimport { randomInt64 } from './utils';\nimport DataStream from './dataStream';\nimport EventStream from './eventStream';\nimport Pairing from './pairing';\nimport RTSP from './rtsp';\nimport Verify from './verify';\n\nexport default class AirPlay {\n get device(): DiscoveryResult {\n return this.#device;\n }\n\n get dataStream(): DataStream | undefined {\n return this.#dataStream;\n }\n\n get eventStream(): EventStream | undefined {\n return this.#eventStream;\n }\n\n get pairing(): Pairing {\n return this.#pairing;\n }\n\n get rtsp(): RTSP {\n return this.#rtsp;\n }\n\n get verify(): Verify {\n return this.#verify;\n }\n\n readonly #device: DiscoveryResult;\n readonly #pairing: Pairing;\n readonly #rtsp: RTSP;\n readonly #verify: Verify;\n readonly #sessionUUID: string;\n #dataStream?: DataStream;\n #eventStream?: EventStream;\n\n constructor(device: DiscoveryResult) {\n this.#device = device;\n this.#rtsp = new RTSP(device.address, device.service.port);\n this.#pairing = new Pairing(this);\n this.#verify = new Verify(this);\n this.#sessionUUID = uuid();\n }\n\n async connect(): Promise<void> {\n await this.#rtsp.connect();\n }\n\n async disconnect(): Promise<void> {\n await this.#rtsp.disconnect();\n }\n\n async feedback(): Promise<void> {\n await this.#rtsp.post('/feedback');\n }\n\n async setupDataStream(sharedSecret: Buffer): Promise<void> {\n const seed = randomInt64();\n const request = serializeBinaryPlist({\n streams: [\n {\n controlType: 2,\n channelID: uuid().toUpperCase(),\n seed,\n clientUUID: uuid().toUpperCase(),\n type: 130,\n wantsDedicatedSocket: true,\n clientTypeUUID: '1910A70F-DBC0-4242-AF95-115DB30604E1'\n }\n ]\n });\n\n const response = await this.#rtsp.setup(`/${this.rtsp.sessionId}`, Buffer.from(request), {\n 'Content-Type': 'application/x-apple-binary-plist'\n });\n\n const plist = parseBinaryPlist(await response.arrayBuffer()) as any;\n const dataPort = plist.streams[0].dataPort & 0xFFFF;\n debug('Should listen on data port', dataPort);\n\n this.#dataStream = new DataStream(this.#rtsp.address, dataPort);\n await this.#dataStream.setup(sharedSecret, seed);\n await this.#dataStream.connect();\n }\n\n async setupEventStream(pairingId: Buffer, sharedSecret: Buffer): Promise<void> {\n const request = serializeBinaryPlist({\n deviceID: pairingId.toString(),\n macAddress: getMacAddress().toUpperCase(),\n name: 'iPhone van Bas',\n model: 'iPhone16,2',\n osBuildVersion: '23C5027f',\n osName: 'iPhone OS',\n osVersion: '26.2',\n sourceVersion: '925.3.2',\n sessionUUID: this.#sessionUUID,\n sessionCorrelationUUID: 'BBB3A645-7453-46B2-92CF-30A8E1F02D26',\n timingProtocol: 'None',\n isRemoteControlOnly: true,\n statsCollectionEnabled: false,\n updateSessionRequest: false\n });\n\n const response = await this.#rtsp.setup(`/${this.rtsp.sessionId}`, Buffer.from(request), {\n 'Content-Type': 'application/x-apple-binary-plist'\n });\n\n const plist = parseBinaryPlist(await response.arrayBuffer()) as any;\n const eventPort = plist.eventPort & 0xFFFF;\n debug('Should listen on event port', eventPort);\n\n this.#eventStream = new EventStream(this.#rtsp.address, eventPort);\n await this.#eventStream.setup(sharedSecret);\n await this.#eventStream.connect();\n\n await this.#rtsp.record(`/${this.rtsp.sessionId}`);\n }\n}\n",
7
7
  "import { randomBytes } from 'node:crypto';\nimport { debug } from '@basmilius/apple-common';\nimport type { RTSPMethod } from './types';\n\nexport function makeHttpHeader(method: RTSPMethod, path: string, headers: HeadersInit, cseq: number): string {\n const lines = [];\n lines.push(`${method} ${path} RTSP/1.0`);\n lines.push(`CSeq: ${cseq}`);\n lines.push('User-Agent: AirPlay/320.20');\n lines.push('X-ProtocolVersion: 1');\n\n for (const [name, value] of Object.entries(headers)) {\n lines.push(`${name}: ${value}`);\n }\n\n lines.push('');\n lines.push('');\n\n return lines.join('\\r\\n');\n}\n\nexport function makeHttpRequest(buffer: Buffer): HttpRequest | null {\n const headerLength = buffer.indexOf('\\r\\n\\r\\n');\n const {headers, method, path} = parseRequestHeaders(buffer.subarray(0, headerLength));\n\n let contentLength = headers['Content-Length'] ? Number(headers['Content-Length']) : 0;\n\n if (isNaN(contentLength)) {\n contentLength = 0;\n }\n\n const requestLength = headerLength + 4 + contentLength;\n\n debug(buffer.byteLength, requestLength);\n\n if (buffer.byteLength < requestLength) {\n return null;\n }\n\n const body = buffer.subarray(headerLength + 4, requestLength);\n\n return {\n headers,\n method,\n path,\n body,\n requestLength\n };\n}\n\nexport function makeHttpResponse(buffer: Buffer): HttpResponse | null {\n const headerLength = buffer.indexOf('\\r\\n\\r\\n');\n const {headers, status, statusText} = parseResponseHeaders(buffer.subarray(0, headerLength));\n\n let contentLength = headers['Content-Length'] ? Number(headers['Content-Length']) : 0;\n\n if (isNaN(contentLength)) {\n contentLength = 0;\n }\n\n const responseLength = headerLength + 4 + contentLength;\n\n // not enough data yet\n if (buffer.byteLength < responseLength) {\n return null;\n }\n\n const body = buffer.subarray(headerLength + 4, responseLength);\n const response = new Response(body, {\n status,\n statusText,\n headers\n });\n\n return {\n response,\n responseLength\n };\n}\n\nexport function randomInt32(): number {\n return randomBytes(4).readUInt32BE(0);\n}\n\nexport function randomInt64(): bigint {\n return randomBytes(8).readBigUint64LE(0);\n}\n\nfunction parseHeaders(lines: string[]): Record<string, string> {\n const headers: Record<string, string> = {};\n\n for (let i = 0; i < lines.length; i++) {\n const colon = lines[i].indexOf(':');\n\n if (colon <= 0) {\n continue;\n }\n\n const name = lines[i].substring(0, colon).trim();\n headers[name] = lines[i].substring(colon + 1).trim();\n }\n\n return headers;\n}\n\nfunction parseRequestHeaders(buffer: Buffer): HttpRequestHeader {\n const lines = buffer.toString('utf8').split('\\r\\n');\n\n const rawRequest = lines[0].match(/^(\\S+)\\s+(\\S+)\\s+RTSP\\/1\\.0$/);\n const method = rawRequest[1] as RTSPMethod;\n const path = rawRequest[2];\n const headers: Record<string, string> = parseHeaders(lines.slice(1));\n\n return {\n headers,\n method,\n path\n };\n}\n\nfunction parseResponseHeaders(buffer: Buffer): HttpResponseHeader {\n const lines = buffer.toString('utf8').split('\\r\\n');\n\n const rawStatus = lines[0].match(/(HTTP|RTSP)\\/[\\d.]+\\s+(\\d+)\\s+(.+)/);\n const status = Number(rawStatus[2]);\n const statusText = rawStatus[3];\n const headers: Record<string, string> = parseHeaders(lines.slice(1));\n\n return {\n headers,\n status,\n statusText\n };\n}\n\ntype HttpRequestHeader = {\n readonly headers: Record<string, string>;\n readonly method: RTSPMethod;\n readonly path: string;\n};\n\ntype HttpResponseHeader = {\n readonly headers: Record<string, string>;\n readonly status: number;\n readonly statusText: string;\n};\n\ntype HttpRequest = {\n readonly headers: Record<string, string>;\n readonly method: RTSPMethod;\n readonly path: string;\n readonly body: Buffer;\n readonly requestLength: number;\n};\n\ntype HttpResponse = {\n readonly response: Response;\n readonly responseLength: number;\n};\n",
8
8
  "import { debug, decryptChacha20, encryptChacha20, hkdf, parseBinaryPlist, serializeBinaryPlist } from '@basmilius/apple-common';\nimport { fromBinary, getExtension, toBinary } from '@bufbuild/protobuf';\nimport * as Proto from '../proto';\nimport { randomInt32 } from './utils';\nimport AirPlayDataStreamMessages from './dataStreamMessages';\nimport AirPlayStream from './stream';\n\nconst DATA_HEADER_LENGTH = 32; // 4 + 12 + 4 + 8 + 4\n\ntype EventMap = {\n readonly deviceInfo: [Proto.DeviceInfoMessage];\n readonly originClientProperties: [Proto.OriginClientPropertiesMessage];\n readonly playerClientProperties: [Proto.PlayerClientPropertiesMessage];\n readonly sendCommandResult: [Proto.SendCommandResultMessage];\n readonly setArtwork: [Proto.SetArtworkMessage];\n readonly setDefaultSupportedCommands: [Proto.SetDefaultSupportedCommandsMessage];\n readonly setNowPlayingClient: [Proto.SetNowPlayingClientMessage];\n readonly setNowPlayingPlayer: [Proto.SetNowPlayingPlayerMessage];\n readonly setState: [Proto.SetStateMessage];\n readonly updateClient: [Proto.UpdateClientMessage];\n readonly updateContentItem: [Proto.UpdateContentItemMessage];\n readonly updateContentItemArtwork: [Proto.UpdateContentItemArtworkMessage];\n readonly updatePlayer: [Proto.UpdatePlayerMessage];\n readonly updateOutputDevice: [Proto.UpdateOutputDeviceMessage];\n readonly volumeControlAvailability: [Proto.VolumeControlAvailabilityMessage];\n readonly volumeControlCapabilitiesDidChange: [Proto.VolumeControlCapabilitiesDidChangeMessage];\n readonly volumeDidChange: [Proto.VolumeDidChangeMessage];\n};\n\nexport default class AirPlayDataStream extends AirPlayStream<EventMap> {\n get messages(): AirPlayDataStreamMessages {\n return this.#messages;\n }\n\n readonly #messages: AirPlayDataStreamMessages;\n #buffer: Buffer = Buffer.alloc(0);\n #seqno: bigint;\n #readCount: number;\n #writeCount: number;\n #handler?: [Function, Function];\n\n constructor(address: string, port: number) {\n super(address, port);\n\n this.#messages = new AirPlayDataStreamMessages();\n this.#seqno = 0x100000000n + BigInt(randomInt32());\n this.#writeCount = 0;\n }\n\n async exchange(message: Proto.ProtocolMessage): Promise<Proto.ProtocolMessage> {\n return new Promise(async (resolve, reject) => {\n this.#handler = [resolve, reject];\n await this.send(message);\n });\n }\n\n async reply(seqno: bigint): Promise<void> {\n const rply = buildReply(seqno);\n\n debug('Sending reply.');\n this.socket.write(await this.#encrypt(rply));\n }\n\n async send(message: Proto.ProtocolMessage): Promise<void> {\n const bytes = toBinary(Proto.ProtocolMessageSchema, message, {writeUnknownFields: true});\n const lenPrefix = Buffer.from(encodeVarint(bytes.length));\n const pbPayload = Buffer.concat([lenPrefix, Buffer.from(bytes)]);\n\n const plistPayload = Buffer.from(\n serializeBinaryPlist({\n params: {\n data: pbPayload.buffer.slice(pbPayload.byteOffset, pbPayload.byteOffset + pbPayload.byteLength)\n }\n } as any)\n );\n\n const header = buildHeader(DATA_HEADER_LENGTH + plistPayload.byteLength, this.#seqno++);\n const frame = Buffer.concat([header, plistPayload]);\n const encrypted = await this.#encrypt(frame);\n\n debug('Sending data stream message', message);\n\n this.socket.write(encrypted);\n }\n\n async setup(sharedSecret: Buffer, seed: bigint): Promise<void> {\n const readKey = hkdf({\n hash: 'sha512',\n key: sharedSecret,\n length: 32,\n salt: Buffer.from(`DataStream-Salt${seed}`),\n info: Buffer.from('DataStream-Input-Encryption-Key')\n });\n\n const writeKey = hkdf({\n hash: 'sha512',\n key: sharedSecret,\n length: 32,\n salt: Buffer.from(`DataStream-Salt${seed}`),\n info: Buffer.from('DataStream-Output-Encryption-Key')\n });\n\n await this.enableEncryption(readKey, writeKey);\n }\n\n async onData(buffer: Buffer): Promise<void> {\n try {\n this.#buffer = Buffer.concat([this.#buffer, buffer]);\n this.#buffer = await this.#decrypt(this.#buffer);\n\n while (this.#buffer.byteLength > DATA_HEADER_LENGTH) {\n const header = this.#buffer.subarray(0, DATA_HEADER_LENGTH);\n const totalLength = header.readUint32BE();\n\n if (this.#buffer.byteLength < totalLength) {\n debug(`Not enough data yet, waiting on the next frame.. needed=${totalLength} available=${this.#buffer.byteLength} receivedLength=${buffer.byteLength}`);\n return;\n }\n\n const frame = this.#buffer.subarray(DATA_HEADER_LENGTH, totalLength);\n const plist = parseBinaryPlist(frame.buffer.slice(frame.byteOffset, frame.byteOffset + frame.byteLength) as any) as any;\n const command = header.toString('ascii', 4, 8);\n\n debug('Raw data received', header.toString());\n debug(`Should read ${totalLength} bytes, ${this.#buffer.byteLength} available.`);\n\n this.#buffer = this.#buffer.subarray(totalLength);\n\n if (!plist || !plist.params || !plist.params.data) {\n if (command === 'rply') {\n debug('Got reply...');\n }\n\n if (command === 'sync') {\n await this.reply(parseHeaderSeqno(header));\n }\n\n if (this.#handler) {\n const [resolve] = this.#handler;\n this.#handler = undefined;\n\n resolve();\n }\n\n continue;\n }\n\n const content = Buffer.from(plist.params.data);\n\n for (const message of await parseMessages(content)) {\n await this.#handleMessage(message);\n }\n\n if (command === 'sync') {\n await this.reply(parseHeaderSeqno(header));\n }\n }\n } catch (err) {\n debug('Error in onData', err);\n }\n }\n\n async #onDeviceInfoMessage(message: Proto.DeviceInfoMessage): Promise<void> {\n debug('Connected to device', message.name);\n\n this.emit('deviceInfo', message);\n }\n\n async #onOriginClientPropertiesMessage(message: Proto.OriginClientPropertiesMessage): Promise<void> {\n debug('Origin client properties', message);\n\n this.emit('originClientProperties', message);\n }\n\n async #onPlayerClientPropertiesMessage(message: Proto.PlayerClientPropertiesMessage): Promise<void> {\n debug('Player client properties', message);\n\n this.emit('playerClientProperties', message);\n }\n\n async #onSendCommandResultMessage(message: Proto.SendCommandResultMessage): Promise<void> {\n debug('Send command result', message);\n\n this.emit('sendCommandResult', message);\n }\n\n async #onSetArtworkMessage(message: Proto.SetArtworkMessage): Promise<void> {\n debug('Set artwork', message);\n\n this.emit('setArtwork', message);\n }\n\n async #onSetDefaultSupportedCommandsMessage(message: Proto.SetDefaultSupportedCommandsMessage): Promise<void> {\n debug('Set default supported commands', message);\n\n this.emit('setDefaultSupportedCommands', message);\n }\n\n async #onSetNowPlayingClientMessage(message: Proto.SetNowPlayingClientMessage): Promise<void> {\n debug('Set now playing client', message);\n\n this.emit('setNowPlayingClient', message);\n }\n\n async #onSetNowPlayingPlayerMessage(message: Proto.SetNowPlayingPlayerMessage): Promise<void> {\n debug('Set now playing player', message);\n\n this.emit('setNowPlayingPlayer', message);\n }\n\n async #onSetStateMessage(message: Proto.SetStateMessage): Promise<void> {\n debug('Set state', message);\n\n this.emit('setState', message);\n }\n\n async #onUpdateClientMessage(message: Proto.UpdateClientMessage): Promise<void> {\n debug('Update client', message);\n\n this.emit('updateClient', message);\n }\n\n async #onUpdateContentItemMessage(message: Proto.UpdateContentItemMessage): Promise<void> {\n debug('Update content item', message);\n\n this.emit('updateContentItem', message);\n }\n\n async #onUpdateContentItemArtworkMessage(message: Proto.UpdateContentItemArtworkMessage): Promise<void> {\n debug('Update content artwork', message);\n\n this.emit('updateContentItemArtwork', message);\n }\n\n async #onUpdatePlayerMessage(message: Proto.UpdatePlayerMessage): Promise<void> {\n debug('Update player', message);\n\n this.emit('updatePlayer', message);\n }\n\n async #onUpdateOutputDeviceMessage(message: Proto.UpdateOutputDeviceMessage): Promise<void> {\n debug('Update output device', message);\n\n this.emit('updateOutputDevice', message);\n }\n\n async #onVolumeControlAvailabilityMessage(message: Proto.VolumeControlAvailabilityMessage): Promise<void> {\n debug('Volume control availability', message);\n\n this.emit('volumeControlAvailability', message);\n }\n\n async #onVolumeControlCapabilitiesDidChangeMessage(message: Proto.VolumeControlCapabilitiesDidChangeMessage): Promise<void> {\n debug('Volume control capabilities did change', message);\n\n this.emit('volumeControlCapabilitiesDidChange', message);\n }\n\n async #onVolumeDidChangeMessage(message: Proto.VolumeDidChangeMessage): Promise<void> {\n debug('VolumeDidChange message', message);\n\n this.emit('volumeDidChange', message);\n }\n\n async #decrypt(data: Buffer): Promise<Buffer> {\n const result: Buffer[] = [];\n let offset = 0;\n let readCount = this.#readCount ?? 0;\n\n while (offset < data.length) {\n if (offset + 2 > data.length) {\n console.error('Truncated frame length');\n return this.#buffer;\n }\n\n const frameLength = data.readUInt16LE(offset);\n offset += 2;\n\n const nonce = Buffer.alloc(12);\n nonce.writeBigUInt64LE(BigInt(readCount++), 4);\n\n const end = offset + frameLength + 16;\n\n if (end > data.length) {\n console.error(`Truncated frame end=${end} length=${data.length}`);\n return this.#buffer;\n }\n\n const ciphertext = data.subarray(offset, offset + frameLength);\n const authTag = data.subarray(offset + frameLength, end);\n offset = end;\n\n const plaintext = decryptChacha20(\n this.readKey,\n nonce,\n Buffer.from(Uint16Array.of(frameLength).buffer.slice(0, 2)), // same AAD = leLength\n ciphertext,\n authTag\n );\n\n result.push(plaintext);\n }\n\n this.#readCount = readCount;\n\n return Buffer.concat(result);\n }\n\n async #encrypt(data: Buffer): Promise<Buffer> {\n const FRAME_LENGTH = 1024;\n const result: Buffer[] = [];\n\n for (let offset = 0; offset < data.length;) {\n const frame = data.subarray(offset, offset + FRAME_LENGTH);\n offset += frame.length;\n\n const leLength = Buffer.alloc(2);\n leLength.writeUInt16LE(frame.length, 0);\n\n const nonce = Buffer.alloc(12);\n nonce.writeBigUInt64LE(BigInt(this.#writeCount++), 4);\n\n const encrypted = encryptChacha20(\n this.writeKey,\n nonce,\n leLength,\n frame\n );\n\n result.push(leLength, encrypted.ciphertext, encrypted.authTag);\n }\n\n return Buffer.concat(result);\n }\n\n async #handleMessage(message: Proto.ProtocolMessage): Promise<void> {\n if (this.#handler) {\n const [resolve] = this.#handler;\n this.#handler = undefined;\n\n resolve(message);\n }\n\n switch (message.type) {\n case Proto.ProtocolMessage_Type.DEVICE_INFO_MESSAGE:\n await this.#onDeviceInfoMessage(getExtension(message, Proto.deviceInfoMessage));\n break;\n\n case Proto.ProtocolMessage_Type.ORIGIN_CLIENT_PROPERTIES_MESSAGE:\n await this.#onOriginClientPropertiesMessage(getExtension(message, Proto.originClientPropertiesMessage));\n break;\n\n case Proto.ProtocolMessage_Type.PLAYER_CLIENT_PROPERTIES_MESSAGE:\n await this.#onPlayerClientPropertiesMessage(getExtension(message, Proto.playerClientPropertiesMessage));\n break;\n\n case Proto.ProtocolMessage_Type.SEND_COMMAND_RESULT_MESSAGE:\n await this.#onSendCommandResultMessage(getExtension(message, Proto.sendCommandResultMessage));\n break;\n\n case Proto.ProtocolMessage_Type.SET_ARTWORK_MESSAGE:\n await this.#onSetArtworkMessage(getExtension(message, Proto.setArtworkMessage));\n break;\n\n case Proto.ProtocolMessage_Type.SET_DEFAULT_SUPPORTED_COMMANDS_MESSAGE:\n await this.#onSetDefaultSupportedCommandsMessage(getExtension(message, Proto.setDefaultSupportedCommandsMessage));\n break;\n\n case Proto.ProtocolMessage_Type.SET_NOW_PLAYING_CLIENT_MESSAGE:\n await this.#onSetNowPlayingClientMessage(getExtension(message, Proto.setNowPlayingClientMessage));\n break;\n\n case Proto.ProtocolMessage_Type.SET_NOW_PLAYING_PLAYER_MESSAGE:\n await this.#onSetNowPlayingPlayerMessage(getExtension(message, Proto.setNowPlayingPlayerMessage));\n break;\n\n case Proto.ProtocolMessage_Type.SET_STATE_MESSAGE:\n await this.#onSetStateMessage(getExtension(message, Proto.setStateMessage));\n break;\n\n case Proto.ProtocolMessage_Type.UPDATE_CLIENT_MESSAGE:\n await this.#onUpdateClientMessage(getExtension(message, Proto.updateClientMessage));\n break;\n\n case Proto.ProtocolMessage_Type.UPDATE_CONTENT_ITEM_MESSAGE:\n await this.#onUpdateContentItemMessage(getExtension(message, Proto.updateContentItemMessage));\n break;\n\n case Proto.ProtocolMessage_Type.UPDATE_CONTENT_ITEM_ARTWORK_MESSAGE:\n await this.#onUpdateContentItemArtworkMessage(getExtension(message, Proto.updateContentItemArtworkMessage));\n break;\n\n case Proto.ProtocolMessage_Type.UPDATE_PLAYER_MESSAGE:\n await this.#onUpdatePlayerMessage(getExtension(message, Proto.updatePlayerMessage));\n break;\n\n case Proto.ProtocolMessage_Type.UPDATE_OUTPUT_DEVICE_MESSAGE:\n await this.#onUpdateOutputDeviceMessage(getExtension(message, Proto.updateOutputDeviceMessage));\n break;\n\n case Proto.ProtocolMessage_Type.VOLUME_CONTROL_AVAILABILITY_MESSAGE:\n await this.#onVolumeControlAvailabilityMessage(getExtension(message, Proto.volumeControlAvailabilityMessage));\n break;\n\n case Proto.ProtocolMessage_Type.VOLUME_CONTROL_CAPABILITIES_DID_CHANGE_MESSAGE:\n await this.#onVolumeControlCapabilitiesDidChangeMessage(getExtension(message, Proto.volumeControlCapabilitiesDidChangeMessage));\n break;\n\n case Proto.ProtocolMessage_Type.VOLUME_DID_CHANGE_MESSAGE:\n await this.#onVolumeDidChangeMessage(getExtension(message, Proto.volumeDidChangeMessage));\n break;\n\n case Proto.ProtocolMessage_Type.UNKNOWN_MESSAGE:\n break;\n\n default:\n debug('Received unknown message.', message);\n break;\n }\n }\n}\n\nfunction buildHeader(totalSize: number, seqno: bigint): Buffer {\n const buf = Buffer.alloc(32);\n\n buf.writeUInt32BE(totalSize, 0);\n buf.write('sync', 4, 'ascii');\n buf.fill(0, 8, 16);\n buf.write('comm', 16, 'ascii');\n buf.writeBigUInt64BE(seqno, 20);\n buf.writeUInt32BE(0, 28);\n\n return buf;\n}\n\nfunction buildReply(seqno: bigint): Buffer {\n const header = Buffer.alloc(32);\n header.writeUInt32BE(0, 0); // placeholder\n header.write('rply', 4, 'ascii');\n header.fill(0, 8, 16);\n header.writeBigUInt64BE(seqno, 20);\n header.writeUInt32BE(0, 28);\n\n const plist = Buffer.from(\n serializeBinaryPlist(Buffer.alloc(0) as any)\n );\n\n const total = header.length + plist.length;\n header.writeUInt32BE(total, 0);\n\n return Buffer.concat([header, plist]);\n}\n\nfunction encodeVarint(value: number): Uint8Array {\n if (value < 0) {\n throw new RangeError('Varint only supports non-negative integers');\n }\n\n const bytes: number[] = [];\n while (value > 127) {\n bytes.push((value & 0x7f) | 0x80);\n value >>>= 7;\n }\n\n bytes.push(value);\n\n return Uint8Array.from(bytes);\n}\n\nfunction parseHeaderSeqno(header: Buffer): bigint {\n if (header.length < 28) {\n throw new Error('Header too short');\n }\n\n return header.readBigUInt64BE(20);\n}\n\nasync function parseMessages(content: Buffer): Promise<Proto.ProtocolMessage[]> {\n const messages: Proto.ProtocolMessage[] = [];\n let offset = 0;\n\n while (offset < content.length) {\n const firstByte = content[offset];\n\n if (firstByte === 0x08) {\n const message = content.subarray(offset);\n const decoded = fromBinary(Proto.ProtocolMessageSchema, message, {readUnknownFields: true});\n messages.push(decoded);\n break;\n }\n\n const [length, variantLen] = readVariant(content, offset);\n offset += variantLen;\n\n if (offset + length > content.length) {\n break;\n }\n\n const message = content.subarray(offset, offset + length);\n offset += length;\n\n const decoded = fromBinary(Proto.ProtocolMessageSchema, message, {readUnknownFields: true});\n messages.push(decoded);\n }\n\n return messages;\n}\n\nfunction readVariant(buf: Buffer, offset = 0): [number, number] {\n let result = 0;\n let shift = 0;\n let bytesRead = 0;\n\n while (true) {\n const byte = buf[offset + bytesRead++];\n result |= (byte & 0x7f) << shift;\n\n if ((byte & 0x80) === 0) {\n break;\n }\n\n shift += 7;\n }\n\n return [result, bytesRead];\n}\n",
@@ -83,7 +83,7 @@
83
83
  "// @generated by protoc-gen-es v2.10.0 with parameter \"target=ts\"\n// @generated from file VolumeControlCapabilitiesDidChangeMessage.proto (syntax proto2)\n/* eslint-disable */\n\nimport type { GenExtension, GenFile, GenMessage } from \"@bufbuild/protobuf/codegenv2\";\nimport { extDesc, fileDesc, messageDesc } from \"@bufbuild/protobuf/codegenv2\";\nimport type { ProtocolMessage } from \"./ProtocolMessage_pb\";\nimport { file_ProtocolMessage } from \"./ProtocolMessage_pb\";\nimport type { VolumeControlAvailabilityMessage } from \"./VolumeControlAvailabilityMessage_pb\";\nimport { file_VolumeControlAvailabilityMessage } from \"./VolumeControlAvailabilityMessage_pb\";\nimport type { Message } from \"@bufbuild/protobuf\";\n\n/**\n * Describes the file VolumeControlCapabilitiesDidChangeMessage.proto.\n */\nexport const file_VolumeControlCapabilitiesDidChangeMessage: GenFile = /*@__PURE__*/\n fileDesc(\"Ci9Wb2x1bWVDb250cm9sQ2FwYWJpbGl0aWVzRGlkQ2hhbmdlTWVzc2FnZS5wcm90byKSAQopVm9sdW1lQ29udHJvbENhcGFiaWxpdGllc0RpZENoYW5nZU1lc3NhZ2USNwoMY2FwYWJpbGl0aWVzGAEgASgLMiEuVm9sdW1lQ29udHJvbEF2YWlsYWJpbGl0eU1lc3NhZ2USEwoLZW5kcG9pbnRVSUQYAyABKAkSFwoPb3V0cHV0RGV2aWNlVUlEGAQgASgJOpoBCil2b2x1bWVDb250cm9sQ2FwYWJpbGl0aWVzRGlkQ2hhbmdlTWVzc2FnZRIQLlByb3RvY29sTWVzc2FnZRhEIAEoCzIqLlZvbHVtZUNvbnRyb2xDYXBhYmlsaXRpZXNEaWRDaGFuZ2VNZXNzYWdlUil2b2x1bWVDb250cm9sQ2FwYWJpbGl0aWVzRGlkQ2hhbmdlTWVzc2FnZQ\", [file_ProtocolMessage, file_VolumeControlAvailabilityMessage]);\n\n/**\n * @generated from message VolumeControlCapabilitiesDidChangeMessage\n */\nexport type VolumeControlCapabilitiesDidChangeMessage = Message<\"VolumeControlCapabilitiesDidChangeMessage\"> & {\n /**\n * @generated from field: optional VolumeControlAvailabilityMessage capabilities = 1;\n */\n capabilities?: VolumeControlAvailabilityMessage;\n\n /**\n * @generated from field: optional string endpointUID = 3;\n */\n endpointUID: string;\n\n /**\n * @generated from field: optional string outputDeviceUID = 4;\n */\n outputDeviceUID: string;\n};\n\n/**\n * Describes the message VolumeControlCapabilitiesDidChangeMessage.\n * Use `create(VolumeControlCapabilitiesDidChangeMessageSchema)` to create a new message.\n */\nexport const VolumeControlCapabilitiesDidChangeMessageSchema: GenMessage<VolumeControlCapabilitiesDidChangeMessage> = /*@__PURE__*/\n messageDesc(file_VolumeControlCapabilitiesDidChangeMessage, 0);\n\n/**\n * @generated from extension: optional VolumeControlCapabilitiesDidChangeMessage volumeControlCapabilitiesDidChangeMessage = 68;\n */\nexport const volumeControlCapabilitiesDidChangeMessage: GenExtension<ProtocolMessage, VolumeControlCapabilitiesDidChangeMessage> = /*@__PURE__*/\n extDesc(file_VolumeControlCapabilitiesDidChangeMessage, 0);\n\n",
84
84
  "// @generated by protoc-gen-es v2.10.0 with parameter \"target=ts\"\n// @generated from file VolumeDidChangeMessage.proto (syntax proto2)\n/* eslint-disable */\n\nimport type { GenExtension, GenFile, GenMessage } from \"@bufbuild/protobuf/codegenv2\";\nimport { extDesc, fileDesc, messageDesc } from \"@bufbuild/protobuf/codegenv2\";\nimport type { ProtocolMessage } from \"./ProtocolMessage_pb\";\nimport { file_ProtocolMessage } from \"./ProtocolMessage_pb\";\nimport type { Message } from \"@bufbuild/protobuf\";\n\n/**\n * Describes the file VolumeDidChangeMessage.proto.\n */\nexport const file_VolumeDidChangeMessage: GenFile = /*@__PURE__*/\n fileDesc(\"ChxWb2x1bWVEaWRDaGFuZ2VNZXNzYWdlLnByb3RvIlYKFlZvbHVtZURpZENoYW5nZU1lc3NhZ2USDgoGdm9sdW1lGAEgASgCEhMKC2VuZHBvaW50VUlEGAIgASgJEhcKD291dHB1dERldmljZVVJRBgDIAEoCTphChZ2b2x1bWVEaWRDaGFuZ2VNZXNzYWdlEhAuUHJvdG9jb2xNZXNzYWdlGDggASgLMhcuVm9sdW1lRGlkQ2hhbmdlTWVzc2FnZVIWdm9sdW1lRGlkQ2hhbmdlTWVzc2FnZQ\", [file_ProtocolMessage]);\n\n/**\n * @generated from message VolumeDidChangeMessage\n */\nexport type VolumeDidChangeMessage = Message<\"VolumeDidChangeMessage\"> & {\n /**\n * @generated from field: optional float volume = 1;\n */\n volume: number;\n\n /**\n * @generated from field: optional string endpointUID = 2;\n */\n endpointUID: string;\n\n /**\n * @generated from field: optional string outputDeviceUID = 3;\n */\n outputDeviceUID: string;\n};\n\n/**\n * Describes the message VolumeDidChangeMessage.\n * Use `create(VolumeDidChangeMessageSchema)` to create a new message.\n */\nexport const VolumeDidChangeMessageSchema: GenMessage<VolumeDidChangeMessage> = /*@__PURE__*/\n messageDesc(file_VolumeDidChangeMessage, 0);\n\n/**\n * @generated from extension: optional VolumeDidChangeMessage volumeDidChangeMessage = 56;\n */\nexport const volumeDidChangeMessage: GenExtension<ProtocolMessage, VolumeDidChangeMessage> = /*@__PURE__*/\n extDesc(file_VolumeDidChangeMessage, 0);\n\n",
85
85
  "// @generated by protoc-gen-es v2.10.0 with parameter \"target=ts\"\n// @generated from file WakeDeviceMessage.proto (syntax proto2)\n/* eslint-disable */\n\nimport type { GenExtension, GenFile, GenMessage } from \"@bufbuild/protobuf/codegenv2\";\nimport { extDesc, fileDesc, messageDesc } from \"@bufbuild/protobuf/codegenv2\";\nimport type { ProtocolMessage } from \"./ProtocolMessage_pb\";\nimport { file_ProtocolMessage } from \"./ProtocolMessage_pb\";\nimport type { Message } from \"@bufbuild/protobuf\";\n\n/**\n * Describes the file WakeDeviceMessage.proto.\n */\nexport const file_WakeDeviceMessage: GenFile = /*@__PURE__*/\n fileDesc(\"ChdXYWtlRGV2aWNlTWVzc2FnZS5wcm90byITChFXYWtlRGV2aWNlTWVzc2FnZTpSChF3YWtlRGV2aWNlTWVzc2FnZRIQLlByb3RvY29sTWVzc2FnZRgtIAEoCzISLldha2VEZXZpY2VNZXNzYWdlUhF3YWtlRGV2aWNlTWVzc2FnZQ\", [file_ProtocolMessage]);\n\n/**\n * @generated from message WakeDeviceMessage\n */\nexport type WakeDeviceMessage = Message<\"WakeDeviceMessage\"> & {\n};\n\n/**\n * Describes the message WakeDeviceMessage.\n * Use `create(WakeDeviceMessageSchema)` to create a new message.\n */\nexport const WakeDeviceMessageSchema: GenMessage<WakeDeviceMessage> = /*@__PURE__*/\n messageDesc(file_WakeDeviceMessage, 0);\n\n/**\n * @generated from extension: optional WakeDeviceMessage wakeDeviceMessage = 45;\n */\nexport const wakeDeviceMessage: GenExtension<ProtocolMessage, WakeDeviceMessage> = /*@__PURE__*/\n extDesc(file_WakeDeviceMessage, 0);\n\n",
86
- "import { uuid } from '@basmilius/apple-common';\nimport { create, setExtension } from '@bufbuild/protobuf';\nimport * as Proto from '@/proto';\n\nexport default class {\n clientUpdatesConfig(): Proto.ProtocolMessage {\n const protocolMessage = this.protocol(Proto.ProtocolMessage_Type.CLIENT_UPDATES_CONFIG_MESSAGE);\n const message = create(Proto.ClientUpdatesConfigMessageSchema, {\n artworkUpdates: true,\n nowPlayingUpdates: true,\n volumeUpdates: true,\n keyboardUpdates: false,\n outputDeviceUpdates: true,\n Unknown1: false\n });\n\n setExtension(protocolMessage, Proto.clientUpdatesConfigMessage, message);\n\n return protocolMessage;\n }\n\n configureConnection(groupId: string): Proto.ProtocolMessage {\n const protocolMessage = this.protocol(Proto.ProtocolMessage_Type.CONFIGURE_CONNECTION_MESSAGE);\n const message = create(Proto.ConfigureConnectionMessageSchema, {\n groupID: groupId\n });\n\n setExtension(protocolMessage, Proto.configureConnectionMessage, message);\n\n return protocolMessage;\n }\n\n deviceInfo(pairingId: Buffer): Proto.ProtocolMessage {\n const protocolMessage = this.protocol(Proto.ProtocolMessage_Type.DEVICE_INFO_MESSAGE);\n const message = create(Proto.DeviceInfoMessageSchema, {\n uniqueIdentifier: pairingId.toString(),\n name: 'iPhone van Bas',\n localizedModelName: 'iPhone',\n systemBuildVersion: '23C5027f',\n applicationBundleIdentifier: 'com.apple.mediaremoted',\n protocolVersion: 1,\n lastSupportedMessageType: 139,\n supportsSystemPairing: true,\n allowsPairing: true,\n systemMediaApplication: 'com.apple.Music',\n supportsACL: true,\n supportsSharedQueue: true,\n sharedQueueVersion: 3,\n managedConfigDeviceID: 'c4:c1:7d:93:d2:13',\n deviceClass: Proto.DeviceClass_Enum.iPhone,\n logicalDeviceCount: 1,\n isProxyGroupPlayer: false,\n groupUID: uuid().toUpperCase(),\n isGroupLeader: true,\n isAirplayActive: false,\n systemPodcastApplication: 'com.apple.podcasts',\n senderDefaultGroupUID: uuid().toUpperCase(),\n clusterType: 0,\n isClusterAware: true,\n modelID: 'iPhone16,2',\n supportsMultiplayer: false,\n routingContextID: uuid().toUpperCase(),\n airPlayGroupID: uuid().toUpperCase(),\n systemBooksApplication: 'com.apple.iBooks',\n parentGroupContainsDiscoverableGroupLeader: 1,\n groupContainsDiscoverableGroupLeader: 1,\n lastKnownClusterType: 2,\n supportsOutputContextSync: true,\n computerName: 'iPhone van Bas',\n configuredClusterSize: 0\n // applicationBundleVersion: '344.28',\n // protocolVersion: 1,\n // lastSupportedMessageType: 108,\n // supportsSystemPairing: true,\n // allowsPairing: true,\n // systemMediaApplication: 'com.apple.TVMusic',\n // supportsACL: true,\n // supportsSharedQueue: true,\n // supportsExtendedMotion: true,\n // sharedQueueVersion: 2,\n // deviceClass: 1,\n // logicalDeviceCount: 1\n });\n\n setExtension(protocolMessage, Proto.deviceInfoMessage, message);\n\n return protocolMessage;\n }\n\n notification(notification: string[]): Proto.ProtocolMessage {\n const protocolMessage = this.protocol(Proto.ProtocolMessage_Type.NOTIFICATION_MESSAGE);\n const message = create(Proto.NotificationMessageSchema, {\n notification\n });\n\n setExtension(protocolMessage, Proto.notificationMessage, message);\n\n return protocolMessage;\n }\n\n protocol(type: Proto.ProtocolMessage_Type, errorCode: Proto.ErrorCode_Enum = Proto.ErrorCode_Enum.NoError): Proto.ProtocolMessage {\n return create(Proto.ProtocolMessageSchema, {\n type,\n errorCode,\n identifier: uuid().toUpperCase(),\n uniqueIdentifier: uuid().toUpperCase()\n });\n }\n\n sendButtonEvent(usagePage: number, usage: number, buttonDown: boolean): Proto.ProtocolMessage {\n const protocolMessage = this.protocol(Proto.ProtocolMessage_Type.SEND_BUTTON_EVENT_MESSAGE);\n const message = create(Proto.SendButtonEventMessageSchema, {\n usagePage,\n usage,\n buttonDown\n });\n\n setExtension(protocolMessage, Proto.sendButtonEventMessage, message);\n\n return protocolMessage;\n }\n\n sendCommand(command: Proto.Command, options?: Proto.CommandOptions): Proto.ProtocolMessage {\n const protocolMessage = this.protocol(Proto.ProtocolMessage_Type.SEND_COMMAND_MESSAGE);\n const message = create(Proto.SendCommandMessageSchema, {\n command,\n options\n });\n\n setExtension(protocolMessage, Proto.sendCommandMessage, message);\n\n return protocolMessage;\n }\n\n setConnectionState(state: Proto.SetConnectionStateMessage_ConnectionState = Proto.SetConnectionStateMessage_ConnectionState.Connected): Proto.ProtocolMessage {\n const protocolMessage = this.protocol(Proto.ProtocolMessage_Type.SET_CONNECTION_STATE_MESSAGE);\n const message = create(Proto.SetConnectionStateMessageSchema, {\n state\n });\n\n setExtension(protocolMessage, Proto.setConnectionStateMessage, message);\n\n return protocolMessage;\n }\n\n setVolume(volume: number): Proto.ProtocolMessage {\n const protocolMessage = this.protocol(Proto.ProtocolMessage_Type.SET_VOLUME_MESSAGE);\n const message = create(Proto.SetVolumeMessageSchema, {\n volume\n });\n\n setExtension(protocolMessage, Proto.setVolumeMessage, message);\n\n return protocolMessage;\n }\n}\n",
86
+ "import { uuid } from '@basmilius/apple-common';\nimport { create, setExtension } from '@bufbuild/protobuf';\nimport * as Proto from '../proto';\n\nexport default class {\n clientUpdatesConfig(): Proto.ProtocolMessage {\n const protocolMessage = this.protocol(Proto.ProtocolMessage_Type.CLIENT_UPDATES_CONFIG_MESSAGE);\n const message = create(Proto.ClientUpdatesConfigMessageSchema, {\n artworkUpdates: true,\n nowPlayingUpdates: true,\n volumeUpdates: true,\n keyboardUpdates: false,\n outputDeviceUpdates: true,\n Unknown1: false\n });\n\n setExtension(protocolMessage, Proto.clientUpdatesConfigMessage, message);\n\n return protocolMessage;\n }\n\n configureConnection(groupId: string): Proto.ProtocolMessage {\n const protocolMessage = this.protocol(Proto.ProtocolMessage_Type.CONFIGURE_CONNECTION_MESSAGE);\n const message = create(Proto.ConfigureConnectionMessageSchema, {\n groupID: groupId\n });\n\n setExtension(protocolMessage, Proto.configureConnectionMessage, message);\n\n return protocolMessage;\n }\n\n deviceInfo(pairingId: Buffer): Proto.ProtocolMessage {\n const protocolMessage = this.protocol(Proto.ProtocolMessage_Type.DEVICE_INFO_MESSAGE);\n const message = create(Proto.DeviceInfoMessageSchema, {\n uniqueIdentifier: pairingId.toString(),\n name: 'iPhone van Bas',\n localizedModelName: 'iPhone',\n systemBuildVersion: '23C5027f',\n applicationBundleIdentifier: 'com.apple.mediaremoted',\n protocolVersion: 1,\n lastSupportedMessageType: 139,\n supportsSystemPairing: true,\n allowsPairing: true,\n systemMediaApplication: 'com.apple.Music',\n supportsACL: true,\n supportsSharedQueue: true,\n sharedQueueVersion: 3,\n managedConfigDeviceID: 'c4:c1:7d:93:d2:13',\n deviceClass: Proto.DeviceClass_Enum.iPhone,\n logicalDeviceCount: 1,\n isProxyGroupPlayer: false,\n groupUID: uuid().toUpperCase(),\n isGroupLeader: true,\n isAirplayActive: false,\n systemPodcastApplication: 'com.apple.podcasts',\n senderDefaultGroupUID: uuid().toUpperCase(),\n clusterType: 0,\n isClusterAware: true,\n modelID: 'iPhone16,2',\n supportsMultiplayer: false,\n routingContextID: uuid().toUpperCase(),\n airPlayGroupID: uuid().toUpperCase(),\n systemBooksApplication: 'com.apple.iBooks',\n parentGroupContainsDiscoverableGroupLeader: 1,\n groupContainsDiscoverableGroupLeader: 1,\n lastKnownClusterType: 2,\n supportsOutputContextSync: true,\n computerName: 'iPhone van Bas',\n configuredClusterSize: 0\n // applicationBundleVersion: '344.28',\n // protocolVersion: 1,\n // lastSupportedMessageType: 108,\n // supportsSystemPairing: true,\n // allowsPairing: true,\n // systemMediaApplication: 'com.apple.TVMusic',\n // supportsACL: true,\n // supportsSharedQueue: true,\n // supportsExtendedMotion: true,\n // sharedQueueVersion: 2,\n // deviceClass: 1,\n // logicalDeviceCount: 1\n });\n\n setExtension(protocolMessage, Proto.deviceInfoMessage, message);\n\n return protocolMessage;\n }\n\n notification(notification: string[]): Proto.ProtocolMessage {\n const protocolMessage = this.protocol(Proto.ProtocolMessage_Type.NOTIFICATION_MESSAGE);\n const message = create(Proto.NotificationMessageSchema, {\n notification\n });\n\n setExtension(protocolMessage, Proto.notificationMessage, message);\n\n return protocolMessage;\n }\n\n protocol(type: Proto.ProtocolMessage_Type, errorCode: Proto.ErrorCode_Enum = Proto.ErrorCode_Enum.NoError): Proto.ProtocolMessage {\n return create(Proto.ProtocolMessageSchema, {\n type,\n errorCode,\n identifier: uuid().toUpperCase(),\n uniqueIdentifier: uuid().toUpperCase()\n });\n }\n\n sendButtonEvent(usagePage: number, usage: number, buttonDown: boolean): Proto.ProtocolMessage {\n const protocolMessage = this.protocol(Proto.ProtocolMessage_Type.SEND_BUTTON_EVENT_MESSAGE);\n const message = create(Proto.SendButtonEventMessageSchema, {\n usagePage,\n usage,\n buttonDown\n });\n\n setExtension(protocolMessage, Proto.sendButtonEventMessage, message);\n\n return protocolMessage;\n }\n\n sendCommand(command: Proto.Command, options?: Proto.CommandOptions): Proto.ProtocolMessage {\n const protocolMessage = this.protocol(Proto.ProtocolMessage_Type.SEND_COMMAND_MESSAGE);\n const message = create(Proto.SendCommandMessageSchema, {\n command,\n options\n });\n\n setExtension(protocolMessage, Proto.sendCommandMessage, message);\n\n return protocolMessage;\n }\n\n setConnectionState(state: Proto.SetConnectionStateMessage_ConnectionState = Proto.SetConnectionStateMessage_ConnectionState.Connected): Proto.ProtocolMessage {\n const protocolMessage = this.protocol(Proto.ProtocolMessage_Type.SET_CONNECTION_STATE_MESSAGE);\n const message = create(Proto.SetConnectionStateMessageSchema, {\n state\n });\n\n setExtension(protocolMessage, Proto.setConnectionStateMessage, message);\n\n return protocolMessage;\n }\n\n setVolume(volume: number): Proto.ProtocolMessage {\n const protocolMessage = this.protocol(Proto.ProtocolMessage_Type.SET_VOLUME_MESSAGE);\n const message = create(Proto.SetVolumeMessageSchema, {\n volume\n });\n\n setExtension(protocolMessage, Proto.setVolumeMessage, message);\n\n return protocolMessage;\n }\n}\n",
87
87
  "import { Socket } from 'node:net';\nimport { BaseSocket, debug, decryptChacha20, encryptChacha20 } from '@basmilius/apple-common';\n\nexport default class AirPlayStream<TEventMap extends Record<string, any>> extends BaseSocket<TEventMap> {\n get isConnected(): boolean {\n return this.#socket.readyState === 'open';\n }\n\n get isEncrypted(): boolean {\n return !!this.#readKey && !!this.#writeKey;\n }\n\n get socket(): Socket {\n return this.#socket;\n }\n\n get readKey(): Buffer {\n return this.#readKey;\n }\n\n get writeKey(): Buffer {\n return this.#writeKey;\n }\n\n readonly #socket: Socket;\n #buffer: Buffer = Buffer.alloc(0);\n #readCount: number;\n #readKey?: Buffer;\n #writeCount: number;\n #writeKey?: Buffer;\n\n constructor(address: string, port: number) {\n super(address, port);\n\n this.onClose = this.onClose.bind(this);\n this.onConnect = this.onConnect.bind(this);\n this.onData = this.onData.bind(this);\n this.onEnd = this.onEnd.bind(this);\n this.onError = this.onError.bind(this);\n\n this.#socket = new Socket();\n this.#socket.on('close', this.onClose);\n this.#socket.on('connect', this.onConnect);\n this.#socket.on('data', this.onData);\n this.#socket.on('end', this.onEnd);\n this.#socket.on('error', this.onError);\n }\n\n async connect(): Promise<void> {\n debug(`Connecting to ${this.address}:${this.port}...`);\n\n return await new Promise(resolve => {\n this.#socket.connect({\n host: this.address,\n port: this.port,\n keepAlive: true\n }, resolve);\n });\n }\n\n async disconnect(): Promise<void> {\n this.#socket.destroy();\n }\n\n async enableEncryption(readKey: Buffer, writeKey: Buffer): Promise<void> {\n this.#readKey = readKey;\n this.#writeKey = writeKey;\n this.#readCount = 0;\n this.#writeCount = 0;\n }\n\n async decrypt(data: Buffer): Promise<Buffer> {\n if (this.#buffer) {\n data = Buffer.concat([this.#buffer, data]);\n this.#buffer = undefined;\n }\n\n let result = Buffer.alloc(0);\n let offset = 0;\n\n while (offset + 2 <= data.length) {\n const length = data.readUInt16LE(offset);\n\n const totalChunkLength = 2 + length + 16;\n\n if (offset + totalChunkLength > data.length) {\n this.#buffer = data.subarray(offset);\n break;\n }\n\n const aad = data.subarray(offset, offset + 2);\n const ciphertext = data.subarray(offset + 2, offset + 2 + length);\n const authTag = data.subarray(offset + 2 + length, offset + 2 + length + 16);\n\n const nonce = Buffer.alloc(12);\n nonce.writeBigUInt64LE(BigInt(this.#readCount++), 4);\n\n const plaintext = decryptChacha20(\n this.#readKey,\n nonce,\n aad,\n ciphertext,\n authTag\n );\n\n result = Buffer.concat([result, plaintext]);\n offset += totalChunkLength;\n }\n\n return result;\n }\n\n async encrypt(data: Buffer): Promise<Buffer> {\n const total = data.length;\n let result = Buffer.alloc(0);\n\n for (let offset = 0; offset < total;) {\n const length = Math.min(total - offset, 0x400);\n const leLength = Buffer.alloc(2);\n leLength.writeUInt16LE(length, 0);\n\n const nonce = Buffer.alloc(12);\n nonce.writeBigUInt64LE(BigInt(this.#writeCount++), 4);\n\n const encrypted = encryptChacha20(\n this.#writeKey,\n nonce,\n leLength,\n data.subarray(offset, offset + length)\n );\n\n offset += length;\n result = Buffer.concat([result, leLength, encrypted.ciphertext, encrypted.authTag]);\n }\n\n return result;\n }\n\n async onClose(): Promise<void> {\n await super.onClose();\n\n debug(`Connection closed from ${this.address}:${this.port}`);\n }\n\n async onConnect(): Promise<void> {\n await super.onConnect();\n\n debug(`Connected to ${this.address}:${this.port}`);\n }\n\n async onData(buffer: Buffer): Promise<void> {\n debug('Data frame received', buffer.toString());\n }\n\n async onEnd(): Promise<void> {\n debug('Connection ended');\n }\n\n async onError(err: Error): Promise<void> {\n await super.onError(err);\n\n debug('Error received', err);\n }\n}\n",
88
88
  "import { debug, hkdf, parseBinaryPlist } from '@basmilius/apple-common';\nimport type { RTSPMethod } from './types';\nimport { makeHttpRequest } from './utils';\nimport AirPlayStream from './stream';\n\nexport default class AirPlayEventStream extends AirPlayStream<never> {\n #buffer: Buffer = Buffer.alloc(0);\n\n async respond(response: Response): Promise<void> {\n const body = Buffer.from(await response.arrayBuffer());\n\n const header = [];\n header.push(`RTSP/1.0 ${response.status} ${response.statusText}`);\n\n for (const [name, value] of Object.entries(response.headers)) {\n header.push(`${name}: ${value}`);\n }\n\n if (body.byteLength > 0) {\n header.push(`Content-Length: ${body.byteLength}`);\n } else {\n header.push('Content-Length: 0');\n }\n\n header.push('');\n header.push('');\n\n const headers = header.join('\\r\\n');\n let data: Buffer;\n\n if (response.body) {\n data = Buffer.concat([\n Buffer.from(headers),\n body\n ]);\n } else {\n data = Buffer.from(headers);\n }\n\n if (this.isEncrypted) {\n data = await this.encrypt(data);\n }\n\n this.socket.write(data);\n }\n\n async setup(sharedSecret: Buffer): Promise<void> {\n const readKey = hkdf({\n hash: 'sha512',\n key: sharedSecret,\n length: 32,\n salt: Buffer.from('Events-Salt'),\n info: Buffer.from('Events-Read-Encryption-Key')\n });\n\n const writeKey = hkdf({\n hash: 'sha512',\n key: sharedSecret,\n length: 32,\n salt: Buffer.from('Events-Salt'),\n info: Buffer.from('Events-Write-Encryption-Key')\n });\n\n await this.enableEncryption(writeKey, readKey);\n }\n\n async onData(buffer: Buffer): Promise<void> {\n this.#buffer = Buffer.concat([this.#buffer, buffer]);\n\n if (this.isEncrypted) {\n this.#buffer = await this.decrypt(this.#buffer);\n }\n\n // debug('Event stream received data', this.#buffer.toString());\n\n while (this.#buffer.byteLength > 0) {\n const result = makeHttpRequest(this.#buffer);\n\n if (result === null) {\n return;\n }\n\n this.#buffer = this.#buffer.subarray(result.requestLength);\n\n await this.#handle(result.method, result.path, result.headers, result.body);\n }\n }\n\n async #handle(method: RTSPMethod, path: string, headers: Record<string, string>, body: Buffer): Promise<void> {\n const key = `${method} ${path}`;\n\n debug(key);\n\n switch (key) {\n case 'POST /command':\n const data = parseBinaryPlist(body.buffer.slice(body.byteOffset, body.byteOffset + body.byteLength) as any) as any;\n\n debug(data);\n\n const response = new Response(null, {\n status: 200,\n statusText: 'OK',\n headers: {\n 'Audio-Latency': '0',\n 'CSeq': (headers['CSeq'] ?? 0).toString()\n }\n });\n\n await this.respond(response);\n break;\n\n default:\n debug('No handler for url', key);\n break;\n }\n }\n}\n",
89
89
  "import { type AccessoryCredentials, type AccessoryKeys, AccessoryPair } from '@basmilius/apple-common';\nimport type AirPlay from './protocol';\nimport type AirPlayRTSP from './rtsp';\n\nexport default class AirPlayPairing {\n get internal(): AccessoryPair {\n return this.#internal;\n }\n\n get rtsp(): AirPlayRTSP {\n return this.#protocol.rtsp;\n }\n\n readonly #internal: AccessoryPair;\n readonly #protocol: AirPlay;\n #hkp: 3 | 4;\n\n constructor(protocol: AirPlay) {\n this.#internal = new AccessoryPair(this.#request.bind(this));\n this.#protocol = protocol;\n }\n\n async start(): Promise<void> {\n await this.#internal.start();\n }\n\n async pin(askPin: () => Promise<string>): Promise<AccessoryCredentials> {\n this.#hkp = 3;\n\n await this.#pinStart();\n\n return this.#internal.pin(askPin);\n }\n\n async pinStart(): Promise<void> {\n this.#hkp = 3;\n\n await this.#pinStart();\n }\n\n async transient(): Promise<AccessoryKeys> {\n this.#hkp = 4;\n\n await this.#pinStart();\n\n return this.#internal.transient();\n }\n\n async #pinStart(): Promise<void> {\n const response = await this.rtsp.post('/pair-pin-start', null, {\n 'Content-Type': 'application/octet-stream',\n 'X-Apple-HKP': this.#hkp.toString()\n });\n\n if (response.status !== 200) {\n throw new Error('Cannot start pairing session.');\n }\n }\n\n async #request(_: 'm1' | 'm3' | 'm5', data: Buffer): Promise<Buffer> {\n const response = await this.rtsp.post('/pair-setup', data, {\n 'Content-Type': 'application/octet-stream',\n 'X-Apple-HKP': this.#hkp.toString()\n });\n\n return Buffer.from(await response.arrayBuffer());\n }\n}\n",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@basmilius/apple-airplay",
3
3
  "description": "Implementation of Apple's AirPlay2 in Node.js.",
4
- "version": "0.0.30",
4
+ "version": "0.0.31",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "author": {
@@ -41,7 +41,7 @@
41
41
  }
42
42
  },
43
43
  "dependencies": {
44
- "@basmilius/apple-common": "0.0.30",
44
+ "@basmilius/apple-common": "0.0.31",
45
45
  "@bufbuild/protobuf": "^2.10.0"
46
46
  },
47
47
  "devDependencies": {