-
new Client(options)createClient(options)ClientMethodsclient.use(plugin)client.on(event, [group], handler)client.connect([opts])client.disconnect()client.sendIq(opts)client.sendMessage(opts)client.sendPresence(opts)client.sendStreamError(opts)- Keepalive
- Roster Management
- Service Discovery
- Jingle
- Pubsub
client.createNode(jid, node, [cb])client.deleteNode(jid, node, [cb])client.getItem(jid, node, id, [cb])client.getItems(jid, node, opts, [cb])client.publish(jid, node, item, [cb])client.purgeNode(jid, node, [cb])client.retract(jid, node, id, notify, [cb])client.subscribeToNode(jid, opts, [cb])client.unsubscribeFromNode(jid, opts, [cb])
- Multi-User Chat
client.ban(room, jid, reason, [cb])client.changeNick(room, nick)client.configureRoom(room, form, [cb])client.directInvite(room, sender, reason)client.discoverReservedNick(room, [cb])client.getRoomConfig(jid, [cb])client.getRoomMembers(room, opts, [cb])client.getUniqueRoomName(jid, [cb])client.invite(room, opts)client.joinRoom(room, nick, opts)client.kick(room, nick, reason, [cb])client.leaveRoom(room, nick, opts)client.requestRoomVoice(room)client.setRoomAffiliation(room, jid, affiliation, reason, [cb])client.setRoomRole(room, nick, role, reason, [cb])client.setSubject(room, subject)client.addBookmark(bookmark, [cb])client.getBookmarks([cb])client.removeBookmark(jid, [cb])client.setBookmarks(opts, [cb])
- Message Syncing
- Other
client.deleteAccount([jid, cb])client.getAccountInfo([jid, cb])client.getAttention(jid, [opts])client.getAvatar(jid, id, [cb])client.getCommands(jid, [cb])client.getPrivateData(opts, [cb])client.getSoftwareVersion(jid, [cb])client.getTime(jid, [cb])client.getVCard(jid, [cb])client.goInvisible([cb])client.goVisible([cb])client.markActive()client.markInactive()client.publishAvatar(id, data, [cb])client.publishGeoLoc(data, [cb])client.publishMood(mood, text, [cb])client.publishNick(nick, [cb])client.publishReachability(data, [cb])client.publishTune(data, [cb])client.publishVCard(vcard, [cb])client.sendLog(jid, opts)client.setPrivateData(opts, [cb])client.updateAccount(jid, data, [cb])client.useAvatars(data, [cb])
-
attentionauth:failedauth:successavailableavatarblockbosh:terminatecarbon:receivedcarbon:sentchat:statechatconnectedcredentials:updatedataformdisco:capsdisconnectedgeolocgroupchatid:IDiq:get:NAMEiq:set:NAMEjingle:acceptedjingle:holdjingle:incomingjingle:localstream:addedjingle:localstream:removedjingle:mutejingle:outgoingjingle:remotestream:addedjingle:remotestream:removedjingle:resumedjingle:ringingjingle:terminatedjingle:unmutemessage:errormessage:sentmessagemuc:availablemuc:declinedmuc:destroyedmuc:errormuc:invitemuc:joinmuc:leavemuc:subjectmuc:unavailablenickpresence:errorpresencepubsub:eventraw:incomingraw:outgoingreachabilityreceipt[:ID]replace[:ID]roster:updateroster:versasl:abortsasl:challengesasl:failuresasl:successsession:boundsession:endsession:errorsession:startedstanzastream:datastream:endstream:errorstream:management:enabledstream:management:failedstream:management:resumedsubscribesubscribedunavailableunblockunsubscribeunsubscribed
Creates a new XMPP client instance, with no plugins loaded.
options- An object with the client configuration as described in client options.
var XMPP = require('stanza.io');
var client = new XMPP.Client({
jid: '[email protected]',
password: 'hunter2'
});An alternative method for creating a client instance.
Instantiating a client via this function will load all built-in plugins.
options- An object with the client configuration as described in client options.
var XMPP = require('stanza.io');
var client = XMPP.createClient({
jid: '[email protected]',
password: 'hunter2'
});When creating a client instance, the following settings will configure its behaviour:
-
jid- (required) the requested bare JID for the client. password- shortcut for settingcredentials.passwordserver- specify the hostname of the server to initially connect to, if different fromjid.domain.resource- suggest a specific resource for this session.credentialsusername- username you're presenting for auth. Typically the local portion of the JID, but could be differentpassword- just like it soundshost- the domain of the serviceserverKey- cached credential created bySCRAM-SHA-1, that can be used without needing to know the passwordclientKey- cached credential created bySCRAM-SHA-1, that can be used without needing to know the passwordsaltedPassword- cached credential created bySCRAM-SHA-1, that can be used without needing to know the passwordserviceType- for most cases should be'XMPP', the defaultserviceName- for most cases should be the same as the'host', the defaultrealm- for most cases should be the same as the'host', the defaultauthzid-
transports- a strings array of transport methods that may be used.wsURL- URL for the XMPP over WebSocket connection endpoint.boshURL- URL for the BOSH connection endpoint.sasl- a list of the SASL mechanisms that are acceptable for use by the client.useStreamManagement- set totrueto enable resuming the session after a disconnect.rosterVer- version ID of cached roster data given by the server, typically saved from a previous session.capsNode- a URL for identifying the client app.softwareVersionname- the name of the client software using stanza.ioversion- the version of the client software using stanza.ioos- the operating system that the client is running on
timeout- number of seconds that IQ requests will wait for a response before generating a timeout error.lang- preferred language used by the client, such as'en'or'de'.
Fetch the jids of all available rooms Example:
client.getDiscoItems('conference.xxx.yyy.zz','', (err, data) => {
//Get list of available rooms
}
Request to join a Multi-User Chat room.
room- The bare JID of the room to joinnick- The requested nickname to use in the room. Note: You are not guaranteed to be assigned this nick.options- Additional presence information to attach to the join request, in particular:joinMuc- A dictionary of options for how to join the room:password- Optional password for entering the roomhistory- May betrueto receive the room's default history replay, or may specifymaxstanzas,seconds, orsinceto specify a history replay range in terms of number of messages, a given time range, or since a particular time.
client.joinRoom('[email protected]', 'User', {
status: 'This will be my status in the MUC',
joinMuc: {
password: 'hunter2',
history: {
maxstanzas: 20
}
}
});Enable carbon messages. This is useful if you want to receive a copy of a message that you sent from one device, and receive on all other logged devices.
Fetch chat history for the specified jid. By default, you will receive all the messages. Optionally you can pass an object to get max number of messages. Example:
client.searchHistory({
with: jid,
rsm: {max: 50, before: true}, --
complete: false
}
Creates a new JID (Jabber IDentifier) object, which represents an address in the XMPP network.
jid- a string of the form[username@]domain[/resource](or an existingJIDobject)
var someServer = new JID('somedomain.example.com');
var friendAddress = new JID('[email protected]');
var addressOfParticularConnection = new JID('[email protected]/laptopclient');All JID objects expose the following properties:
local- If theJIDis of the form'[email protected]', then thelocalvalue would be the'user'portiondomain- If theJIDis of the form'[email protected]'(or'example.com'), then thedomainvalue would be'example.com'resource- If theJIDis of the form'[email protected]/res'(or even'example.com/res'), then theresourcevalue would be'res'bare- The bareJIDcontains only the local and domain sections, eg'[email protected]'full- The fullJIDcontains the local, domain, and resource sections, eg'[email protected]/res'
Example:
{
type: 'chat',
to: JID,
from: JID,
body: 'this is a chat'
}
Example:
{
type: 'chat',
to: JID,
from: JID,
chatState: 'composing'
}
Example:
{
to: JID,
from: JID,
caps: {
hash: 'sha-1',
node: 'https://stanza.io',
ver: 'rs/tl9NCfXBpKoOYUy+JdBbPGDg='
}
}
Example:
{
type: 'subscribe',
to: JID,
from: JID
}
Example:
{
type: 'unsubscribed',
to: JID,
from: JID
}