Add WebSocket package with client/server & native
Introduce a new WebSocket package implementing RFC6455 functionality and permessage-deflate support. Adds core connection handling (packages/websocket/websocket.js), client wrapper (client.js), server and upgrade handling (server.js), extensions (permessage-deflate) and helpers (extensions.js), an index and native loader (native.js). Also include prebuilt native addon binaries for multiple platforms and integration points to use the native Parser and frame builder. The server supports handleUpgrade, subprotocol negotiation, and verifyClient hooks; the client performs handshakes and queues sends until open. Error handling, UTF-8 validation, close/ping/pong control frames, and max-payload checks are implemented.
This commit is contained in:
1 parent
39f1672b29
commit
5fb969da7c
9 files changed
+1170
No files matched your search
@@ -0,0 +1,33 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { createRequire } from 'node:module';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
const candidates = [
|
||||
path.join(__dirname, '..', 'build', 'Release', 'snowluma_ws.node'),
|
||||
path.join(__dirname, '..', 'build', 'Debug', 'snowluma_ws.node'),
|
||||
];
|
||||
|
||||
let addon = null;
|
||||
let lastErr = null;
|
||||
for (const p of candidates) {
|
||||
if (fs.existsSync(p)) {
|
||||
try {
|
||||
addon = require(p);
|
||||
break;
|
||||
} catch (e) {
|
||||
lastErr = e;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!addon) {
|
||||
throw new Error(
|
||||
'Failed to load native snowluma_ws addon. Run `npm run build` first. ' +
|
||||
(lastErr ? `Last error: ${lastErr.message}` : ''),
|
||||
);
|
||||
}
|
||||
|
||||
export default addon;
|
||||
Reference in new issue
Block a user