message-subscription-websocket
v1.0.2
Published
tuya message subscription websocket
Downloads
3
Maintainers
Readme
Connector to Tuya's Messaging Service using the Node.js SDK from Tuya
Environment
- Nodejs >= 12.0
- yarn
Start
- Install
yarn
- Build
yarn build
- Publish
yarn deploy
Run example
- Install
yarn
- Config your accessId and accessKey in
example/index.js
const client = new TuyaWebsocket({
accessId: "your accessId",
accessKey: "your accessKey",
url: TuyaWebsocket.URL.CN,
env: TuyaWebsocket.env.PROD,
maxRetryTimes: 100,
});
- Start
yarn example
Example code
import TuyaWebsocket from "xxx";
const client = new TuyaWebsocket({
accessId: "your accessId",
accessKey: "your accessKey",
url: TuyaWebsocket.URL.CN,
env: TuyaWebsocket.env.PROD,
maxRetryTimes: 100,
});
client.open(() => {
console.log('open');
});
client.message((ws, message) => {
client.ackMessage(message.messageId);
console.log('message', message);
});
client.reconnect(() => {
console.log('reconnect');
});
client.ping(() => {
console.log('ping');
});
client.pong(() => {
console.log('pong');
});
client.close((ws, ...args) => {
console.log('close', ...args);
});
client.error((ws, error) => {
console.log('error', error);
});
client.start()