How to use @xmpp/jid - 10 common examples

To help you get started, we’ve selected a few @xmpp/jid 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 DefinitelyTyped / DefinitelyTyped / types / xmpp__jid / xmpp__jid-tests.ts View on Github external
import { JID } from '@xmpp/jid';

/*
 * All return an instance of JID.JID, the new operator is optional.
 */
let addr = new JID('alice@wonderland.net/rabbithole');          // OK
addr = new JID('alice', 'wonderland.net', 'rabbithole');    // BEST; see section on escaping below

/*
 * local
 */
addr.local = 'alice';
addr.local;      // alice
// same as
addr.setLocal('alice');
addr.getLocal(); // alice

/*
 * domain
 */
addr.domain = 'wonderland.net';
addr.domain;      // wonderland.net
// same as
github DefinitelyTyped / DefinitelyTyped / xmpp__jid / xmpp__jid-tests.ts View on Github external
import {JID} from '@xmpp/jid';

/*
 * All return an instance of JID.JID, the new operator is optional.
 */
let addr = new JID('alice@wonderland.net/rabbithole');          // OK
addr = new JID('alice', 'wonderland.net', 'rabbithole');    // BEST; see section on escaping below

/*
 * local
 */
addr.local = 'alice';
addr.local;      // alice
// same as
addr.setLocal('alice');
addr.getLocal(); // alice

/*
 * domain
 */
addr.domain = 'wonderland.net';
addr.domain;      // wonderland.net
// same as
github DefinitelyTyped / DefinitelyTyped / types / xmpp__jid / xmpp__jid-tests.ts View on Github external
addr.setDomain('wonderland.net');
addr.getDomain(); // wonderland.net

/*
 * resource
 */
addr.resource = 'rabbithole';
addr.resource;      // rabbithole
// same as
addr.setResource('rabbithole');
addr.getResource(); // rabbithole

addr.toString(); // alice@wonderland.net/rabbithole
addr.bare();     // returns a JID without resource

const some_jid = new JID('is', 'a', 'test');
addr.equals(some_jid); // returns true if the two JIDs are equal, false otherwise
github DefinitelyTyped / DefinitelyTyped / types / xmpp__jid / xmpp__jid-tests.ts View on Github external
import { JID } from '@xmpp/jid';

/*
 * All return an instance of JID.JID, the new operator is optional.
 */
let addr = new JID('alice@wonderland.net/rabbithole');          // OK
addr = new JID('alice', 'wonderland.net', 'rabbithole');    // BEST; see section on escaping below

/*
 * local
 */
addr.local = 'alice';
addr.local;      // alice
// same as
addr.setLocal('alice');
addr.getLocal(); // alice

/*
 * domain
 */
addr.domain = 'wonderland.net';
addr.domain;      // wonderland.net
github DefinitelyTyped / DefinitelyTyped / xmpp__jid / xmpp__jid-tests.ts View on Github external
addr.setDomain('wonderland.net');
addr.getDomain(); // wonderland.net

/*
 * resource
 */
addr.resource = 'rabbithole';
addr.resource;      // rabbithole
// same as
addr.setResource('rabbithole');
addr.getResource(); // rabbithole

addr.toString(); // alice@wonderland.net/rabbithole
addr.bare();     // returns a JID without resource

const some_jid = new JID('is', 'a', 'test');
addr.equals(some_jid); // returns true if the two JIDs are equal, false otherwise
github DefinitelyTyped / DefinitelyTyped / xmpp__jid / xmpp__jid-tests.ts View on Github external
import {JID} from '@xmpp/jid';

/*
 * All return an instance of JID.JID, the new operator is optional.
 */
let addr = new JID('alice@wonderland.net/rabbithole');          // OK
addr = new JID('alice', 'wonderland.net', 'rabbithole');    // BEST; see section on escaping below

/*
 * local
 */
addr.local = 'alice';
addr.local;      // alice
// same as
addr.setLocal('alice');
addr.getLocal(); // alice

/*
 * domain
 */
addr.domain = 'wonderland.net';
addr.domain;      // wonderland.net
github matrix-org / matrix-bifrost / src / xmppjs / XJSInstance.ts View on Github external
public getAccount(username: string, protocolId: string, mxid: string): IPurpleAccount|null {
        const j = jid(username);
        if (j.domain === this.myAddress.domain &&
            j.local.startsWith("#") &&
            this.serviceHandler.parseAliasFromJID(j)) {
            // Account is an gateway alias, not trying.
            return null;
        }
        const uLower = username.toLowerCase();
        log.debug("Getting account", username);
        if (protocolId !== "xmpp-js") {
            return null;
        }
        if (this.accounts.has(uLower)) {
            return this.accounts.get(uLower)!;
        }
        const acct = new XmppJsAccount(username, this.defaultRes, this, mxid);
        this.accounts.set(uLower, acct);
github matrix-org / matrix-bifrost / src / xmppjs / XJSInstance.ts View on Github external
private async handleMessageStanza(stanza: Element, alias: string|null) {
        if (!stanza.attrs.from || !stanza.attrs.to) {
            return;
        }
        const to = jid(stanza.attrs.to)!;
        let localAcct: any = this.accounts.get(`${to!.local}@${to!.domain}`)!;
        let from = jid(stanza.attrs.from);
        let convName = `${from.local}@${from.domain}`;

        if (alias) {
            // If this is an alias, we want to do some gateway related things.
            if (!to.resource) {
                // Group message to a MUC, so reflect it to other XMPP users
                // and set the right to/from addresses.
                convName = `${to.local}@${to.domain}`;
                log.info(`Sending gateway group message to ${convName}`);
                if (!this.gateway!.reflectXMPPMessage(convName, stanza)) {
                    log.warn(`Message could not be sent, not forwarding to Matrix`);
                    return;
                }
                stanza.attrs.from = this.gateway!.getAnonIDForJID(
github matrix-org / matrix-bifrost / src / xmppjs / XJSInstance.ts View on Github external
private async handleMessageStanza(stanza: Element, alias: string|null) {
        if (!stanza.attrs.from || !stanza.attrs.to) {
            return;
        }
        const to = jid(stanza.attrs.to)!;
        let localAcct: any = this.accounts.get(`${to!.local}@${to!.domain}`)!;
        let from = jid(stanza.attrs.from);
        let convName = `${from.local}@${from.domain}`;

        if (alias) {
            // If this is an alias, we want to do some gateway related things.
            if (!to.resource) {
                // Group message to a MUC, so reflect it to other XMPP users
                // and set the right to/from addresses.
                convName = `${to.local}@${to.domain}`;
                log.info(`Sending gateway group message to ${convName}`);
                if (!this.gateway!.reflectXMPPMessage(convName, stanza)) {
                    log.warn(`Message could not be sent, not forwarding to Matrix`);
                    return;
                }
                stanza.attrs.from = this.gateway!.getAnonIDForJID(
                    convName, stanza.attrs.from) || false;
                if (stanza.attrs.from === false) {
github matrix-org / matrix-bifrost / src / xmppjs / XJSInstance.ts View on Github external
private handlePresenceStanza(stanza: Element, gatewayAlias: string|null) {
        const to = jid(stanza.getAttr("to"));
        // XMPP is case insensitive.
        const localAcct = this.accounts.get(`${to.local}@${to.domain}`);
        const from = jid(stanza.getAttr("from"));
        const convName = `${from.local}@${from.domain}`;
        const delta = this.presenceCache.add(stanza);

        if (!delta) {
            return;
        }

        if (delta.error && localAcct) {
            if (delta.error === "conflict") {
                log.info(`${from.toString()} conflicted with another user, attempting to fix`);
                localAcct.xmppRetryJoin(from).catch((err) => {
                    log.error("Failed to retry join", err);
                });

@xmpp/jid

XMPP identifiers (JID) for JavaScript

ISC
Latest version published 3 years ago

Package Health Score

68 / 100
Full package analysis

Popular @xmpp/jid functions