How to use the @xmpp/client.xml function in @xmpp/client

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 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();
github pazznetwork / ngx-chat / projects / pazznetwork / ngx-chat / src / lib / services / adapters / xmpp / plugins / multi-user-chat.plugin.ts View on Github external
private convertConfiguration(configurationKeyValuePair: { [key: string]: string[] }) {
        const configurationFields = [];
        for (const configurationKey in configurationKeyValuePair) {
            if (configurationKeyValuePair.hasOwnProperty(configurationKey)) {
                const configurationValues = configurationKeyValuePair[configurationKey].map(value => xml('value', {}, value));
                configurationFields.push(
                    xml('field', {var: configurationKey}, ...configurationValues)
                );
            }
        }
        return configurationFields;
    }
github pazznetwork / ngx-chat / projects / pazznetwork / ngx-chat / src / lib / services / adapters / xmpp / plugins / message-state.plugin.ts View on Github external
private sendMessageStateNotification(recipient: JID, messageId: string, state: MessageState) {
        const messageStateResponse = xml('message', {
                to: recipient.bare().toString(),
                from: this.xmppChatAdapter.chatConnectionService.userJid.toString(),
                type: 'chat'
            },
            xml('message-state', {
                xmlns: STORAGE_NGX_CHAT_CONTACT_MESSAGE_STATES,
                messageId,
                date: new Date().toISOString(),
                state
            })
        );
        this.xmppChatAdapter.chatConnectionService.send(messageStateResponse);
    }
github pazznetwork / ngx-chat / projects / pazznetwork / ngx-chat / src / lib / services / adapters / xmpp / plugins / message-state.plugin.ts View on Github external
private sendMessageStateNotification(recipient: JID, messageId: string, state: MessageState) {
        const messageStateResponse = xml('message', {
                to: recipient.bare().toString(),
                from: this.xmppChatAdapter.chatConnectionService.userJid.toString(),
                type: 'chat'
            },
            xml('message-state', {
                xmlns: STORAGE_NGX_CHAT_CONTACT_MESSAGE_STATES,
                messageId,
                date: new Date().toISOString(),
                state
            })
        );
        this.xmppChatAdapter.chatConnectionService.send(messageStateResponse);
    }
github pazznetwork / ngx-chat / projects / pazznetwork / ngx-chat / src / lib / services / adapters / xmpp / plugins / multi-user-chat.plugin.ts View on Github external
const configurationListElement = configurationForm.getChild('query').getChild('x');
        if (!configurationListElement) {
            throw new Error('room not configurable');
        }

        const configurationKeyValuePair = {
            ...this.extractDefaultConfiguration(configurationListElement.getChildren('field')),
            ...this.extractRoomCreationRequestConfiguration(request)
        };

        try {
            await this.xmppChatAdapter.chatConnectionService.sendIq(
                xml('iq', {type: 'set', to: room.roomJid.toString()},
                    xml('query', {xmlns: 'http://jabber.org/protocol/muc#owner'},
                        xml('x', {xmlns: 'jabber:x:data', type: 'submit'},
                            xml('field', {var: 'FORM_TYPE'},
                                xml('value', {}, 'http://jabber.org/protocol/muc#roomconfig')
                            ),
                            ...this.convertConfiguration(configurationKeyValuePair)
                        )
                    )
                )
            );
            return room;
        } catch (e) {
            throw new Error('room configuration rejected: ' + e.toString());
        }
    }

@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