Registry / iot / tuya-ws

tuya-ws

JSON →
library0.0.1jsnpmunverified

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.

npm install tuya-ws
INSTALL
IMPORT
SIG · TUYA-WS
T
tuya-ws
iotjavascriptv0.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

TuyaWebsocket
import TuyaWebsocket from 'tuya-ws'
const TuyaWebsocket = require('tuya-ws')
ESM-only package; no CJS export.
default export
import TuyaWebsocket from 'tuya-ws'
import { TuyaWebsocket } from 'tuya-ws'
The package exports a single default class, not named.
URL and env constants
TuyaWebsocket.URL.CN
tuyaWs.URL.CN
Access static properties on the class, not an instance.

Initializes a Tuya WebSocket client with credentials and environment, sets up open, message, and error event handlers, acknowledges received messages, and starts consumption.

import TuyaWebsocket from 'tuya-ws'; const client = new TuyaWebsocket({ accessId: process.env.TUYA_ACCESS_ID ?? '', accessKey: process.env.TUYA_ACCESS_KEY ?? '', url: TuyaWebsocket.URL.CN, env: TuyaWebsocket.env.PROD, maxRetryTimes: 100, }); client.open(() => console.log('connected')); client.message((ws, message) => { console.log('received:', message); client.ackMessage(message.messageId); }); client.error((ws, err) => console.error('error:', err)); client.start();
Debug
Known issues
gotchaThe package is version 0.0.1 and may have unstable API or bugs.
fix
Consider locking version in package.json.
affects: =0.0.1
gotchaBefore starting, you must call client.open() or other event setters; otherwise no events fire.
fix
Always register event handlers before calling client.start().
affects: >=0
gotchaackMessage must be called with the messageId string from the message object, otherwise the server may redeliver messages.
fix
Call client.ackMessage(message.messageId) inside the message callback.
affects: >=0
breakingVersion 0.0.1 is initial and may contain breaking changes in future minor or patch releases.
fix
Use ^0.0.1 in package.json to allow only patch updates.
affects: >=0.0.1
Errors
Common errors & fixes
Error: Cannot find module 'tuya-ws'
Package not installed or missing from node_modules.
fix
Run 'yarn add tuya-ws' or 'npm install tuya-ws'.
TypeError: TuyaWebsocket is not a constructor
Using CommonJS require() instead of ESM import.
fix
Use 'import TuyaWebsocket from 'tuya-ws'' and ensure package.json has 'type': 'module'.
Error: accessId is required
Missing accessId in options object.
fix
Add 'accessId: process.env.TUYA_ACCESS_ID ?? '' ' to constructor options.
Upgrade
Version history
0.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
26 hits · last 30 days
node
22
OpenAI (training)
1
Resources
tuya-ws — npm install tuya-ws · libregistry