import { HttpSupport } from '../../../../util/HttpSupport'; import { CloverWebSocketClient } from './CloverWebSocketClient'; import { WebSocketCloverTransport } from "./WebSocketCloverTransport"; /** * WebSocket Cloud Clover Transport. This handles the need to notify the device before a connection attempt is made. * */ export declare class WebSocketCloudCloverTransport extends WebSocketCloverTransport { /** * HTTP Header key that helps identify the connected client. Typically set to the * 'friendlyId'. * * @type {string} */ static X_CLOVER_CONNECTED_ID: string; private httpSupport; private readonly cloverServer; private webSocketURL; private readonly merchantId; private readonly accessToken; private readonly deviceId; private readonly friendlyId; private readonly forceConnect; /** * @param {number} reconnectDelay - duration to wait until a reconnect is attempted - millis. * @param {Object} webSocketImplClass - the function that will return an instance of the * CloverWebSocketInterface that will be used when connecting. For Browser implementations, this can be * @param {string} cloverServer the base url for the clover server used in the cloud connection. * EX: https://www.clover.com, http://localhost:9000 * @param {string} merchantId - the merchant the device belongs to. * @param {string} accessToken - the OAuth access token that will be used when contacting the clover server * @param {string} deviceId - the id (not uuid) of the device to connect to * @param {string} friendlyId - an identifier for the specific terminal connected to this device. This id is used * in debugging and may be sent to other clients if they attempt to connect to the same device. It will also be * sent to other clients that are currently connected if this device does a forceConnect. * @param {boolean} forceConnect - if true, overtake any existing connection. * @param {HttpSupport} httpSupport - the helper object used when making http requests. */ constructor(reconnectDelay: number, webSocketImplClass: any, cloverServer: string, merchantId: string, accessToken: string, deviceId: string, friendlyId: string, forceConnect: boolean, httpSupport: HttpSupport); /** * Calls COS's alert endpoint which: * Initialize the connection. */ initialize(): void; /** * Calls the COS remote_pay endpoint which: * * 1) Determines what Cloud/Support server we should open a WebSocket connection to, and returns the URL of this server * in the response so we can establish a connection. Versions of COS post SEMI-2079 deployment return a Cloud/Support * server identifier in the queryString which is used by HA Proxy to connect to the correct server. * 2) Sends a PUSH notification to the device, to notify it what server to open a WebSocket connection to. * * To make the call, we need a valid OAuth access token and to have an AJAX implementation abstraction that does * not tie us to a particular environment (e.g. the SDK code can work in the browser as well as Node, etc.). * This abstraction is httpSupport an implementation of which can be passed in in this classes constructor. */ private obtainWebSocketUrlAndSendPushAlert; /** * This handles the response from the server of the request to send a notification to the device. If the * notification was successful, then an OPTIONS call is made using the information provided. * * @param notificationResponse - has a boolean property for 'sent', that indicates if the notification * was sent to the device. If it was, then the properties 'host' and 'token' are used to derive the * websocket endpoint uri. */ private deviceNotificationSent; /** * Do an OPTIONS call to the web socket endpoint (using http). This helps with a problem where a 401 * response came back from the websocket endpoint. * * @param deviceWebSocketEndpoint */ private doOptionsCallToAvoid401Error; /** * Handles the response to the OPTIONS call. This helps with a 401 response, and is used to help identify * any existing connection to the device. * * If the endpoint is available, then the transport is connected to the websocket. * * @param deviceWebSocketEndpoint */ private afterOptionsCall; private buildAuthorizationHeader; /** * * @override * @param ws */ onOpen(ws: CloverWebSocketClient): void; }