@eclipse-ditto/ditto-javascript-client-node
Version:
Node.js(r) implementation of Eclipse Ditto JavaScript API.
106 lines • 4.7 kB
JavaScript
"use strict";
/*!
* 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
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.WebSocketClientBuilder = void 0;
/* tslint:disable:no-empty-interface */
const websocket_resilience_handler_bufferless_1 = require("./request-factory/resilience/websocket-resilience-handler-bufferless");
const websocket_resilience_handler_standard_1 = require("./request-factory/resilience/websocket-resilience-handler-standard");
const websocket_resilience_interfaces_1 = require("./request-factory/resilience/websocket-resilience-interfaces");
const websocket_request_sender_1 = require("./request-factory/websocket-request-sender");
const websocket_request_handler_1 = require("./request-factory/websocket-request-handler");
const ditto_client_websocket_1 = require("./ditto-client-websocket");
const auth_provider_1 = require("../auth/auth-provider");
const ditto_protocol_1 = require("../model/ditto-protocol");
const builder_steps_1 = require("./builder-steps");
/**
* Implementation of all the methods to build a Context.
*/
class WebSocketClientBuilder extends builder_steps_1.AbstractBuilder {
constructor(builder) {
super();
this.builder = builder;
this.customHandles = {};
this.stateHandler = new websocket_resilience_interfaces_1.NoopWebSocketStateHandler();
}
/**
* Creates a new WebSocket Builder.
*
* @param urlBuilder The url builder used by the builder.
*/
static newBuilder(urlBuilder) {
return new WebSocketClientBuilder(urlBuilder);
}
finalize() {
return this;
}
withStateHandler(handler) {
this.stateHandler = handler;
return this;
}
withBuffer(size) {
this.resilienceFactory = websocket_resilience_handler_standard_1.StandardResilienceHandlerFactory.getInstance(size);
return this;
}
withoutBuffer() {
this.resilienceFactory = websocket_resilience_handler_bufferless_1.BufferlessResilienceHandlerFactory.getInstance();
return this;
}
liveChannel() {
this.channel = ditto_protocol_1.Channel.live;
return this;
}
twinChannel() {
this.channel = ditto_protocol_1.Channel.twin;
return this;
}
withCustomThingsHandle(factory) {
this.customHandles = Object.assign(this.customHandles, { thingsHandle: factory });
return this;
}
withCustomFeaturesHandle(factory) {
this.customHandles = Object.assign(this.customHandles, { featuresHandle: factory });
return this;
}
withCustomMessagesHandle(factory) {
this.customHandles = Object.assign(this.customHandles, { messagesHandle: factory });
return this;
}
withCustomEventsHandle(factory) {
this.customHandles = Object.assign(this.customHandles, { eventsHandle: factory });
return this;
}
withCustomCommandsHandle(factory) {
this.customHandles = Object.assign(this.customHandles, { commandsHandle: factory });
return this;
}
build() {
const protocol = this.tls ? 'wss' : 'ws';
const path = (this.customPath === undefined) ? '/ws' : this.customPath;
const resilienceHandlerFactory = this.resilienceFactory.withContext(this.builder.withConnectionDetails(auth_provider_1.ImmutableURL.newInstance(protocol, this.domain, `${path}/${this.apiVersion}`), this.authProviders), this.stateHandler);
const requester = new websocket_request_handler_1.WebSocketRequestHandler(resilienceHandlerFactory);
return ditto_client_websocket_1.DefaultDittoWebSocketClient.getInstance(new websocket_request_sender_1.WebSocketRequestSenderFactory(this.apiVersion, this.channel, requester), requester, this.customHandles);
}
buildClient(tls, domain, apiVersion, stateHandler, channel, authProviders) {
this.tls = tls;
this.domain = domain;
this.apiVersion = apiVersion;
this.stateHandler = stateHandler;
this.channel = channel;
this.resilienceFactory = websocket_resilience_handler_bufferless_1.BufferlessResilienceHandlerFactory.getInstance();
this.authProviders = authProviders;
return this.build();
}
}
exports.WebSocketClientBuilder = WebSocketClientBuilder;
//# sourceMappingURL=websocket-client-builder.js.map