{"id":49802,"library":"xy-websocket","title":"xy-websocket","description":"Simple protocol for awaitable RPC calls and events over WebSocket connections. Current stable version is 1.14.1, with regular updates. Key differentiators: built-in RPC with automatic promise resolution, event broadcasting to all/single clients, and error handling that passes exceptions across the wire. Supports both server and client usage with a straightforward API. Compared to raw WebSocket or socket.io, it provides a higher-level abstraction for request-response patterns without heavy framework dependencies.","status":"active","version":"1.14.1","language":"javascript","source_language":"en","source_url":"https://github.com/xylogistics/xy-websocket","tags":["javascript"],"install":[{"cmd":"npm install xy-websocket","lang":"bash","label":"npm"},{"cmd":"yarn add xy-websocket","lang":"bash","label":"yarn"},{"cmd":"pnpm add xy-websocket","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM only; package does not support CommonJS require().","wrong":"const { createServer } = require('xy-websocket')","symbol":"createServer","correct":"import { createServer } from 'xy-websocket'"},{"note":"Named export, not default. Use curly braces.","wrong":"import createClient from 'xy-websocket'","symbol":"createClient","correct":"import { createClient } from 'xy-websocket'"},{"note":"Server is a TypeScript type, not a runtime value. Use 'import type' to avoid bundling issues.","wrong":"import { Server } from 'xy-websocket'","symbol":"Server","correct":"import type { Server } from 'xy-websocket'"}],"quickstart":{"code":"import http from 'http';\nimport Koa from 'koa';\nimport { createServer } from 'xy-websocket';\n\nconst app = new Koa();\nconst httpServer = http.createServer(app.callback());\nconst wsServer = createServer({ httpServer });\n\nwsServer.register('greet', async ({ params }) => {\n  return `Hello, ${params.name}!`;\n});\n\nwsServer.broadcast('user_count', { count: wsServer.sockets.length });","lang":"javascript","description":"Creates a WebSocket server using Koa HTTP server, registers an RPC function 'greet', and broadcasts user count."},"warnings":[{"fix":"Use import { createServer } from 'xy-websocket' (curly braces).","message":"The 'createServer' and 'createClient' are named exports, not default exports. Using default import will import 'undefined' instead.","severity":"gotcha","affected_versions":">=1.0"},{"fix":"Use dynamic import() if in a CJS context, or switch to ESM.","message":"The package is ESM-only; it cannot be imported via CommonJS require(). Attempting require() will result in an error.","severity":"gotcha","affected_versions":">=1.0"},{"fix":"Use import type { Server } from 'xy-websocket' for type annotations.","message":"The 'Server' type export is deprecated for runtime use; it should only be used as a TypeScript type.","severity":"deprecated","affected_versions":">=1.10"}],"env_vars":null,"search_vec":"'1.14.1':19 'abstract':69 'across':44 'all/single':36 'api':56 'automat':30 'await':7 'broadcast':34 'built':26 'built-in':25 'call':9 'client':37,51 'compar':57 'connect':14 'current':15 'depend':78 'differenti':24 'error':39 'event':11,33 'except':43 'framework':77 'handl':40 'heavi':76 'higher':67 'higher-level':66 'javascript':79 'key':23 'level':68 'pass':42 'pattern':74 'promis':31 'protocol':5 'provid':64 'raw':59 'regular':21 'request':72 'request-respons':71 'resolut':32 'respons':73 'rpc':8,28 'server':49 'simpl':4 'socket.io':62 'stabl':16 'straightforward':55 'support':47 'updat':22 'usag':52 'version':17 'websocket':3,13,60 'wire':46 'without':75 'xy':2 'xy-websocket':1","created_at":"2026-06-07T17:03:40.578296+00:00","updated_at":"2026-06-07T17:03:40.578296+00:00","problems":[{"fix":"import { createServer } from 'xy-websocket'","cause":"Using default import instead of named import for createServer or createClient.","error":"TypeError: xy_websocket_1.default is not a function"},{"fix":"Use import() or set type: 'module' in package.json.","cause":"Using CommonJS require() to import an ESM-only package.","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module not supported"}],"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/xylogistics/xy-websocket#readme","github":"https://github.com/xylogistics/xy-websocket","docs":null,"changelog":null,"pypi":null,"npm":"xy-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}}