3.0.8 • Published 2 years ago

@openrc/react-native-mqtt v3.0.8

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

English    

这是一个支持 react-native 的极简 mqtt 协议库, , 与MQTT保持同步, 支持Emqmosquitto

安装

npm i --save @openrc/react-native-mqtt
yarn add @openrc/react-native-mqtt

用法(websocket)

import MQTT from '@openrc/react-native-mqtt';

const client = MQTT.connect('ws://car.openrc.top/mqtt', {
  port: 8083,
  protocol: 'ws',
  username: 'your username',
  password: 'your password',
  reconnectPeriod: 30 * 1000,
  qos: 2,
});

client.on('closed', function () {
  console.log('mqtt event closed');
});

client.on('error', function (msg) {
  console.log('mqtt event error', msg);
});

client.on('connect', function () {
  console.log('connected mqtt');
});

export default client;

API

  • mqtt.connect()
  • mqtt.Client()
  • mqtt.Client#publish()
  • mqtt.Client#subscribe()
  • mqtt.Client#unsubscribe()
  • mqtt.Client#end()
  • mqtt.Client#removeOutgoingMessage()
  • mqtt.Client#reconnect()
  • mqtt.Client#handleMessage()
  • mqtt.Client#connected
  • mqtt.Client#reconnecting
  • mqtt.Client#getLastMessageId()
  • mqtt.Store()
  • mqtt.Store#put()
  • mqtt.Store#del()
  • mqtt.Store#createStream()
  • mqtt.Store#close()

了解更多

License

MIT