UNPKG

@nixjs23n6/grpc-socket-core

Version:

gRPC for Web Clients.

57 lines 1.78 kB
import { WSClient } from "./WSClient"; export class WSClientBuilder { constructor(baseURL, path) { this._ws = null; this._logger = {}; this._baseURL = baseURL; this._path = path; } addProtocols(p) { this._protocols = p; return this; } addBackOff(b) { this._backOff = b; return this; } addProtoConfigParameters(p) { this._protoConfigParameters = p; return this; } addExecuteAnyFunc(exe) { if (typeof exe === "function") this._executeAnyFunc = exe; return this; } addLogger(logger) { this._logger.debug = (logger && logger.debug) || false; this._logger.namespace = (logger && logger.namespace) || "[Socket]"; this._logger.color = (logger && logger.color) || "#D3DEDC"; } /** * Create WSClient instance */ init() { if (this._ws !== null) return this; this._ws = new WSClient(this._baseURL, this._protocols, this._path, this._backOff, this._protoConfigParameters, this._executeAnyFunc, this._logger); return this; } /** * Connect socket and allow override the parameters WSClient * @param path * @param protocols * @param protoConfigParameters * @param executeAnyFunc */ build({ protocols, protoConfigParameters, path, executeAnyFunc, executeState, }) { if (!this._ws) return null; this._ws .connect(path, protocols, protoConfigParameters, executeAnyFunc) .then((state) => executeState && executeState(state)) .catch((state) => executeState && executeState(state)); return this._ws; } } //# sourceMappingURL=WSClientBuilder.js.map