Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function component(options) {
const {password, service, domain} = options
const entity = new Component({service, domain})
const reconnect = _reconnect({entity})
const middleware = _middleware({entity})
const iqCaller = _iqCaller({entity, middleware})
const iqCallee = _iqCallee({entity, middleware})
entity.on('open', async el => {
try {
const {id} = el.attrs
if (typeof password === 'function') {
await password(creds => entity.authenticate(id, creds))
} else {
await entity.authenticate(id, password)
}
} catch (err) {
entity.emit('error', err)