Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions client/base_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ export type ClientOptions = {
incomingStore?: IncomingStore;
outgoingStore?: OutgoingStore;
logger?: (msg: string, ...args: unknown[]) => void;
/** Path to the ca.crt files */
caCerts?: string[];
/** Content of the client.crt file */
certChain?: string;
/** Content of the client.key file */
privateKey?: string;
};

export type RetryOptions = {
Expand Down Expand Up @@ -253,7 +259,10 @@ export abstract class Client {
}

public async connect(): Promise<ConnackPacket> {
await this.disconnect();
switch (this.connectionState) {
case 'connecting':
case 'disconnecting':
case 'offline':
case 'disconnected':
break;
Expand Down Expand Up @@ -364,6 +373,7 @@ export abstract class Client {
input: SubscriptionOption | string | (SubscriptionOption | string)[],
qos?: QoS
): Promise<Subscription[]> {
await this.connect();
switch (this.connectionState) {
case 'disconnecting':
case 'disconnected':
Expand Down Expand Up @@ -566,6 +576,8 @@ export abstract class Client {
this.changeState('disconnected');
this.stopTimers();
break;
case 'disconnected':
break;
default:
throw new Error(
`should not be disconnecting in ${this.connectionState} state`
Expand Down
15 changes: 5 additions & 10 deletions deno/deno_client.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
import {
Client as BaseClient,
ClientOptions as BaseClientOptions,
ClientOptions,
} from '../client/base_client.ts';
import { AnyPacket } from '../packets/mod.ts';

export type ClientOptions = BaseClientOptions & {
certFile?: string;
};

const DEFAULT_BUF_SIZE = 4096;

const utf8Encoder = new TextEncoder();
const utf8Decoder = new TextDecoder();

export class Client extends BaseClient {
declare options: ClientOptions;
private conn: Deno.Conn | undefined;
private closing = false;

Expand Down Expand Up @@ -43,13 +38,13 @@ export class Client extends BaseClient {
port: Number(url.port),
});
} else if (url.protocol === 'mqtts:') {
// console.log(this.options.certFile);

conn = await Deno.connectTls({
hostname: url.hostname,
port: Number(url.port),
certFile: this.options.certFile,
});
caCerts: this.options?.caCerts,
certChain: this.options?.certChain,
privateKey: this.options?.privateKey
} as any);
} else {
throw new Error(`unknown URL protocol ${url.protocol.slice(0, -1)}`);
}
Expand Down