{"_id":"@aetherframework/websocket","_rev":"3-065ade6958d0a0b08cf86eed6f4f3011","name":"@aetherframework/websocket","dist-tags":{"latest":"1.0.3"},"versions":{"1.0.0":{"name":"@aetherframework/websocket","version":"1.0.0","keywords":["websocket","factory-pattern","zero-dependency","high-performance","esm"],"author":{"name":"Aether Framework Team"},"license":"MIT","_id":"@aetherframework/websocket@1.0.0","maintainers":[{"name":"aetherframework","email":"aetherjs@outlook.com"}],"homepage":"https://www.aetherjs.org","bugs":{"url":"https://github.com/aetherjs/aetherframework-websocket/issues","email":"support@aetherjs.org"},"dist":{"shasum":"9f4ae24b1bed8296cc7f286cedf27892bd251471","tarball":"https://registry.npmjs.org/@aetherframework/websocket/-/websocket-1.0.0.tgz","fileCount":23,"integrity":"sha512-OiEubZCltiUMejkrPSf4RISjHj086NQxZtyVL98jXk8dJMy9fWYQTGJhMLZbfLWKbWkSi0fHQ8lcvNCZCwDPsg==","signatures":[{"sig":"MEQCIHvUQfcXAs71TwCdgSC4hTdHTXesSn3jkerfcyvZ7z3eAiBOS//LABNIBsaZm25/rjYTCcEAgewc00vuAgWDe7PT6Q==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":135833},"main":"index.js","type":"module","types":"index.d.ts","engines":{"node":">=18.0.0"},"scripts":{"test":"echo \"Error: no test specified\" && exit 1","start:api":"node examples/realtime-api.js","start:chat":"node examples/chat-server.js","start:basic":"node examples/basic-server.js"},"_npmUser":{"name":"aetherframework","email":"aetherjs@outlook.com"},"repository":{"url":"git+https://github.com/aetherjs/aetherframework-websocket.git","type":"git"},"_npmVersion":"10.9.3","description":"Zero-dependency WebSocket server implementation for AetherJS","directories":{},"_nodeVersion":"22.18.0","_hasShrinkwrap":false,"devDependencies":{"jest":"^29.0.0","jsdoc":"^4.0.0","dotenv":"^16.6.1","eslint":"^8.0.0","prettier":"^3.0.0","@types/node":"^20.0.0"},"_npmOperationalInternal":{"tmp":"tmp/websocket_1.0.0_1780652888536_0.5212369212213126","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"@aetherframework/websocket","version":"1.0.1","keywords":["websocket","factory-pattern","zero-dependency","high-performance","esm"],"author":{"name":"Aether Framework Team"},"license":"MIT","_id":"@aetherframework/websocket@1.0.1","maintainers":[{"name":"aetherframework","email":"aetherjs@outlook.com"}],"homepage":"https://www.aetherjs.org","bugs":{"url":"https://github.com/aetherjs/aetherframework-websocket/issues","email":"support@aetherjs.org"},"dist":{"shasum":"37b9040f447f4e1ed32f5b575bd26baf7376a5f0","tarball":"https://registry.npmjs.org/@aetherframework/websocket/-/websocket-1.0.1.tgz","fileCount":4,"integrity":"sha512-IzI7f4NKnMW1GZKGRD65s9UedsOWxobXbFzsEoFj1jOROzTFXY18FJ5pTuYV1Bhto6SYRBs0z/Ad4WdG2h/QCQ==","signatures":[{"sig":"MEYCIQD9iINX3rDssN3F8WsTdL9WL0H6dnT0R3m+K6wlYTX42QIhAMV0ojnpQ/uci62mdnGNX2M3QGOITuVIxZ+simE9pjxB","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":10816},"main":"index.js","type":"module","types":"index.d.ts","engines":{"node":">=18.0.0"},"scripts":{"test":"echo \"Error: no test specified\" && exit 1","start:api":"node examples/realtime-api.js","start:chat":"node examples/chat-server.js","start:basic":"node examples/basic-server.js"},"_npmUser":{"name":"aetherframework","email":"aetherjs@outlook.com"},"repository":{"url":"git+https://github.com/aetherjs/aetherframework-websocket.git","type":"git"},"_npmVersion":"10.9.3","description":"Zero-dependency WebSocket server implementation for AetherJS","directories":{},"_nodeVersion":"22.18.0","_hasShrinkwrap":false,"devDependencies":{"jest":"^29.0.0","jsdoc":"^4.0.0","dotenv":"^16.6.1","eslint":"^8.0.0","prettier":"^3.0.0","@types/node":"^20.0.0"},"_npmOperationalInternal":{"tmp":"tmp/websocket_1.0.1_1780932017766_0.9613026491797343","host":"s3://npm-registry-packages-npm-production"}},"1.0.3":{"name":"@aetherframework/websocket","version":"1.0.3","description":"Zero-dependency WebSocket server implementation for AetherJS","main":"index.js","types":"index.d.ts","type":"module","scripts":{"start:basic":"node examples/basic-server.js","start:chat":"node examples/chat-server.js","start:api":"node examples/realtime-api.js","test":"echo \"Error: no test specified\" && exit 1"},"keywords":["websocket","factory-pattern","zero-dependency","high-performance","esm"],"devDependencies":{"@types/node":"^20.0.0","dotenv":"^16.6.1","eslint":"^8.0.0","jest":"^29.0.0","jsdoc":"^4.0.0","prettier":"^3.0.0"},"engines":{"node":">=18.0.0"},"author":{"name":"Aether Framework Team"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/aetherjs/aetherframework-websocket.git"},"bugs":{"url":"https://github.com/aetherjs/aetherframework-websocket/issues","email":"support@aetherjs.org"},"homepage":"https://www.aetherjs.org","_id":"@aetherframework/websocket@1.0.3","_nodeVersion":"22.18.0","_npmVersion":"10.9.3","dist":{"integrity":"sha512-2rObOS6VQyhDUCs32w4HVluiQf8uDulKghlQ4W4h9yzgaEb4EijcaLU4wOJhca3S4Zy6uuYR14fcXJTVqj7W7A==","shasum":"4629686bd52fef808faeb167b15874268179e1af","tarball":"https://registry.npmjs.org/@aetherframework/websocket/-/websocket-1.0.3.tgz","fileCount":29,"unpackedSize":177591,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDqUJ9Y6TlsxgjfqXEoWiUkDfvsHfMeq/ZqLlGJCzHRcgIgFaicNtCTjQXlOy8NCeG4DYbtwla6Q2EiA8ZSX38NC8w="}]},"_npmUser":{"name":"aetherframework","email":"aetherjs@outlook.com"},"directories":{},"maintainers":[{"name":"aetherframework","email":"aetherjs@outlook.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/websocket_1.0.3_1780933873341_0.1500826117544889"},"_hasShrinkwrap":false}},"time":{"created":"2026-06-05T09:48:08.377Z","modified":"2026-06-08T15:51:13.601Z","1.0.0":"2026-06-05T09:48:08.708Z","1.0.1":"2026-06-08T15:20:17.892Z","1.0.3":"2026-06-08T15:51:13.495Z"},"bugs":{"url":"https://github.com/aetherjs/aetherframework-websocket/issues","email":"support@aetherjs.org"},"author":{"name":"Aether Framework Team"},"license":"MIT","homepage":"https://www.aetherjs.org","keywords":["websocket","factory-pattern","zero-dependency","high-performance","esm"],"repository":{"type":"git","url":"git+https://github.com/aetherjs/aetherframework-websocket.git"},"description":"Zero-dependency WebSocket server implementation for AetherJS","maintainers":[{"name":"aetherframework","email":"aetherjs@outlook.com"}],"readme":"Aether WebSocket API 🚀\r\n\r\nHigh-Performance, Zero-Dependency WebSocket Server & Client for Node.js\r\n\r\nAether is a lightweight, robust, and highly efficient WebSocket implementation built from the ground up for Node.js. Unlike heavy frameworks that bundle unnecessary features, Aether focuses on raw speed, memory efficiency, and strict RFC 6455 compliance.\r\n\r\n✨ Why Choose Aether?\r\n\r\n1. ⚡ Blazing Fast Performance\r\nBuilt with a custom binary frame parser (`FrameParser`) and encoder (`FrameEncoder`), Aether minimizes garbage collection pressure and maximizes throughput. It handles thousands of concurrent connections with minimal CPU overhead.\r\n\r\n2. 🪶 Zero Dependencies\r\nAether relies only on Node.js built-in modules (`net`, `http`, `crypto`, `events`). No `npm install` bloat, no security vulnerabilities from third-party packages, and a tiny footprint ideal for microservices and serverless environments.\r\n\r\n3. 🛡️ Robust & Secure\r\n- Strict Protocol Compliance: Fully adheres to RFC 6455.\r\n- Memory Safety: Built-in protection against memory leaks via efficient buffer management.\r\n- Error Resilience: Graceful handling of malformed frames, unexpected disconnections, and protocol errors.\r\n\r\n\r\n> Best For: Developers who need a reliable, lightweight, and transparent WebSocket solution without the baggage of large frameworks.\r\n\r\n---\r\n\r\n📦 Installation\r\n\r\nInstall Aether WebSocket via npm:\r\n\r\n```bash\r\nnpm install aetherframework-websocket\r\n```\r\n\r\n---\r\n\r\n🚀 Quick Start\r\n\r\n1. Create a WebSocket Server\r\n\r\n```javascript\r\nimport { createWebSocketFactory } from 'aetherframework-websocket';\r\n\r\n// Create a WebSocket factory instance\r\nconst factory = createWebSocketFactory({\r\n  port: 8080,\r\n  host: '0.0.0.0',\r\n  maxPayload: 1024 * 1024, // 1MB max message size\r\n  pingInterval: 30000,     // Send ping every 30s\r\n});\r\n\r\n// Handle new connections\r\nfactory.on('connection', (connection) => {\r\n  console.log(`✅ New connection: ${connection.id}`);\r\n\r\n  // Send a welcome message\r\n  connection.socket.write(factory._encodeFrame(0x1, Buffer.from('Welcome to Aether!')));\r\n\r\n  // Handle incoming messages\r\n  factory.on('message', (conn, data, isBinary) => {\r\n    console.log(`📨 Received from ${conn.id}:`, data.toString());\r\n    \r\n    // Echo back\r\n    conn.socket.write(factory._encodeFrame(0x1, Buffer.from('Echo: ' + data)));\r\n  });\r\n\r\n  // Handle disconnection\r\n  factory.on('close', (conn, code, reason) => {\r\n    console.log(`❌ Disconnected: ${conn.id} (Code: ${code})`);\r\n  });\r\n});\r\n\r\n// Start the server\r\nasync function start() {\r\n  try {\r\n    const server = await factory.createServer();\r\n    console.log(`🚀 Aether Server running on ws://${server.address.address}:${server.address.port}`);\r\n  } catch (error) {\r\n    console.error('Failed to start server:', error);\r\n  }\r\n}\r\n\r\nstart();\r\n```\r\n\r\n2. Create a WebSocket Client\r\n\r\n```javascript\r\nimport { createWebSocketFactory } from 'aetherframework-websocket';\r\n\r\nconst factory = createWebSocketFactory();\r\n\r\nasync function connect() {\r\n  try {\r\n    const client = await factory.createClient('ws://localhost:8080');\r\n    \r\n    console.log('✅ Connected to server');\r\n\r\n    // Listen for messages\r\n    factory.on('message', (conn, data, isBinary) => {\r\n      console.log('📨 Server says:', data.toString());\r\n      \r\n      // Close connection after receiving\r\n      client.close(1000, 'Goodbye');\r\n    });\r\n\r\n    // Send a message\r\n    client.send('Hello Aether!');\r\n\r\n  } catch (error) {\r\n    console.error('Connection failed:', error);\r\n  }\r\n}\r\n\r\nconnect();\r\n```\r\n\r\n---\r\n\r\n📚 API Reference\r\n\r\n`createWebSocketFactory` Function\r\n\r\n```javascript\r\ncreateWebSocketFactory(config)\r\n```\r\n- `config.port` (number): Server port (default: `80`).\r\n- `config.host` (string): Server host (default: `'0.0.0.0'`).\r\n- `config.maxPayload` (number): Max message size in bytes (default: `1048576`).\r\n- `config.pingInterval` (number): Milliseconds between pings (default: `null`).\r\n\r\nAvailable Methods\r\n\r\n| Method | Description | Returns |\r\n| :--- | :--- | :--- |\r\n| `createServer(options)` | Starts the HTTP/WebSocket server. | `Promise<{ type, address, close }>` |\r\n| `createClient(url, options)` | Creates a WebSocket client connection. | `Promise<{ id, socket, send, close }>` |\r\n| `closeServer()` | Gracefully shuts down the server. | `Promise<void>` |\r\n| `getStats()` | Returns current server statistics. | `Object` |\r\n\r\nEvents\r\n\r\n| Event | Callback Arguments | Description |\r\n| :--- | :--- | :--- |\r\n| `connection` | `(connection)` | Fired when a new client connects. |\r\n| `message` | `(connection, data, isBinary)` | Fired when a message is received. |\r\n| `close` | `(connection, code, reason)` | Fired when a connection closes. |\r\n| `error` | `(errorObj)` | Fired on parsing or socket errors. |\r\n| `ping` | `(connection, payload)` | Fired when a ping is received. |\r\n| `pong` | `(connection, payload)` | Fired when a pong is received. |\r\n\r\n---\r\n\r\n🛠️ Advanced Configuration\r\n\r\nHandling Binary Data\r\nAether seamlessly handles both text and binary frames.\r\n\r\n```javascript\r\nfactory.on('message', (conn, data, isBinary) => {\r\n  if (isBinary) {\r\n    console.log('Received binary data:', data.length, 'bytes');\r\n    // Process Buffer directly\r\n  } else {\r\n    console.log('Received text:', data.toString());\r\n  }\r\n});\r\n```\r\n\r\nCustom Heartbeat Logic\r\nIf you disable `pingInterval` in config, you can implement custom health checks:\r\n\r\n```javascript\r\nfactory.on('connection', (conn) => {\r\n  conn.isAlive = true;\r\n  \r\n  const interval = setInterval(() => {\r\n    if (!conn.isAlive) {\r\n      console.log('Terminating inactive connection');\r\n      conn.socket.destroy();\r\n      return clearInterval(interval);\r\n    }\r\n    conn.isAlive = false;\r\n    factory._sendPing(conn.socket);\r\n  }, 30000);\r\n\r\n  factory.on('pong', () => {\r\n    conn.isAlive = true;\r\n  });\r\n});\r\n```\r\n\r\n---\r\n\r\n📊 Statistics & Monitoring\r\n\r\nUse `getStats()` to monitor server health in real-time:\r\n\r\n```javascript\r\nsetInterval(() => {\r\n  const stats = factory.getStats();\r\n  console.log(`Active Connections: ${stats.connections}`);\r\n  console.log(`Uptime: ${stats.uptime}ms`);\r\n  console.log(`Memory RSS: ${stats.memory.rss} bytes`);\r\n}, 10000);\r\n```\r\n---\r\n\r\n📄 License\r\n\r\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\r\n\r\n---\r\n\r\nMade with ❤️ by the Aether Team","readmeFilename":"README.md"}