* Server constructor. * * @param {Object} opts - options
(opts: ServerOptions = {})
| 185 | * @param {Object} opts - options |
| 186 | */ |
| 187 | constructor(opts: ServerOptions = {}) { |
| 188 | super(); |
| 189 | |
| 190 | this.clients = {}; |
| 191 | this.clientsCount = 0; |
| 192 | |
| 193 | this.opts = Object.assign( |
| 194 | { |
| 195 | wsEngine: DEFAULT_WS_ENGINE, |
| 196 | pingTimeout: 20000, |
| 197 | pingInterval: 25000, |
| 198 | upgradeTimeout: 10000, |
| 199 | maxHttpBufferSize: 1e6, |
| 200 | transports: ["polling", "websocket"], // WebTransport is disabled by default |
| 201 | allowUpgrades: true, |
| 202 | httpCompression: { |
| 203 | threshold: 1024, |
| 204 | }, |
| 205 | cors: false, |
| 206 | allowEIO3: false, |
| 207 | }, |
| 208 | opts, |
| 209 | ); |
| 210 | |
| 211 | if (opts.cookie) { |
| 212 | this.opts.cookie = Object.assign( |
| 213 | { |
| 214 | name: "io", |
| 215 | path: "/", |
| 216 | httpOnly: true, |
| 217 | sameSite: "lax", |
| 218 | }, |
| 219 | opts.cookie, |
| 220 | ); |
| 221 | } |
| 222 | |
| 223 | if (this.opts.cors) { |
| 224 | this.use(require("cors")(this.opts.cors)); |
| 225 | } |
| 226 | |
| 227 | if (opts.perMessageDeflate) { |
| 228 | this.opts.perMessageDeflate = Object.assign( |
| 229 | { |
| 230 | threshold: 1024, |
| 231 | }, |
| 232 | opts.perMessageDeflate, |
| 233 | ); |
| 234 | } |
| 235 | |
| 236 | this.init(); |
| 237 | } |
| 238 | |
| 239 | protected abstract init(): void; |
| 240 |