はじめに
セットアップのプロンプトをコピーして、インストールの手順とこのプラグインのフルマークダウンガイドを含む。
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-mqtt`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/mqtt/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
インストール
「インストール」のセクションbun add @capgo/capacitor-mqttbunx cap syncimport { MqttBridge } from '@capgo/capacitor-mqtt';API の概要
Section titled “API の概要”connect
Section titled “接続”現在の契約のソース定義を参照してください。
import { MqttBridge } from '@capgo/capacitor-mqtt';
await MqttBridge.connect({} as { serverURI: string; port: number; clientId: string; username: string; password: string; setCleanSession: boolean; connectionTimeout: number; keepAliveInterval: number; setAutomaticReconnect: boolean; setLastWill?: { willTopic: string; willPayload: string; willQoS: number; setRetained: boolean; }; });disconnect
Section titled “切断”現在の契約のソース定義を参照してください。
import { MqttBridge } from '@capgo/capacitor-mqtt';
await MqttBridge.disconnect();subscribe
Section titled “サブスクライブ”現在の契約のソース定義を参照してください。
import { MqttBridge } from '@capgo/capacitor-mqtt';
await MqttBridge.subscribe({} as { topic: string; qos: number });publish
「公開」セクション現在の契約のソース定義を参照してください。
import { MqttBridge } from '@capgo/capacitor-mqtt';
await MqttBridge.publish({} as { topic: string; payload: string; qos: number; retained: boolean });型参照
「型参照」セクションonConnectionLostListener
「onConnectionLostListener」セクションexport type onConnectionLostListener = (x: { connectionStatus: string; reasonCode: number; message: string }) => void;onConnectCompleteListener
「onConnectCompleteListener」セクションexport type onConnectCompleteListener = (x: { reconnected: boolean; serverURI: string }) => void;onMessageArrivedListener
「onMessageArrivedListener」セクションexport type onMessageArrivedListener = (x: { topic: string; message: string }) => void;真実の源
「真実の源」と題されたセクションこのページはプラグインの src/definitions.ts公開 API がアップストリームで変更された場合に再度同期を実行してください。