Skip to content

Commit b1cb699

Browse files
committed
update mqtt5 client options
1 parent 31c2f13 commit b1cb699

3 files changed

Lines changed: 78 additions & 111 deletions

File tree

lib/browser/mqtt5.ts

Lines changed: 4 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import * as auth from "./auth";
2525

2626
export * from "../common/mqtt5";
2727
export * from '../common/mqtt5_packet';
28+
export { Mqtt5ClientConfigBase } from "../common/mqtt_shared";
2829

2930
/**
3031
* Factory function that allows the user to completely control the url used to form the websocket handshake
@@ -124,66 +125,16 @@ export interface Mqtt5WebsocketConfig {
124125
/**
125126
* Configuration options for mqtt5 client creation.
126127
*/
127-
export interface Mqtt5ClientConfig {
128-
129-
/**
130-
* Host name of the MQTT server to connect to.
131-
*/
132-
hostName: string;
133-
134-
/**
135-
* Network port of the MQTT server to connect to.
136-
*/
137-
port: number;
138-
139-
/**
140-
* Controls how the MQTT5 client should behave with respect to MQTT sessions.
141-
*/
142-
sessionBehavior? : mqtt5.ClientSessionBehavior;
143-
144-
/**
145-
* Controls how the reconnect delay is modified in order to smooth out the distribution of reconnection attempt
146-
* timepoints for a large set of reconnecting clients.
147-
*/
148-
retryJitterMode? : mqtt5.RetryJitterType;
149-
150-
/**
151-
* Minimum amount of time to wait to reconnect after a disconnect. Exponential backoff is performed with jitter
152-
* after each connection failure.
153-
*/
154-
minReconnectDelayMs? : number;
155-
156-
/**
157-
* Maximum amount of time to wait to reconnect after a disconnect. Exponential backoff is performed with jitter
158-
* after each connection failure.
159-
*/
160-
maxReconnectDelayMs? : number;
161-
162-
/**
163-
* Amount of time that must elapse with an established connection before the reconnect delay is reset to the minimum.
164-
* This helps alleviate bandwidth-waste in fast reconnect cycles due to permission failures on operations.
165-
*/
166-
minConnectedTimeToResetReconnectDelayMs? : number;
167-
168-
/**
169-
* All configurable options with respect to the CONNECT packet sent by the client, including the will. These
170-
* connect properties will be used for every connection attempt made by the client.
171-
*/
172-
connectProperties?: mqtt5_packet.ConnectPacket;
128+
export interface Mqtt5ClientConfig extends mqtt_shared.Mqtt5ClientConfigBase {
173129

174130
/**
175131
* Overall time interval to wait to establish an MQTT connection. If a complete MQTT connection (from socket
176132
* establishment all the way up to CONNACK receipt) has not been established before this timeout expires,
177133
* the connection attempt will be considered a failure.
178-
*/
179-
connectTimeoutMs? : number;
180-
181-
/**
182-
* Additional controls for client behavior with respect to topic alias usage.
183134
*
184-
* If this setting is left undefined, then topic aliasing behavior will be disabled.
135+
* @group Browser-only
185136
*/
186-
topicAliasingOptions? : mqtt5.TopicAliasingOptions
137+
connectTimeoutMs? : number;
187138

188139
/**
189140
* Options for the underlying websocket connection

lib/common/mqtt_shared.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
import { MqttWill } from './mqtt';
1111
import * as event from "./event";
12+
import * as mqtt5 from "./mqtt5";
13+
import * as mqtt5_packet from "./mqtt5_packet";
1214

1315

1416
/**
@@ -343,3 +345,67 @@ export class PublishAcknowledgementHandle {
343345
}
344346
}
345347
}
348+
349+
/**
350+
* Base configuration options shared by all MQTT5 clients.
351+
*
352+
* This interface contains the common configuration properties used by both
353+
* browser and native MQTT5 client implementations. Platform-specific implementations
354+
* extend this interface with additional properties.
355+
*
356+
* @category MQTT5
357+
*/
358+
export interface Mqtt5ClientConfigBase {
359+
360+
/**
361+
* Host name of the MQTT server to connect to.
362+
*/
363+
hostName: string;
364+
365+
/**
366+
* Network port of the MQTT server to connect to.
367+
*/
368+
port: number;
369+
370+
/**
371+
* Controls how the MQTT5 client should behave with respect to MQTT sessions.
372+
*/
373+
sessionBehavior? : mqtt5.ClientSessionBehavior;
374+
375+
/**
376+
* Controls how the reconnect delay is modified in order to smooth out the distribution of reconnection attempt
377+
* timepoints for a large set of reconnecting clients.
378+
*/
379+
retryJitterMode? : mqtt5.RetryJitterType;
380+
381+
/**
382+
* Minimum amount of time to wait to reconnect after a disconnect. Exponential backoff is performed with jitter
383+
* after each connection failure.
384+
*/
385+
minReconnectDelayMs? : number;
386+
387+
/**
388+
* Maximum amount of time to wait to reconnect after a disconnect. Exponential backoff is performed with jitter
389+
* after each connection failure.
390+
*/
391+
maxReconnectDelayMs? : number;
392+
393+
/**
394+
* Amount of time that must elapse with an established connection before the reconnect delay is reset to the minimum.
395+
* This helps alleviate bandwidth-waste in fast reconnect cycles due to permission failures on operations.
396+
*/
397+
minConnectedTimeToResetReconnectDelayMs? : number;
398+
399+
/**
400+
* All configurable options with respect to the CONNECT packet sent by the client, including the will. These
401+
* connect properties will be used for every connection attempt made by the client.
402+
*/
403+
connectProperties?: mqtt5_packet.ConnectPacket;
404+
405+
/**
406+
* Additional controls for client behavior with respect to topic alias usage.
407+
*
408+
* If this setting is left undefined, then topic aliasing behavior will be disabled.
409+
*/
410+
topicAliasingOptions? : mqtt5.TopicAliasingOptions;
411+
}

lib/native/mqtt5.ts

Lines changed: 8 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {CrtError} from "./error";
2525
export { HttpProxyOptions } from './http';
2626
export * from "../common/mqtt5";
2727
export * from '../common/mqtt5_packet';
28+
export { Mqtt5ClientConfigBase } from "../common/mqtt_shared";
2829

2930
/**
3031
* Websocket handshake http request transformation function signature
@@ -123,59 +124,16 @@ export enum ClientExtendedValidationAndFlowControl {
123124
/**
124125
* Configuration options for mqtt5 client creation.
125126
*/
126-
export interface Mqtt5ClientConfig {
127-
128-
/**
129-
* Host name of the MQTT server to connect to.
130-
*/
131-
hostName: string;
132-
133-
/**
134-
* Network port of the MQTT server to connect to.
135-
*/
136-
port: number;
137-
138-
/**
139-
* Controls how the MQTT5 client should behave with respect to MQTT sessions.
140-
*/
141-
sessionBehavior? : mqtt5.ClientSessionBehavior;
142-
143-
/**
144-
* Controls how the reconnect delay is modified in order to smooth out the distribution of reconnection attempt
145-
* timepoints for a large set of reconnecting clients.
146-
*/
147-
retryJitterMode? : mqtt5.RetryJitterType;
148-
149-
/**
150-
* Minimum amount of time to wait to reconnect after a disconnect. Exponential backoff is performed with jitter
151-
* after each connection failure.
152-
*/
153-
minReconnectDelayMs? : number;
154-
155-
/**
156-
* Maximum amount of time to wait to reconnect after a disconnect. Exponential backoff is performed with jitter
157-
* after each connection failure.
158-
*/
159-
maxReconnectDelayMs? : number;
160-
161-
/**
162-
* Amount of time that must elapse with an established connection before the reconnect delay is reset to the minimum.
163-
* This helps alleviate bandwidth-waste in fast reconnect cycles due to permission failures on operations.
164-
*/
165-
minConnectedTimeToResetReconnectDelayMs? : number;
127+
export interface Mqtt5ClientConfig extends mqtt_shared.Mqtt5ClientConfigBase {
166128

167129
/**
168130
* Time interval to wait after sending a CONNECT request for a CONNACK to arrive. If one does not arrive, the
169131
* connection will be shut down.
132+
*
133+
* @group Node-only
170134
*/
171135
connackTimeoutMs? : number;
172136

173-
/**
174-
* All configurable options with respect to the CONNECT packet sent by the client, including the will. These
175-
* connect properties will be used for every connection attempt made by the client.
176-
*/
177-
connectProperties?: mqtt5_packet.ConnectPacket;
178-
179137
/**
180138
* Controls how disconnects affect the queued and in-progress operations tracked by the client. Also controls
181139
* how new operations are handled while the client is not connected. In particular, if the client is not connected,
@@ -201,13 +159,6 @@ export interface Mqtt5ClientConfig {
201159
*/
202160
ackTimeoutSeconds? : number;
203161

204-
/**
205-
* Additional controls for client behavior with respect to topic alias usage.
206-
*
207-
* If this setting is left undefined, then topic aliasing behavior will be disabled.
208-
*/
209-
topicAliasingOptions? : mqtt5.TopicAliasingOptions
210-
211162
/**
212163
* Client bootstrap to use. In almost all cases, this can be left undefined.
213164
*
@@ -256,13 +207,12 @@ export interface Mqtt5ClientConfig {
256207
*/
257208
extendedValidationAndFlowControlOptions? : ClientExtendedValidationAndFlowControl;
258209

259-
260210
/**
261-
* Options for enable/disable Aws IoT Metrics. The metrics includes SDK name, version, and platform.
262-
*
211+
* Options for disable Aws IoT Metrics. The metrics includes SDK name, version, and platform.
212+
*
263213
* @group Node-only
264214
*/
265-
enableMetrics? : boolean
215+
disableMetrics? : boolean;
266216
}
267217

268218
/**
@@ -300,7 +250,7 @@ export class Mqtt5Client extends NativeResourceMixin(BufferedEventEmitter) imple
300250
config.socketOptions ? config.socketOptions.native_handle() : null,
301251
config.tlsCtx ? config.tlsCtx.native_handle() : null,
302252
config.httpProxyOptions ? config.httpProxyOptions.create_native_handle() : null,
303-
config.enableMetrics == false ? undefined : new mqtt_shared.AwsIoTDeviceSDKMetrics()
253+
config.disableMetrics == true ? undefined : new mqtt_shared.AwsIoTDeviceSDKMetrics()
304254
));
305255
}
306256

0 commit comments

Comments
 (0)