Skip to main content
Home

Built and signed on GitHub Actions

MQTT Server and Client on Deno, NodeJS and Bun

This package works with Node.js, Deno, BunIt is unknown whether this package works with Cloudflare Workers, Browsers
It is unknown whether this package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
It is unknown whether this package works with Browsers
JSR Score
100%
Published
2 months ago (1.11.2)
class Client

The Client class provides an MQTT Client that can be used to connect to a MQTT broker and publish/subscribe messages.

The Client class is not meant to be used directly, but instead should be subclassed and the subclass should override the createConn() method to provide a connection type that is supported by the subclass.

Constructors

new
Client()

Creates a new MQTT client instance

Properties

onConnected: () => void
onDisconnected: () => void
onError: (err: Error) => void
onPacket: (pkt: PublishPacket) => void | Promise<void>
onReconnecting: () => void
protected
keepAlive
protected
protocolLevel
protected
url: URL
private
optional
caCerts: string[]
private
optional
cert: string
private
optional
connectPacket: ConnectPacket
readonly
connectionState: TConnectionState
private
ctx: Context
private
optional
key: string

Methods

connect(params?: ConnectParameters): Promise<TAuthenticationResult>

Connects to the MQTT broker

protected
createConn(
protocol: string,
_hostname: string,
_port?: number,
_caCerts?: string[],
_cert?: string,
_key?: string,
): Promise<SockConn>

Creates a new connection to the MQTT broker

Disconnects from the MQTT broker

private
doConnect(): Promise<void>

Handles the connection process including retries and reconnection

messages(): AsyncIterable<PublishPacket>

Gets an async iterator for received messages

Publishes a message to the MQTT broker

Subscribes to topics on the MQTT broker

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@seriousme/opifex

Import symbol

import { Client } from "@seriousme/opifex/client";
or

Import directly with a jsr specifier

import { Client } from "jsr:@seriousme/opifex/client";

Add Package

pnpm i jsr:@seriousme/opifex
or (using pnpm 10.8 or older)
pnpm dlx jsr add @seriousme/opifex

Import symbol

import { Client } from "@seriousme/opifex/client";

Add Package

yarn add jsr:@seriousme/opifex
or (using Yarn 4.8 or older)
yarn dlx jsr add @seriousme/opifex

Import symbol

import { Client } from "@seriousme/opifex/client";

Add Package

vlt install jsr:@seriousme/opifex

Import symbol

import { Client } from "@seriousme/opifex/client";

Add Package

npx jsr add @seriousme/opifex

Import symbol

import { Client } from "@seriousme/opifex/client";

Add Package

bunx jsr add @seriousme/opifex

Import symbol

import { Client } from "@seriousme/opifex/client";