mirror of
https://github.com/socketio/socket.io.git
synced 2026-01-13 00:48:12 -05:00
This major bump creates a lot of noise, but it is necessary for
prettier to be able to parse new syntax such as:
- typed imports: `import { type xxx } from ...`
- private attributes: `class A { #b; #c() {} }`
58 lines
1.2 KiB
JavaScript
58 lines
1.2 KiB
JavaScript
const { listen, uServer } = require("..");
|
|
const { Socket } =
|
|
process.env.EIO_CLIENT === "3"
|
|
? require("engine.io-client-v3")
|
|
: require("engine.io-client");
|
|
|
|
/**
|
|
* Listen shortcut that fires a callback on an ephemeral port.
|
|
*/
|
|
|
|
exports.listen = (opts, fn) => {
|
|
if ("function" === typeof opts) {
|
|
fn = opts;
|
|
opts = {};
|
|
}
|
|
|
|
opts.allowEIO3 = true;
|
|
|
|
if (process.env.EIO_WS_ENGINE === "uws") {
|
|
const { App, us_socket_local_port } = require("uWebSockets.js");
|
|
const engine = new uServer(opts);
|
|
const app = App();
|
|
engine.attach(app, opts);
|
|
|
|
app.listen(0, (listenSocket) => {
|
|
const port = us_socket_local_port(listenSocket);
|
|
process.nextTick(() => {
|
|
fn(port);
|
|
});
|
|
});
|
|
|
|
return engine;
|
|
}
|
|
|
|
if (process.env.EIO_WS_ENGINE === "eiows") {
|
|
opts.wsEngine = require("eiows").Server;
|
|
}
|
|
|
|
const e = listen(0, opts, () => {
|
|
fn(e.httpServer.address().port);
|
|
});
|
|
|
|
return e;
|
|
};
|
|
|
|
exports.ClientSocket = Socket;
|
|
|
|
exports.createPartialDone = (done, count) => {
|
|
let i = 0;
|
|
return () => {
|
|
if (++i === count) {
|
|
done();
|
|
} else if (i > count) {
|
|
done(new Error(`partialDone() called too many times: ${i} > ${count}`));
|
|
}
|
|
};
|
|
};
|