How to use @xmpp/client - 10 common examples

To help you get started, we’ve selected a few @xmpp/client examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github xmppjs / xmpp.js / packages / client / example.js View on Github external
/* 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')
})
github xmppjs / xmpp.js / packages / roster / example.js View on Github external
/* 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(
github pazznetwork / ngx-chat / projects / pazznetwork / ngx-chat / src / lib / services / adapters / xmpp / plugins / multi-user-chat.plugin.spec.ts View on Github external
xml('presence', {from: stanza.attrs.to, to: stanza.attrs.from},
                            xml('x', {xmlns: 'http://jabber.org/protocol/muc#user'},
                                xml('item', {affiliation: 'owner', role: 'moderator'}),
                                xml('status', {code: '110'}),
                                xml('status', {code: '201'})
                            )
                        )
                    );
                } else {
                    throw new Error('unknown stanza: ' + stanza.toString());
                }

            });

            // when
            const myOccupantJid = parseJid('chatroom@conference.example.com/me');
            const room = await multiUserChatPlugin.joinRoom(myOccupantJid);
            await multiUserChatPlugin.sendMessage(room, 'message body');

            // then
            expect(room.messages.length).toEqual(1);
            expect(room.messages[0].body).toEqual('message body');
            expect(room.messages[0].direction).toEqual(Direction.out);
            expect(room.messages[0].id).not.toBeUndefined();
            expect(room.messages[0].from).toEqual(myOccupantJid);

        });
github xmppjs / xmpp.js / packages / console / cli.js View on Github external
input: process.stdin,
    output: process.stdout,
    prompt: chalk.magenta.bold('✏ '),
  }
  if (Number(process.env.NODE_NO_READLINE)) {
    options.terminal = false
  }
  const rl = readline.createInterface(options)

  let prevent = false

  let entity
  if (flags.type === 'compomnent') {
    entity = component.xmpp().component
  } else {
    entity = client.xmpp().client
  }

  const xconsole = new Console(entity)
  xconsole.resetInput = function() {
    rl.prompt()
  }
  xconsole.log = function(...args) {
    readline.cursorTo(process.stdout, 0)
    console.log(...args)
    rl.prompt()
  }
  xconsole.info = function(...args) {
    this.log(chalk.cyan.bold('🛈'), ...args)
  }
  xconsole.warning = function(...args) {
    this.log(chalk.yellow.bold('⚠'), ...args)
github pazznetwork / ngx-chat / projects / pazznetwork / ngx-chat / src / lib / services / adapters / xmpp / plugins / message-archive.plugin.spec.ts View on Github external
describe('message archive plugin', () => {

    let chatConnectionService: XmppChatConnectionService;
    let chatAdapter: XmppChatAdapter;
    let contactFactory: ContactFactoryService;
    let xmppClientMock: SpyObj;
    let contact1: Contact;
    const userJid = parseJid('me@example.com/myresource');

    const validArchiveStanza =
        xml('message', {},
            xml('result', {xmlns: 'urn:xmpp:mam:2'},
                xml('forwarded', {},
                    xml('delay', {stamp: '2018-07-18T08:47:44.233057Z'}),
                    xml('message', {to: userJid.toString(), from: 'someone@else.com/resource'},
                        xml('origin-id', {id: 'id'}),
                        xml('body', {}, 'message text')))));

    beforeEach(() => {
        const mockClientFactory = new MockClientFactory();
        xmppClientMock = mockClientFactory.clientInstance;

        TestBed.configureTestingModule({
            providers: [
                XmppChatConnectionService,
                {provide: XmppClientFactoryService, useValue: mockClientFactory},
                XmppChatAdapter,
                {provide: LogService, useValue: testLogService()},
                ContactFactoryService
            ]
        });
github pazznetwork / ngx-chat / projects / pazznetwork / ngx-chat / src / lib / services / adapters / xmpp / plugins / roster.plugin.ts View on Github external
private sendAddToRoster(jid: string) {
        return this.chatService.chatConnectionService.sendIq(
            xml('iq', {type: 'set'},
                xml('query', {xmlns: 'jabber:iq:roster'},
                    xml('item', {jid}))));
    }
github pazznetwork / ngx-chat / projects / pazznetwork / ngx-chat / src / lib / services / adapters / xmpp / plugins / bookmark.plugin.ts View on Github external
private convertSavedConferenceToElement(savedConference: SavedConference) {
        const {name, autojoin, jid} = savedConference;
        return xml('conference', {name, jid, autojoin: autojoin.toString()});
    }
github pazznetwork / ngx-chat / projects / pazznetwork / ngx-chat / src / lib / services / adapters / xmpp / plugins / publish-subscribe.plugin.ts View on Github external
toStanza() {
        return xml('iq', {type: 'get'},
            xml('pubsub', {xmlns: 'http://jabber.org/protocol/pubsub'},
                xml('items', {node: this.node})
            )
        );
    }
github pazznetwork / ngx-chat / projects / pazznetwork / ngx-chat / src / lib / services / adapters / xmpp / plugins / registration.plugin.ts View on Github external
domain = domain || getDomain(service);

                    this.logService.debug('registration plugin', 'connecting...');
                    await this.connect(username, password, service, domain);

                    this.logService.debug('registration plugin', 'connection established, starting registration');
                    await this.client.iqCaller.request(
                        xml('iq', {type: 'get', to: domain},
                            xml('query', {xmlns: 'jabber:iq:register'})
                        )
                    );

                    this.logService.debug('registration plugin', 'server acknowledged registration request, sending credentials');
                    await this.client.iqCaller.request(
                        xml('iq', {type: 'set'},
                            xml('query', {xmlns: 'jabber:iq:register'},
                                xml('username', {}, username),
                                xml('password', {}, password)
                            )
                        )
                    );

                    this.registered$.next();
                    await this.loggedIn$.pipe(takeUntil(this.cleanUp), first()).toPromise();
                    this.logService.debug('registration plugin', 'registration successful');
                })(), this.registrationTimeout);
            } catch (e) {
github pazznetwork / ngx-chat / projects / pazznetwork / ngx-chat / src / lib / services / adapters / xmpp / plugins / service-discovery.plugin.spec.ts View on Github external
if (content.attrs.to === 'jabber.example.com'
                && content.getChild('query').attrs.xmlns === 'http://jabber.org/protocol/disco#items') {

                chatConnectionService.onStanzaReceived(
                    xml('iq', {type: 'result', id: content.attrs.id},
                        xml('query', {xmlns: 'http://jabber.org/protocol/disco#items'},
                            xml('item', {jid: 'conference.jabber.example.com'})
                        )
                    ) as Stanza
                );
            } else if (content.getChild('query') && content.getChild('query').attrs.xmlns === 'http://jabber.org/protocol/disco#info') {
                if (content.attrs.to === 'conference.jabber.example.com') {
                    chatConnectionService.onStanzaReceived(
                        xml('iq', {type: 'result', id: content.attrs.id, from: content.attrs.to},
                            xml('query', {xmlns: 'http://jabber.org/protocol/disco#info'},
                                xml('identity', {type: 'text', category: 'conference'})
                            )
                        ) as Stanza
                    );
                } else {
                    chatConnectionService.onStanzaReceived(
                        xml('iq', {type: 'result', id: content.attrs.id, from: content.attrs.to},
                            xml('query', {xmlns: 'http://jabber.org/protocol/disco#info'},
                                xml('identity', {type: 'type', category: 'category'})
                            )
                        ) as Stanza
                    );
                }
            } else {
                fail('unexpected stanza: ' + content.toString());
            }
            return Promise.resolve();

@xmpp/client

An XMPP client is an entity that connects to an XMPP server.

ISC
Latest version published 3 years ago

Package Health Score

50 / 100
Full package analysis

Similar packages