@homebridge/hap-nodejs
    Preparing search index...

    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.

    Hierarchy

    • EventEmitter
      • EventedHTTPServer
    Index

    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
      • Optionalhostname: string

      Returns void

    • Parameters

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

      Returns this

    • Parameters

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

      Returns this

    • Parameters

      • event: "request"
      • listener: (
            connection: HAPConnection,
            request: IncomingMessage,
            response: ServerResponse,
        ) => void

      Returns this

    • Parameters

      • event: "connection-closed"
      • listener: (connection: HAPConnection) => 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