{"id":15493287,"url":"https://github.com/ko-devhong/react-native-mqtt","last_synced_at":"2025-04-22T19:48:31.561Z","repository":{"id":233760818,"uuid":"787829017","full_name":"ko-devHong/react-native-mqtt","owner":"ko-devHong","description":null,"archived":false,"fork":false,"pushed_at":"2024-07-05T12:26:29.000Z","size":1621,"stargazers_count":7,"open_issues_count":2,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-22T16:41:49.361Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ko-devHong.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-04-17T09:03:24.000Z","updated_at":"2024-11-09T12:31:38.000Z","dependencies_parsed_at":"2024-04-22T02:54:08.435Z","dependency_job_id":"8e9f4346-d91b-4107-b09b-9a80cc6701d6","html_url":"https://github.com/ko-devHong/react-native-mqtt","commit_stats":{"total_commits":54,"total_committers":1,"mean_commits":54.0,"dds":0.0,"last_synced_commit":"a5f529aa86cb7575ca01a0a3671c35f0cd4ece6e"},"previous_names":["ko-devhong/react-native-mqtt"],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ko-devHong%2Freact-native-mqtt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ko-devHong%2Freact-native-mqtt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ko-devHong%2Freact-native-mqtt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ko-devHong%2Freact-native-mqtt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ko-devHong","download_url":"https://codeload.github.com/ko-devHong/react-native-mqtt/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250312712,"owners_count":21410087,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-02T08:05:18.339Z","updated_at":"2025-04-22T19:48:31.515Z","avatar_url":"https://github.com/ko-devHong.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-native-mqtt\n\nThis library is used to communicate with the message broker using the MQTT protocol. This library is available in a React Native environment and supports TypeScript.\n\nThis library uses the following native MQTT client libraries:\n\n\u003e iOS - https://github.com/emqx/CocoaMQTT\n\u003e\n\u003e Android - https://github.com/eclipse/paho.mqtt.android\n\n## Installation\n\nTo use this library, you must first install it using npm or yarn.\n\n```sh\nnpm install @ko-developerhong/react-native-mqtt\n# OR\nyarn add @ko-developerhong/react-native-mqtt\n```\n\n## IOS Setup\nAdd Podfile\n```\npod \"CocoaMQTT\", :modular_headers =\u003e true\npod \"MqttCocoaAsyncSocket\", :modular_headers =\u003e true\n```\n\n## Import\n```ts\nimport MqttClient, { ConnectionOptions, ClientEvent, MQTTEventHandler } from 'react-native-mqtt';\n```\n\n## Connect\nTo connect to the message broker, use the connect method, which takes the host address and connection options as arguments.\n\n```tsx\nimport MqttClient, { ConnectionOptions } from 'react-native-mqtt';\n\nconst options: ConnectionOptions = {\n  clientId: 'myClientId',\n  cleanSession: true,\n  keepAlive: 60,\n  timeout: 60,\n  maxInFlightMessages: 1,\n  autoReconnect: true,\n  username: 'myUsername',\n  password: 'myPassword',\n  tls: {\n    caDer: Buffer.from('myCertificate'),\n    cert: 'myCertificate',\n    key: 'myKey',\n    p12: Buffer.from('myP12'),\n    pass: 'myPass',\n  },\n  allowUntrustedCA: true,\n  enableSsl: true,\n  protocol: 'mqtts',\n};\n\nMqttClient.connect('mqtt://broker.hivemq.com', options)\n  .then(() =\u003e console.log('Connected'))\n  .catch((error) =\u003e console.error('Connection failed: ', error));\n```\n\n## Subscribe\nTo subscribe to a specific topic, use the subscribe method.\n```ts\ntype MQTT = {\n  subscribe: (topic: string, qos?: number) =\u003e void;\n};\n```\n```ts\nMqttClient.subscribe('myTopic', 0);\n```\n\n## Publish a message\nTo publish a message, use the publish method.\n```ts\ntype MQTT = {\n  publish: (topic: string, message: string, qos?: number , retained?: boolean) =\u003e void,\n}\n```\n```ts\nMqttClient.publish('myTopic', 'Hello, World!', 0, false);\n```\n\n## Event Handler\nThis library offers a variety of events. To handle events, use the on, once, and off methods.\n```ts\nconst onConnect: MQTTEventHandler\u003cClientEvent.Connect\u003e = (reconnect) =\u003e {\n  console.log('Connected', reconnect);\n};\n\nMqttClient.on(ClientEvent.Connect, onConnect);\n\nMqttClient.once(ClientEvent.Disconnect, (cause) =\u003e {\n  console.log('Disconnected', cause);\n});\n\nMqttClient.off(ClientEvent.Connect, onConnect);\n```\n\n## Disconnect\nTo disconnect, use the disconnect method.\n```ts\nMqttClient.disconnect();\n```\n\n## Close\nTo close the library, use the close method.\n```ts\nMqttClient.close();\n```\n\n## Troubleshooting\n\u003e The Swift pod `CocoaMQTT` depends upon `MqttCocoaAsyncSocket`, which does not define modules.\n```\nyou may set `use_modular_headers!` globally in your Podfile, or specify `:modular_headers =\u003e true` for particular dependencies.\n```\n\n## Contributing\n\nSee the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.\n\n## NOTE\n\n- This library is available only in React Native environments.\n- This library supports TypeScript.\n- This library is used to communicate with the message broker using the MQTT protocol.\n- This library is based on [react-native-mqtt](https://github.com/davesters/rn-native-mqtt).\n\n\n## License\n\nMIT\n\n---\n\nMade with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)\n\n\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fko-devhong%2Freact-native-mqtt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fko-devhong%2Freact-native-mqtt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fko-devhong%2Freact-native-mqtt/lists"}