UNPKG

@eclipse-ditto/ditto-javascript-client-dom

Version:

DOM implementation of Eclipse Ditto JavaScript API to be used in browsers.

159 lines 5.97 kB
/*! * Copyright (c) 2019 Contributors to the Eclipse Foundation * * See the NOTICE file(s) distributed with this work for additional * information regarding copyright ownership. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * http://www.eclipse.org/legal/epl-2.0 * * SPDX-License-Identifier: EPL-2.0 */ import { RequestOptions } from '../../options/request.options'; import { FetchRequest, RequestSender, RequestSenderFactory } from './request-sender'; import { ProtocolResponseValue, WebSocketRequestHandler } from './websocket-request-handler'; import { ApiVersion, Channel } from '../../model/ditto-protocol'; import { GenericResponse } from '../../model/response'; /** * Handle to send web socket requests. */ export declare class WebSocketRequestSender extends RequestSender { private readonly requester; readonly group: string; readonly channel: 'twin' | 'live'; readonly apiVersion: 2; constructor(requester: WebSocketRequestHandler, group: string, channel: 'twin' | 'live', apiVersion: 2); private static buildPath; /** * Builds the path to use for a Message web socket request. * * @param path - The path to the entity within the basic object. * @param mailbox - The direction the message is sent in (eg. inbox). * @param subject - The subject of the message. * @returns The path for a Message request */ private static buildMessagePath; /** * Splits an ID into name and namespace. Element 0 is the namespace and element 1 is the name. * * @param idWithNamespace - The id to separate. * @returns The Array containing namespace and name */ private static separateNamespace; /** * Translate a verb from HTTP (eg. GET) into web socket form (eg. retrieve). * * @param verb - The verb to translate. * @returns The translated verb */ private static translateVerb; /** * The basic headers needed for every web socket request. * * @returns The headers */ private get baseHeaders(); fetchRequest(options: FetchRequest): Promise<GenericResponse>; /** * Fetches the specified request and checks if the request was successful. * * @param options - The options to use for the request. * @returns A Promise for the response */ fetchGenericJsonRequest(options: FetchRequest): Promise<GenericResponse>; /** * Sends a Message and returns the response. * * @param options - The options to use for the Message. * @returns A Promise for the response */ sendMessageWithResponse(options: MessageRequest): Promise<GenericResponse>; /** * Sends a Message. * * @param options - The options to use for the Message. * @returns A Promise that resolves once the Message was sent */ sendMessage(options: MessageRequest): Promise<void>; /** * Registers a subscription. * * @param options - The options to use for the subscription. * @returns The id of the subscription. It can be used to delete the subscription. */ subscribe(options: SubscribeRequest): string; /** * Builds headers to use for a web socket request. It combines base headers, options headers and then additional headers * * @param options - The options to provided in the request. * @param additionalHeaders - Additional headers to add. * @returns The combined headers */ private buildHeaders; /** * Builds the topic to use for a Message web socket request. * * @param id - The id of the basic entity the request is for. * @param messageSubject - The subject of the message. * @returns The topic for a Message request */ private buildMessageTopic; /** * Builds the topic to use for a web socket request. * * @param id - The id of the basic entity the request is for. * @param group - The group of the request (eg. things). * @param criterion - The area of the request (eg. commands). * @param action - The action to perform. * @returns The topic for a request */ private buildTopic; } /** * A Factory for a WebSocketRequestSender. */ export declare class WebSocketRequestSenderFactory implements RequestSenderFactory { private readonly apiVersion; private readonly channel; private readonly requester; constructor(apiVersion: ApiVersion, channel: Channel, requester: WebSocketRequestHandler); buildInstance(group: string): WebSocketRequestSender; } /** * The specification of a Message to be sent over the web socket connection. */ export interface MessageRequest { /** The id of the basic entity the request is for. */ id: string; /** The path to the entity the request is about from the basic entity. */ path?: string; /** The subject of the message. */ messageSubject: string; /** The message. */ message: string; /** The direction to send in (outbox/inbox). */ direction: string; /** The content type of the message. */ contentType: string; /** The options to use for the request. */ options?: RequestOptions; } /** * The specification of a subscription to register. */ export interface SubscribeRequest { /** The id of the basic entity to subscribe to. */ id: string; /** The callback to call every time a message that fits the criteria comes in. */ callback: (message: ProtocolResponseValue) => any; /** The type of message to subscribe to (eg. event). */ type: string; /** The path to the entity to subscribe to */ path?: string; /** The action to listen for (eg. modify). */ action?: string; /** Whether or not sub-resources of the Property should also trigger the callback. */ subResources?: boolean; } //# sourceMappingURL=websocket-request-sender.d.ts.map