Class EventedHTTPServer

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

Implementation

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.

Hierarchy

  • EventEmitter
    • EventedHTTPServer

Constructors

Methods

  • 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.

    Parameters

    Returns void

  • Parameters

    • targetPort: number
    • Optional hostname: string

    Returns void

  • Parameters

    • event: "listening"
    • listener: ((port, address) => void)
        • (port, address): void
        • Parameters

          • port: number
          • address: string

          Returns void

    Returns this

  • Parameters

    • event: "connection-opened"
    • listener: ((connection) => void)
        • (connection): void
        • Parameters

          Returns void

    Returns this

  • Parameters

    • event: "request"
    • listener: ((connection, request, response) => void)
        • (connection, request, response): void
        • Parameters

          • connection: HAPConnection
          • request: IncomingMessage
          • response: ServerResponse

          Returns void

    Returns this

  • Parameters

    • event: "connection-closed"
    • listener: ((connection) => void)
        • (connection): void
        • Parameters

          Returns void

    Returns this

  • 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.

    Parameters

    • 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