Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/* eslint-disable node/no-extraneous-require */
'use strict'
const {client, xml} = require('@xmpp/client')
const debug = require('@xmpp/debug')
const xmpp = client({
service: 'ws://localhost:5280/xmpp-websocket',
domain: 'localhost',
resource: 'example',
username: 'username',
password: 'password',
})
debug(xmpp, true)
xmpp.on('error', err => {
console.error(err)
})
xmpp.on('offline', () => {
console.log('offline')
})/* eslint-disable node/no-extraneous-require */
/*
* This is a complete example of roster management with persistent versioning (caching) support
* it uses XML serialization and the filesystem for persistence but
* you can use anything you like such as IndexedDB and JSON as long as the version (ver) is correct
*/
'use strict'
const {client, xml} = require('@xmpp/client')
const debug = require('@xmpp/debug')
const Roster = require('.') // @xmpp/roster
const Storage = require('./Storage') // @xmpp/storage
const xmpp = client({
// service: 'ws://localhost:5280/xmpp-websocket',
// domain: 'localhost',
service: 'localhost',
username: 'username',
password: 'password',
})
debug(xmpp, true)
const storage = new Storage(xmpp)
// eslint-disable-next-line new-cap
xmpp.roster = Roster({...xmpp, storage})
xmpp.on('online', async () => {
const roster = await xmpp.roster.get()
console.log(return new Promise(resolveConnectionEstablished => {
this.client = client({
domain: domain || getDomain(service),
service,
credentials: async (authenticationCallback) => {
resolveConnectionEstablished();
await this.registered$.pipe(takeUntil(this.cleanUp), first()).toPromise();
await authenticationCallback({username, password});
}
});
this.client.reconnect.stop();
this.client.timeout = this.registrationTimeout;
this.client.on('online', () => {
this.logService.debug('registration plugin', 'online event');
this.loggedIn$.next();
});