{"id":49512,"library":"think-websocket","title":"ThinkJS WebSocket Extension","description":"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.","status":"maintenance","version":"1.0.8","language":"javascript","source_language":"en","source_url":"https://github.com/thinkjs/think-websocket","tags":["javascript","typescript"],"install":[{"cmd":"npm install think-websocket","lang":"bash","label":"npm"},{"cmd":"yarn add think-websocket","lang":"bash","label":"yarn"},{"cmd":"pnpm add think-websocket","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"CommonJS require style; the module is not ESM-compatible.","symbol":"think-websocket","correct":"const websocket = require('think-websocket');"},{"note":"The module exports a function directly, not a default export. Do not use .default.","wrong":"const websocket = require('think-websocket').default;","symbol":"default export (websocket function)","correct":"const websocket = require('think-websocket'); exports[websocket(think.app)];"},{"note":"Works with TypeScript's esModuleInterop; but the module is CommonJS.","symbol":"TypeScript import (type)","correct":"import * as websocket from 'think-websocket';"}],"quickstart":{"code":"// src/config/extend.js\nconst websocket = require('think-websocket');\nmodule.exports = [\n  websocket(think.app)\n];\n\n// In controller\nmodule.exports = class extends think.Controller {\n  openAction() {\n    this.websocket.send('connected');\n  }\n  closeAction() {\n    console.log('client disconnected');\n  }\n  messageAction() {\n    const msg = this.websocket.data;\n    console.log('received:', msg);\n    this.websocket.send('echo: ' + msg);\n  }\n};","lang":"javascript","description":"Configures the WebSocket extension in ThinkJS and shows basic open/close/message event handling in a controller."},"warnings":[{"fix":"Evaluate migration to ThinkJS 4 or use a standalone WebSocket library like ws.","message":"ThinkJS 3.x is in maintenance mode; consider upgrading to ThinkJS 4+ or an alternative framework.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Ensure you pass think.app: websocket(think.app)","message":"The module must be called as a function with think.app argument; forgetting this causes runtime errors.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Do not try to import/use this package outside of ThinkJS.","message":"This package is not a standalone WebSocket library; it only works within ThinkJS 3.x applications.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'1.0.8':15 '3':8 '6.0.0':67 'access':54 'app':51 'cadenc':23 'capabl':28 'close':36 'configur':58 'control':31 'coupl':47 'current':11 'definit':63 'error':39 'event':33 'extens':3,5 'framework':10 'integr':25 'javascript':68 'librari':43 'lifecycl':52 'like':34 'low':21 'mainten':18 'messag':37 'node.js':66 'open':35 'packag':60 'releas':22 'requir':53,65 'server':27 'ship':61 'stabl':12 'standalon':41 'status':19 'support':32 'think.app':56 'thinkj':1,7,30,49 'tight':46 'typescript':62,69 'unlik':40 'version':13 'websocket':2,4,26,42 'x':9","created_at":"2026-06-07T17:02:08.798677+00:00","updated_at":"2026-06-07T17:02:08.798677+00:00","problems":[{"fix":"const websocket = require('think-websocket');\nmodule.exports = [\n  websocket(think.app)\n];","cause":"Forgetting to call websocket(think.app) or importing incorrectly.","error":"TypeError: websocket is not a function"},{"fix":"Only use this in ThinkJS config files where think is globally available.","cause":"Using think.app outside of a ThinkJS context.","error":"ReferenceError: think is not defined"},{"fix":"Verify that think-websocket is enabled in extend configuration and ThinkJS server is running.","cause":"The WebSocket server is not started or misconfigured.","error":"WebSocket connection to 'ws://...' failed"}],"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":"https://github.com/thinkjs/think-websocket#readme","github":"https://github.com/thinkjs/think-websocket","docs":null,"changelog":null,"pypi":null,"npm":"think-websocket","openapi_spec":null,"status_page":null,"smithery":null,"categories":["messaging"],"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}}