/// import { Socket } from 'net'; import { HAPServerConnection } from "../HAPServer"; import { EventEmitter } from "../lib/EventEmitter"; import { DataStreamClientConnection } from "./DataStreamClient"; import { DataStreamConnection, DataStreamConnectionEventMap } from "./DataStreamConnection"; import { HDSFrame } from "./index"; import Timeout = NodeJS.Timeout; export declare type PreparedDataStreamSession = { connection: HAPServerConnection; hdsClientConnection: DataStreamClientConnection; accessoryToControllerEncryptionKey: Buffer; controllerToAccessoryEncryptionKey: Buffer; accessoryKeySalt: Buffer; port?: number; connectTimeout?: Timeout; }; export declare enum DataStreamServerEvents { CONNECTION_OPENED = "connection-opened", CONNECTION_IDENTIFIED = "connection-identified", CONNECTION_CLOSED = "connection-closed" } export declare type DataStreamServerEventMap = { [DataStreamServerEvents.CONNECTION_OPENED]: (connection: DataStreamServerConnection) => void; [DataStreamServerEvents.CONNECTION_IDENTIFIED]: (preparedSession: PreparedDataStreamSession, connection: DataStreamServerConnection) => void; [DataStreamServerEvents.CONNECTION_CLOSED]: (connection: DataStreamServerConnection) => void; }; /** * DataStreamServer which listens for incoming tcp connections and handles identification of new connections * * @event 'connection-opened': (connection: DataStreamServerConnection) => void * This event is emitted when a new client socket is received. At this point we have no idea to what * hap session this connection will be matched. * * @event 'connection-closed': (connection: DataStreamServerConnection) => void * This event is emitted when the socket of a connection gets closed. */ export declare class DataStreamServer extends EventEmitter { private state; private tcpServer?; private tcpPort?; preparedSessions: PreparedDataStreamSession[]; private connections; constructor(); prepareSession(connection: HAPServerConnection, controllerKeySalt: Buffer, clientConnection: DataStreamClientConnection, callback: (preparedSession: PreparedDataStreamSession) => void): void; private timeoutPreparedSession; private checkTCPServerEstablished; private listening; private onConnection; private handleSessionIdentification; private connectionClosed; private checkCloseable; private closed; } export declare enum DataStreamServerConnectionEvents { IDENTIFICATION = "identification" } export declare type IdentificationCallback = (identifiedSession?: PreparedDataStreamSession) => void; export interface DataStreamServerConnectionEventMap extends DataStreamConnectionEventMap { [DataStreamServerConnectionEvents.IDENTIFICATION]: (frame: HDSFrame, callback: IdentificationCallback) => void; } /** * DataStream connection which holds any necessary state information, encryption an decryption keys, manages * protocol handlers and also handles sending and receiving of data stream frames. * * @event 'identification': (frame: HDSFrame, callback: IdentificationCallback) => void * This event is emitted when the first HDSFrame is received from a new connection. * The connection expects the handler to identify the connection by trying to match the decryption keys. * If identification was successful the PreparedDataStreamSession should be supplied to the callback, * otherwise undefined should be supplied. * * @event 'handle-message-globally': (message: DataStreamMessage) => void * This event is emitted when no handler could be found for the given protocol of a event or request message. * * @event 'closed': () => void * This event is emitted when the socket of the connection was closed. */ export declare class DataStreamServerConnection extends DataStreamConnection { private connection?; constructor(socket: Socket); protected handleInitialization(firstFrame: HDSFrame): void; } //# sourceMappingURL=DataStreamServer.d.ts.map