Files
cypress/packages/socket/lib/socket.ts
Tim Griesser bda7e5eec6 refactor: Add GitDataSource, FileDataSource, toast for errors (#18385)
* refactor: Add GitDataSource, FileDataSource, toast for errors

* Fix

* fix

* Fix: use frontend-shared for common optimizeDeps

* schema/type fixes

* add debug for circle job

* add debug for circle job

* Attempting to debug CI flake

* Fix types

* Attempt to fix

* Revert "Attempt to fix"

This reverts commit 12a8db455a.

* Just use more parallelization?

* See if this fixes it

* remove debug

* Force browser relaunch?

* use internal ENV var
2021-10-07 20:47:02 -04:00

49 lines
1.3 KiB
TypeScript

import fs from 'fs'
import type http from 'http'
import server, { Server as SocketIOBaseServer, ServerOptions, Socket } from 'socket.io'
import { client } from './browser'
export type { Socket }
const HUNDRED_MEGABYTES = 1e8 // 100000000
const { version } = require('socket.io-client/package.json')
const clientSource = require.resolve('socket.io-client/dist/socket.io.js')
export { ServerOptions }
// socket.io types are incorrect
type PatchedServerOptions = ServerOptions & { cookie: { name: string | boolean } }
class SocketIOServer extends SocketIOBaseServer {
constructor (srv: http.Server, opts?: Partial<PatchedServerOptions>) {
// in socket.io v3, they reduced down the max buffer size
// from 100mb to 1mb, so we reset it back to the previous value
//
// previous commit for reference:
// https://github.com/socketio/engine.io/blame/61b949259ed966ef6fc8bfd61f14d1a2ef06d319/lib/server.js#L29
opts = opts ?? {}
opts.maxHttpBufferSize = opts.maxHttpBufferSize ?? HUNDRED_MEGABYTES
super(srv, opts)
}
}
export {
client,
server,
SocketIOServer,
}
export const getPathToClientSource = () => {
return clientSource
}
export const getClientVersion = () => {
return version
}
export const getClientSource = () => {
return fs.readFileSync(getPathToClientSource(), 'utf8')
}