Class EventedHTTPServer

EventedHTTPServer provides an HTTP-like server that supports HAP "extensions" for security and events.


In order to implement the "custom HTTP" server required by the HAP protocol (see HAPServer.js) without completely reinventing the wheel, we create both a generic TCP socket server and a standard Node HTTP server. The TCP socket server acts as a proxy, allowing users of this class to transform data (for encryption) as necessary and passing through bytes directly to the HTTP server for processing. This way we get Node to do all the "heavy lifting" of HTTP like parsing headers and formatting responses.

Events are sent by simply waiting for current HTTP traffic to subside and then sending a custom response packet directly down the wire via the socket.

Each connection to the main TCP server gets its own internal HTTP server, so we can track ongoing requests/responses for safe event insertion.


  • EventEmitter
    • EventedHTTPServer



  • Send an event notification for given characteristic and changed value to all connected clients. If originator is specified, the given HAPConnection will be excluded from the broadcast.


    • aid: number

      The accessory id of the updated characteristic.

    • iid: number

      The instance id of the updated characteristic.

    • value: Nullable<CharacteristicValue>

      The newly set value of the characteristic.

    • Optional originator: HAPConnection

      If specified, the connection will not get an event message.

    • Optional immediateDelivery: boolean

      The HAP spec requires some characteristics to be delivery immediately. Namely, for the ButtonEvent and the ProgrammableSwitchEvent characteristics.

    Returns void

  • Parameters

    • targetPort: number
    • Optional hostname: string

    Returns void

  • This method is to be called when a given HAPConnection performs a request that should result in the disconnection of all other HAPConnection with the same HAPUsername.

    The initiator MUST be in the middle of a http request were the response was not served yet. Otherwise, the initiator connection might reside in a state where it isn't disconnected and can't make any further requests.


    • initiator: HAPConnection

      The connection that requested to disconnect all connections of the same username.

    • username: string

      The username for which all connections shall be closed.

    Returns void