Skip to content
Snippets Groups Projects
Commit 4b15ac47 authored by Marin Karamihalev's avatar Marin Karamihalev
Browse files

added cleanSession option, defaults to false, set clientId to fromId

parent 61cf7adb
Branches client-d
No related tags found
No related merge requests found
Pipeline #119000 passed
{ {
"name": "usp-js", "name": "usp-js",
"version": "0.4.7", "version": "0.4.8",
"description": "Library for easy usp(TR-369) communication using mqtt or ws.", "description": "Library for easy usp(TR-369) communication using mqtt or ws.",
"main": "node/index.js", "main": "node/index.js",
"browser": "web/index.js", "browser": "web/index.js",
......
...@@ -16,8 +16,15 @@ import { jsonRoots } from "./util"; ...@@ -16,8 +16,15 @@ import { jsonRoots } from "./util";
export const isURL = (opts: ConnectionOptions): opts is URLConnectionOptions => export const isURL = (opts: ConnectionOptions): opts is URLConnectionOptions =>
"url" in opts; "url" in opts;
export const connectClient: ConnectClientFn = async (opts) => const correctOptions = (opts: ConnectionOptions): ConnectionOptions => ({
isURL(opts) ...opts,
clientId: opts.clientId || opts.fromId,
clean: opts.cleanSession ?? false,
});
export const connectClient: ConnectClientFn = async (initialOpts) => {
const opts = correctOptions(initialOpts);
return isURL(opts)
? (mqttAsync.connectAsync( ? (mqttAsync.connectAsync(
opts.url, opts.url,
opts as any opts as any
...@@ -31,6 +38,7 @@ export const connectClient: ConnectClientFn = async (opts) => ...@@ -31,6 +38,7 @@ export const connectClient: ConnectClientFn = async (opts) =>
: {}), : {}),
} as any) as unknown as ConnectionClient) } as any) as unknown as ConnectionClient)
: (mqttAsync.connectAsync(opts) as unknown as ConnectionClient); : (mqttAsync.connectAsync(opts) as unknown as ConnectionClient);
};
export const loadProtobuf = async (version: USPVersion): Promise<Proto> => { export const loadProtobuf = async (version: USPVersion): Promise<Proto> => {
const [rootRecordJson, rootMsgJson] = jsonRoots[version]; const [rootRecordJson, rootMsgJson] = jsonRoots[version];
......
...@@ -765,6 +765,10 @@ export interface MainConnectionOptions { ...@@ -765,6 +765,10 @@ export interface MainConnectionOptions {
*/ */
connectTimeout?: number; connectTimeout?: number;
clientId?: string; clientId?: string;
/**
* Defaults to false
*/
cleanSession?: boolean;
/** /**
* Allows passing additional options to the underlying connection library * Allows passing additional options to the underlying connection library
*/ */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment