Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function Manager(uri, opts) {
if (!(this instanceof Manager)) return new Manager(uri, opts)
opts.path = opts.path || 'socket.io'
this.nsps = {}
this.subs = []
this.opts = opts
this.uri = uri
this.readyState = 'closed'
this.connected = false
this.reconnection(opts.reconnection !== false)
this.reconnectionAttempts(opts.reconnectionAttempts || Infinity)
this.reconnectionDelay(opts.reconnectionDelay || 1000)
this.reconnectionDelayMax(opts.reconnectionDelayMax || 5000)
this.randomizationFactor(opts.randomizationFactor || 0.5)
this.backoff = new Backoff({
min: this.reconnectionDelay(),
max: this.reconnectionDelayMax(),
jitter: this.randomizationFactor(),
})
this.timeout(null == opts.timeout ? 20000 : opts.timeout)
this.encoder = encoder
this.decoder = decoder
this.connecting = []
this.autoConnect = opts.autoConnect !== false
if (this.autoConnect) this.open()
}
export default function getBackoff (config={}) {
config = { ...defaultConfig, ...config }
const backoff = new Backoff({
min: config.delayMin,
max: config.delayMax,
jitter: 0.5,
})
return backoff
}
constructor({
uri,
options: {
lazy = false,
operationTimeout = Infinity,
reconnect = false,
reconnectAttempts = Infinity,
} = {},
webSockImpl = NativeWebSocket,
}: Options) {
const backoff = new Backoff({ jitter: 0.5 });
if (webSockImpl == null) {
throw new Error(
'Not native WebSocket implementation detected, please provide an implementation',
);
}
this.lazy = lazy;
this.ee = new EventEmitter.EventEmitter() as any;
this.operationProcessor = new OperationProcessor({ operationTimeout });
this.machine = interpret(
clientMachine.withContext({
backoff,
reconnect,
reconnectAttempts,
uri,