JID
XMPP identifiers (JID) for JavaScript
JID type | local | @ | domain | / | resource | usage |
---|---|---|---|---|---|---|
domain | wonderland.net | servers and components | ||||
bare | alice | @ | wonderland.net | users | ||
full | alice | @ | wonderland.net | / | rabbithole | user resource (device) |
https://en.wikipedia.org/wiki/XMPP#Decentralization_and_addressing
Usage
var JID = /* * All return an instance of JID.JID, the new operator is optional. */var addr = 'alice@wonderland.net/rabbithole' // OKvar addr = JID`@/` // OK, es6 tagged template stringvar addr = 'alice' 'wonderland.net' 'rabbithole' // BEST; see section on escaping below addr instanceof JIDJID // true // domain JIDs are created passing the domain as the first argumentvar addr = /* * local */addrlocal = 'alice'addrlocal // alice// same asaddraddr // alice /* * domain */addrdomain = 'wonderland.net'addrdomain // wonderland.net// same asaddraddr // wonderland.net /* * resource */addrresource = 'rabbithole'addrresource // rabbithole// same asaddraddr // rabbithole addr // alice@wonderland.net/rabbitholeaddr // returns a JID without resource addr // returns true if the two JIDs are equal, false otherwise// same asJID JID // returns true if the passed argument is an instance of JID.JID, false otherwise
Escaping
The XEP-0106 defines a method to escape and unescape characters that aren't allowed in the local part of the JID. This library fully implement it but because @
and /
are ones of them and used as JID separators, you should always prefer the following syntax
// GOODlocal domain resource
over
// BADlocal@domain/resource
for user input.
References
- RFC 7622 XMPP Address Format mostly implemented, l10n WIP
- XEP-0106 JID Escaping implemented