Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
throw new Error("Couldn't connect")
}
const uri = uris.shift()
const Transport = entity._findTransport(uri)
if (!Transport) {
return fallbackConnect(entity, uris)
}
entity._status('connecting', uri)
const params = Transport.prototype.socketParameters(uri)
const socket = new Transport.prototype.Socket()
try {
await socketConnect(socket, params)
// eslint-disable-next-line no-unused-vars
} catch (err) {
return fallbackConnect(entity, uris)
}
entity._attachSocket(socket)
socket.emit('connect')
/* eslint-disable require-atomic-updates */
entity.Transport = Transport
entity.Socket = Transport.prototype.Socket
entity.Parser = Transport.prototype.Parser
/* eslint-enable require-atomic-updates */
}
if (uris.length === 0) {
throw new Error("Couldn't connect")
}
const uri = uris.shift()
const Transport = entity._findTransport(uri)
if (!Transport) {
return fallbackConnect(entity, uris)
}
const params = Transport.prototype.socketParameters(uri)
const socket = new Transport.prototype.Socket()
try {
await socketConnect(socket, params)
} catch (err) {
return fallbackConnect(entity, uris)
}
entity._attachSocket(socket)
socket.emit('connect')
entity.Transport = Transport
entity.Socket = Transport.prototype.Socket
entity.Parser = Transport.prototype.Parser
}
socketParameters(service) {
const {port, hostname, protocol} = parseURI(service)
return protocol === 'xmpps:'
? {port: Number(port) || 5223, host: hostname}
: undefined
}
}
socketParameters(service) {
const {port, hostname, protocol} = parseURI(service)
return protocol === 'xmpp:'
? {port: port ? Number(port) : null, host: hostname}
: undefined
}