{"id":49562,"library":"tuya-ws","title":"Tuya WebSocket SDK","description":"0.0.1 - Client library for subscribing to Tuya IoT platform messages via WebSocket, wrapping Pulsar message consumption. Provides event-driven callbacks for open, message, reconnect, ping, pong, close, and error events. Supports automatic reconnection, ack-based message handling, and multiple environments (CN, US, EU). Requires an access ID and key. Not for production due to early version; lacks documentation on error handling and security.","status":"active","version":"0.0.1","language":"javascript","source_language":"en","source_url":null,"tags":["javascript","tuya","message","subscription","websocket","typescript"],"install":[{"cmd":"npm install tuya-ws","lang":"bash","label":"npm"},{"cmd":"yarn add tuya-ws","lang":"bash","label":"yarn"},{"cmd":"pnpm add tuya-ws","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM-only package; no CJS export.","wrong":"const TuyaWebsocket = require('tuya-ws')","symbol":"TuyaWebsocket","correct":"import TuyaWebsocket from 'tuya-ws'"},{"note":"The package exports a single default class, not named.","wrong":"import { TuyaWebsocket } from 'tuya-ws'","symbol":"default export","correct":"import TuyaWebsocket from 'tuya-ws'"},{"note":"Access static properties on the class, not an instance.","wrong":"tuyaWs.URL.CN","symbol":"URL and env constants","correct":"TuyaWebsocket.URL.CN"}],"quickstart":{"code":"import TuyaWebsocket from 'tuya-ws';\n\nconst client = new TuyaWebsocket({\n  accessId: process.env.TUYA_ACCESS_ID ?? '',\n  accessKey: process.env.TUYA_ACCESS_KEY ?? '',\n  url: TuyaWebsocket.URL.CN,\n  env: TuyaWebsocket.env.PROD,\n  maxRetryTimes: 100,\n});\n\nclient.open(() => console.log('connected'));\nclient.message((ws, message) => {\n  console.log('received:', message);\n  client.ackMessage(message.messageId);\n});\nclient.error((ws, err) => console.error('error:', err));\nclient.start();","lang":"typescript","description":"Initializes a Tuya WebSocket client with credentials and environment, sets up open, message, and error event handlers, acknowledges received messages, and starts consumption."},"warnings":[{"fix":"Consider locking version in package.json.","message":"The package is version 0.0.1 and may have unstable API or bugs.","severity":"gotcha","affected_versions":"=0.0.1"},{"fix":"Always register event handlers before calling client.start().","message":"Before starting, you must call client.open() or other event setters; otherwise no events fire.","severity":"gotcha","affected_versions":">=0"},{"fix":"Call client.ackMessage(message.messageId) inside the message callback.","message":"ackMessage must be called with the messageId string from the message object, otherwise the server may redeliver messages.","severity":"gotcha","affected_versions":">=0"},{"fix":"Use ^0.0.1 in package.json to allow only patch updates.","message":"Version 0.0.1 is initial and may contain breaking changes in future minor or patch releases.","severity":"breaking","affected_versions":">=0.0.1"}],"env_vars":null,"search_vec":"'0.0.1':4 'access':51 'ack':39 'ack-bas':38 'automat':36 'base':40 'callback':24 'client':5 'close':31 'cn':46 'consumpt':19 'document':63 'driven':23 'due':58 'earli':60 'environ':45 'error':33,65 'eu':48 'event':22,34 'event-driven':21 'handl':42,66 'id':52 'iot':11 'javascript':69 'key':54 'lack':62 'librari':6 'messag':13,18,27,41,71 'multipl':44 'open':26 'ping':29 'platform':12 'pong':30 'product':57 'provid':20 'pulsar':17 'reconnect':28,37 'requir':49 'sdk':3 'secur':68 'subscrib':8 'subscript':72 'support':35 'tuya':1,10,70 'typescript':74 'us':47 'version':61 'via':14 'websocket':2,15,73 'wrap':16","created_at":"2026-06-07T17:02:24.744459+00:00","updated_at":"2026-06-07T17:02:24.744459+00:00","problems":[{"fix":"Run 'yarn add tuya-ws' or 'npm install tuya-ws'.","cause":"Package not installed or missing from node_modules.","error":"Error: Cannot find module 'tuya-ws'"},{"fix":"Use 'import TuyaWebsocket from 'tuya-ws'' and ensure package.json has 'type': 'module'.","cause":"Using CommonJS require() instead of ESM import.","error":"TypeError: TuyaWebsocket is not a constructor"},{"fix":"Add 'accessId: process.env.TUYA_ACCESS_ID ?? '' ' to constructor options.","cause":"Missing accessId in options object.","error":"Error: accessId is required"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":null,"github":null,"docs":null,"changelog":null,"pypi":null,"npm":"tuya-ws","openapi_spec":null,"status_page":null,"smithery":null,"categories":["iot"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}