NguyenMinhTri / TuyaWebsocket

Home Page:tuya-websocket.vercel.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Nodejs websocket consumer pulsar msg sdk example

Environment

  • Nodejs >= 12.0
  • yarn

Start

  1. Install
yarn
  1. Build
yarn build
  1. Publish
yarn deploy

Run example

  1. Install
yarn
  1. 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,
});
  1. 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() // 开始接收消息

About

tuya-websocket.vercel.app


Languages

Language:TypeScript 53.2%Language:JavaScript 46.6%Language:Shell 0.2%