Files
cypress/packages/socket/lib/node/socket.ts

34 lines
1.2 KiB
TypeScript

import buffer from 'buffer'
import type http from 'http'
import { Server as SocketIOBaseServer, ServerOptions } from 'socket.io'
// TODO: this will need to be updated to use an ESM version of the package
const { version } = require('socket.io-client/package.json')
const clientSource = require.resolve('socket.io-client/dist/socket.io.js')
// socket.io types are incorrect
type PatchedServerOptions = ServerOptions & { cookie: { name: string | boolean } }
export class SocketIOServer extends SocketIOBaseServer {
constructor (srv: http.Server, opts?: Partial<PatchedServerOptions>) {
opts = opts ?? {}
// the maxHttpBufferSize is used to limit the message size sent over
// the socket. Small values can be used to mitigate exposure to
// denial of service attacks; the default as of v3.0 is 1MB.
// because our server is local, we do not need to arbitrarily limit
// the message size and can use the theoretical maximum value.
opts.maxHttpBufferSize = opts.maxHttpBufferSize ?? buffer.constants.MAX_LENGTH
super(srv, opts)
}
}
export const getPathToClientSource = () => {
return clientSource
}
export const getClientVersion = () => {
return version
}