MQTT.ts
MQTT.ts copied to clipboard
Support for cafile certificates
The server I use employs MQTTS and uses a certificate file. When I connect using mosquitto_sub
I include the --cafile
flag and pass my certificate file. Is this functionality supported in your tool?
The Deno client supports CAs. The equivalent of --cafile
in Deno is an option called certFile
(see Deno.connectTls) if you're constructing the Deno client in code. I need to work on the docs and add some examples.
Thanks for the reply.
Script throws 17 errors when running, I can't find the solutions in the documentation:
/* deno_sub.js */
import { Client } from 'https://deno.land/x/mqtt/deno/mod.ts'
const CAfile = await Deno.readTextFile('mqtt.crt')
const conf = {
url: 'mqqts://mqtt.coventry.ac.uk',
options: {
host: 'xxx',
port: 8883,
protocol: 'mqtts',
protocolId: 'MQIsdp',
certFile: CAfile,
username: 'xxx',
password: 'xxx',
secureProtocol: 'TLSv1_method',
protocolVersion: 3
}
}
const client = new Client(conf)
await client.connect()
await client.subscribe('iot/#')
client.on('message', (topic, payload) => {
console.log(topic, payload)
})
These are the errors thrown.
$ deno run deno_sub.js
Check file:///home/codio/workspace/deno_sub.js
error: TS1205 [ERROR]: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
ConnectPacket,
~~~~~~~~~~~~~
at https://deno.land/x/[email protected]/packets/mod.ts:37:3
TS1205 [ERROR]: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
ConnackPacket,
~~~~~~~~~~~~~
at https://deno.land/x/[email protected]/packets/mod.ts:38:3
TS1205 [ERROR]: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
PublishPacket,
~~~~~~~~~~~~~
at https://deno.land/x/[email protected]/packets/mod.ts:39:3
TS1205 [ERROR]: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
PubackPacket,
~~~~~~~~~~~~
at https://deno.land/x/[email protected]/packets/mod.ts:40:3
TS1205 [ERROR]: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
PubrecPacket,
~~~~~~~~~~~~
at https://deno.land/x/[email protected]/packets/mod.ts:41:3
TS1205 [ERROR]: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
PubrelPacket,
~~~~~~~~~~~~
at https://deno.land/x/[email protected]/packets/mod.ts:42:3
TS1205 [ERROR]: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
PubcompPacket,
~~~~~~~~~~~~~
at https://deno.land/x/[email protected]/packets/mod.ts:43:3
TS1205 [ERROR]: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
SubscribePacket,
~~~~~~~~~~~~~~~
at https://deno.land/x/[email protected]/packets/mod.ts:44:3
TS1205 [ERROR]: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
SubackPacket,
~~~~~~~~~~~~
at https://deno.land/x/[email protected]/packets/mod.ts:45:3
TS1205 [ERROR]: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
UnsubscribePacket,
~~~~~~~~~~~~~~~~~
at https://deno.land/x/[email protected]/packets/mod.ts:46:3
TS1205 [ERROR]: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
UnsubackPacket,
~~~~~~~~~~~~~~
at https://deno.land/x/[email protected]/packets/mod.ts:47:3
TS1205 [ERROR]: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
PingreqPacket,
~~~~~~~~~~~~~
at https://deno.land/x/[email protected]/packets/mod.ts:48:3
TS1205 [ERROR]: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
PingresPacket,
~~~~~~~~~~~~~
at https://deno.land/x/[email protected]/packets/mod.ts:49:3
TS1205 [ERROR]: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
DisconnectPacket,
~~~~~~~~~~~~~~~~
at https://deno.land/x/[email protected]/packets/mod.ts:50:3
TS1243 [ERROR]: 'async' modifier cannot be used with 'abstract' modifier.
protected abstract async open(url: URL): Promise<void>;
~~~~~
at https://deno.land/x/[email protected]/client/base_client.ts:589:22
TS1243 [ERROR]: 'async' modifier cannot be used with 'abstract' modifier.
protected abstract async write(bytes: Uint8Array): Promise<void>;
~~~~~
at https://deno.land/x/[email protected]/client/base_client.ts:591:22
TS1243 [ERROR]: 'async' modifier cannot be used with 'abstract' modifier.
protected abstract async close(): Promise<void>;
~~~~~
at https://deno.land/x/[email protected]/client/base_client.ts:593:22
Found 17 errors.
It shoud be resolve your issue: #10