UNPKG

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

Version:

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

61 lines 2.65 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 { DefaultWebSocketMessagesHandle } from './handles/messages-websocket'; import { DefaultCommandsHandle } from './handles/commands'; import { AbstractDittoClient } from './ditto-client'; import { DefaultThingsHandle } from './handles/things'; import { DefaultFeaturesHandle } from './handles/features'; import { WebSocketEventsHandle } from './handles/events-websocket'; class DefaultHandles { constructor() { this.thingsHandle = DefaultThingsHandle.getInstance; this.featuresHandle = DefaultFeaturesHandle.getInstance; this.eventsHandle = WebSocketEventsHandle.getInstance; this.messagesHandle = DefaultWebSocketMessagesHandle.getInstance; this.commandsHandle = DefaultCommandsHandle.getInstance; } } export class DefaultDittoWebSocketClient extends AbstractDittoClient { constructor(builder, responseHandler, handles) { super(builder, handles); this.responseHandler = responseHandler; } /** * Returns an instance of DittoClient based on the context provided. * * @param requestSenderFactory - The request sender factory to use. * @param requester - The requester to use. * @param customHandles - custom handles to use with the client. * @return the DittoClient instance. */ static getInstance(requestSenderFactory, requester, customHandles) { const handles = Object.assign(new DefaultHandles(), customHandles); return new DefaultDittoWebSocketClient(requestSenderFactory, requester, handles); } getThingsHandle(customBuildContext) { return this.handles.thingsHandle(this.builder, customBuildContext); } getEventsHandle(customBuildContext) { return this.handles.eventsHandle(this.builder, this.responseHandler, customBuildContext); } getMessagesHandle(customBuildContext) { return this.handles.messagesHandle(this.builder, this.responseHandler, customBuildContext); } getCommandsHandle(customBuildContext) { return this.handles.commandsHandle(this.builder, this.responseHandler, customBuildContext); } close(code, data) { this.responseHandler.close(code, data); } } //# sourceMappingURL=ditto-client-websocket.js.map