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

To help you get started, we’ve selected a few @xmpp/xml 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 matrix-org / matrix-bifrost / src / xmppjs / XJSGateway.ts View on Github external
stanza.attrs.to,
                stanza.attrs.from,
                undefined,
                "member",
                "participant",
                true,
            ),
        );
        this.reflectXMPPMessage(chatName, x("presence", {
                from: stanza.attrs.from,
                to: null,
                id: stanza.attrs.id,
            }, x("x", {
                    xmlns: "http://jabber.org/protocol/muc#user",
                }, [
                    x("item", {affiliation: "member", role: "participant"}),
                ]),
        ));
        // 3. Room history
        log.debug("Emitting history");
        const history = this.roomHistory.get(room.roomId) || [];
        history.forEach((e) => {
            e.attrs.to = stanza.attrs.from;
            // TODO: Add delay info to this.
            this.xmpp.xmppWriteToStream(e);
        });
        log.debug("Emitting subject");
        // 4. The room subject
        this.xmpp.xmppSend(new StzaMessageSubject(chatName, stanza.attrs.from, undefined,
            `${room.name || ""} ${room.topic ? "| " + room.topic : ""}`,
        ));
        // All done, now for some house cleaning.
github matrix-org / matrix-bifrost / test / xmppjs / test_presencecache.ts View on Github external
import { x } from "@xmpp/xml";
const expect = Chai.expect;

const aliceJoin = x("presence", {
    xmlns: "jabber:client",
    to: "bob@xmpp.matrix.org/fakedevice",
    from: "aroom@conf.xmpp.matrix.org/alice",
});

const aliceJoinGateway = x("presence", {
    xmlns: "jabber:client",
    from: "alice@xmpp.matrix.org/fakedevice",
    to: "aroom@conf.xmpp.matrix.org/alice",
});

const aliceLeave = x("presence", {
    to: "bob@xmpp.matrix.org/fakedevice",
    from: "aroom@conf.xmpp.matrix.org/alice",
    type: "unavailable",
}, [
    x("x", {xmlns: "http://jabber.org/protocol/muc#user"}, [
        x("item", {affiliation: "none", role: "none"}),
    ]),
]);

const bobJoin = x("presence", {
    to: "bob@xmpp.matrix.org/fakedevice",
    from: "aroom@conf.xmpp.matrix.org/bob",
}, [
    x("x", {xmlns: "http://jabber.org/protocol/muc#user"}, [
        x("item", {affiliation: "member", role: "participant"}),
        x("status", {code: "110"}),
github matrix-org / matrix-bifrost / test / xmppjs / test_presencecache.ts View on Github external
from: "aroom@conf.xmpp.matrix.org/bob",
    type: "unavailable",
}, [
    x("x", {xmlns: "http://jabber.org/protocol/muc#user"}, [
        x("item", {affiliation: "none", role: "none"}),
        x("status", {code: "110"}),
    ]),
]);

const aliceKick = x("presence", {
        xmlns: "jabber:client",
        to: "bob@xmpp.matrix.org/fakedevice",
        from: "aroom@conf.xmpp.matrix.org/alice",
        type: "unavailable",
    },
    x("x", {
        xmlns: "http://jabber.org/protocol/muc#user",
    },
    [
        x("status", {
            code: "307",
        }),
        x("item", undefined, [
            x("actor", {
                nick: "bob",
            }),
            x("reason", undefined, "Didn't like em much"),
        ]),
    ],
));

describe("PresenceCache", () => {
github matrix-org / matrix-bifrost / test / xmppjs / test_presencecache.ts View on Github external
x("x", {xmlns: "http://jabber.org/protocol/muc#user"}, [
        x("item", {affiliation: "none", role: "none"}),
    ]),
]);

const bobJoin = x("presence", {
    to: "bob@xmpp.matrix.org/fakedevice",
    from: "aroom@conf.xmpp.matrix.org/bob",
}, [
    x("x", {xmlns: "http://jabber.org/protocol/muc#user"}, [
        x("item", {affiliation: "member", role: "participant"}),
        x("status", {code: "110"}),
    ]),
]);

const aliceSeesBobJoin = x("presence", {
    to: "alice@xmpp.matrix.org/fakedevice",
    from: "aroom@conf.xmpp.matrix.org/bob",
}, [
    x("x", {xmlns: "http://jabber.org/protocol/muc#user"}, [
        x("item", {affiliation: "member", role: "participant"}),
    ]),
]);

const bobLeave = x("presence", {
    to: "bob@xmpp.matrix.org/fakedevice",
    from: "aroom@conf.xmpp.matrix.org/bob",
    type: "unavailable",
}, [
    x("x", {xmlns: "http://jabber.org/protocol/muc#user"}, [
        x("item", {affiliation: "none", role: "none"}),
        x("status", {code: "110"}),
github pazznetwork / ngx-chat / projects / pazznetwork / ngx-chat / src / lib / services / adapters / xmpp / xmpp-chat-adapter.service.spec.ts View on Github external
it('#messages$ should emit a message with the same id a second time, the message in the contact should only exist once', (done) => {
            let messagesSeen = 0;
            chatService.message$.pipe(take(2)).subscribe(contact => {
                expect(contact.messages[0].body).toEqual('message text');
                expect(contact.messages[0].direction).toEqual(Direction.in);
                expect(contact.messages[0].id).toEqual('id');
                messagesSeen++;
                if (messagesSeen === 2) {
                    expect(chatService.getContactById(contact1.jidBare.toString()).messages.length).toEqual(1);
                    done();
                }
            });
            const sampleMessageStanzaWithId = xml('message', {from: contact1.jidBare.toString()},
                xml('origin-id', {id: 'id'}),
                xml('body', {}, 'message text')) as Stanza;
            chatConnectionService.onStanzaReceived(sampleMessageStanzaWithId);
            chatConnectionService.onStanzaReceived(sampleMessageStanzaWithId);
        });
github pazznetwork / ngx-chat / projects / pazznetwork / ngx-chat / src / lib / services / adapters / xmpp / xmpp-chat-adapter.service.spec.ts View on Github external
it('#messages$ should emit a message with the same id a second time, the message in the contact should only exist once', (done) => {
            let messagesSeen = 0;
            chatService.message$.pipe(take(2)).subscribe(contact => {
                expect(contact.messages[0].body).toEqual('message text');
                expect(contact.messages[0].direction).toEqual(Direction.in);
                expect(contact.messages[0].id).toEqual('id');
                messagesSeen++;
                if (messagesSeen === 2) {
                    expect(chatService.getContactById(contact1.jidBare.toString()).messages.length).toEqual(1);
                    done();
                }
            });
            const sampleMessageStanzaWithId = xml('message', {from: contact1.jidBare.toString()},
                xml('origin-id', {id: 'id'}),
                xml('body', {}, 'message text')) as Stanza;
            chatConnectionService.onStanzaReceived(sampleMessageStanzaWithId);
            chatConnectionService.onStanzaReceived(sampleMessageStanzaWithId);
        });
github pazznetwork / ngx-chat / projects / pazznetwork / ngx-chat / src / lib / services / adapters / xmpp / plugins / roster.plugin.spec.ts View on Github external
async function testPresenceAfterShow(show: string) {
            const contact = await setupMockContact();

            expect(contact.presence$.getValue())
                .toEqual(Presence.unavailable);

            const handled = chatAdapter.getPlugin(RosterPlugin).handleStanza(
                xml('presence', {from: 'test@example.com', to: 'me@example.com/resource'},
                    xml('show', {}, show))
            );
            expect(handled).toBeTruthy();

            expect(contact.presence$.getValue())
                .toEqual(Presence.present);
        }
github matrix-org / matrix-bifrost / src / xmppjs / ServiceHandler.ts View on Github external
private notFound(to: string, from: string, id: string, type: string, xmlns: string) {
        this.xmpp.xmppWriteToStream(
            x("iq", {
                type: "error",
                to,
                from,
                id,
            }, x(type, {
                    xmlns,
                },
                x("error", {
                        type: "cancel",
                        code: "404",
                    },
                    x("item-not-found", {
                        xmlns: "urn:ietf:params:xml:ns:xmpp-stanzas",
                    }),
                ),
            )));
    }
github matrix-org / matrix-bifrost / src / xmppjs / ServiceHandler.ts View on Github external
];

        if (profile.displayname) {
            vCard.push(x("FN", undefined, profile.displayname));
            vCard.push(x("NICKNAME", undefined, profile.displayname));
        }

        if (profile.avatar_url) {
            try {
                const res = await this.getThumbnailBuffer(profile.avatar_url, intent);
                if (res) {
                    const b64 = res.data.toString("base64");
                    vCard.push(
                        x("PHOTO", undefined, [
                            x("BINVAL", undefined, b64),
                            x("TYPE", undefined, res.type),
                        ]),
                    );
                }
            } catch (ex) {
                log.warn("Could not fetch avatar for ", account.mxId, ex);
            }
        }

        this.xmpp.xmppWriteToStream(
            x("iq", {
                type: "result",
                to: from,
                from: to,
                id,
            }, x("vCard", {
                    xmlns: "vcard-temp",
github matrix-org / matrix-bifrost / src / xmppjs / ServiceHandler.ts View on Github external
var: "http://jabber.org/protocol/disco#info",
                        }),
                        x("feature", {
                            var: "http://jabber.org/protocol/muc",
                        }),
                    ]),
                ),
            );
        } catch (ex) {
            await this.xmpp.xmppWriteToStream(
                x("iq", {
                    type: "error",
                    to: from,
                    from: toStr,
                    id,
                }, x("query", {
                        xmlns: "http://jabber.org/protocol/disco#info",
                    },
                    x("error", {
                            type: "cancel",
                            code: "404",
                        },
                        x("item-not-found", {
                            xmlns: "urn:ietf:params:xml:ns:xmpp-stanzas",
                        }),
                    ),
                )));
        }
    }