Registry / messaging / think-websocket

think-websocket

JSON →
library1.0.8jsnpmunverified

WebSocket extension for ThinkJS 3.x framework. Current stable version is 1.0.8, with a maintenance status and low release cadence. It integrates WebSocket server capabilities into ThinkJS controllers, supporting events like open, close, message, and error. Unlike standalone WebSocket libraries, this is tightly coupled with ThinkJS's app lifecycle, requiring access to think.app during configuration. The package ships TypeScript definitions and requires Node.js >= 6.0.0.

npm install think-websocket
INSTALL
IMPORT
SIG · THINK-WEBSOCKET
T
think-websocket
messagingjavascriptv1.0.8
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.

think-websocket
const websocket = require('think-websocket');
CommonJS require style; the module is not ESM-compatible.
default export (websocket function)
const websocket = require('think-websocket'); exports[websocket(think.app)];
const websocket = require('think-websocket').default;
The module exports a function directly, not a default export. Do not use .default.
TypeScript import (type)
import * as websocket from 'think-websocket';
Works with TypeScript's esModuleInterop; but the module is CommonJS.

Configures the WebSocket extension in ThinkJS and shows basic open/close/message event handling in a controller.

// src/config/extend.js const websocket = require('think-websocket'); module.exports = [ websocket(think.app) ]; // In controller module.exports = class extends think.Controller { openAction() { this.websocket.send('connected'); } closeAction() { console.log('client disconnected'); } messageAction() { const msg = this.websocket.data; console.log('received:', msg); this.websocket.send('echo: ' + msg); } };
Debug
Known issues
deprecatedThinkJS 3.x is in maintenance mode; consider upgrading to ThinkJS 4+ or an alternative framework.
fix
Evaluate migration to ThinkJS 4 or use a standalone WebSocket library like ws.
affects: >=1.0.0
gotchaThe module must be called as a function with think.app argument; forgetting this causes runtime errors.
fix
Ensure you pass think.app: websocket(think.app)
affects: >=1.0.0
gotchaThis package is not a standalone WebSocket library; it only works within ThinkJS 3.x applications.
fix
Do not try to import/use this package outside of ThinkJS.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: websocket is not a function
Forgetting to call websocket(think.app) or importing incorrectly.
fix
const websocket = require('think-websocket');
module.exports = [
  websocket(think.app)
];
ReferenceError: think is not defined
Using think.app outside of a ThinkJS context.
fix
Only use this in ThinkJS config files where think is globally available.
WebSocket connection to 'ws://...' failed
The WebSocket server is not started or misconfigured.
fix
Verify that think-websocket is enabled in extend configuration and ThinkJS server is running.
Upgrade
Version history
1.0.8latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
25 hits · last 30 days
node
24
OpenAI (training)
1
Resources
think-websocket — npm install think-websocket · libregistry