-
new Client(options)
createClient(options)
Client
Methodsclient.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])
-
attention
auth:failed
auth:success
available
avatar
block
bosh:terminate
carbon:received
carbon:sent
chat:state
chat
connected
credentials:update
dataform
disco:caps
disconnected
geoloc
groupchat
id:ID
iq:get:NAME
iq:set:NAME
jingle:accepted
jingle:hold
jingle:incoming
jingle:localstream:added
jingle:localstream:removed
jingle:mute
jingle:outgoing
jingle:remotestream:added
jingle:remotestream:removed
jingle:resumed
jingle:ringing
jingle:terminated
jingle:unmute
message:error
message:sent
message
muc:available
muc:declined
muc:destroyed
muc:error
muc:invite
muc:join
muc:leave
muc:subject
muc:unavailable
nick
presence:error
presence
pubsub:event
raw:incoming
raw:outgoing
reachability
receipt[:ID]
replace[:ID]
roster:update
roster:ver
sasl:abort
sasl:challenge
sasl:failure
sasl:success
session:bound
session:end
session:error
session:started
stanza
stream:data
stream:end
stream:error
stream:management:enabled
stream:management:failed
stream:management:resumed
subscribe
subscribed
unavailable
unblock
unsubscribe
unsubscribed
Creates a new XMPP client instance.
Instantiating a client via this function will not load any built-in plugins.
options
- An object with the client configuration as described in client options.
var XMPP = require('stanza.io');
var client = new XMPP.Client({
jid: 'test@example.com',
password: 'hunter2'
});
// Loading plugins
var plugins = require('stanza.io/lib/plugins');
client.use(plugins)
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: 'test@example.com',
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.password
server
- specify the hostname of the server to initially connect to, if different fromjid.domain
.resource
- suggest a specific resource for this session.credentials
username
- 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
-
sendReceipts
- boolean value to determine whether or not client automatically sends acknowledgements if they are requested (XEP-0184). Default value is true, set to false if you want to send acknowledgements yourself.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 totrue
to 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.softwareVersion
name
- 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'
.
Load a plugin.
Example:
client.use(myAwesomePlugin);
Listen for an event.
Example:
client.on('chat', chat => {
// chat event handler
});
Send a message.
Example:
client.sendMessage({
to: JID,
body: "Hello!"
});
Send presence to the server.
client.on('session:started', () => {
client.getRoster(() => {
client.sendPresence();
})
});
Note the session:started
. You'll need to send your presence immediately to get presence from rosters.
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 betrue
to receive the room's default history replay, or may specifymaxstanzas
,seconds
, orsince
to specify a history replay range in terms of number of messages, a given time range, or since a particular time.
Example:
client.joinRoom('room@muc.example.com', '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.
Example:
client.on('session:started', () => {
client.sendPresence();
client.enableCarbons();
});
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 existingJID
object)
var someServer = new JID('somedomain.example.com');
var friendAddress = new JID('friend@example.com');
var addressOfParticularConnection = new JID('me@example.com/laptopclient');
All JID
objects expose the following properties:
local
- If theJID
is of the form'user@example.com'
, then thelocal
value would be the'user'
portiondomain
- If theJID
is of the form'user@example.com'
(or'example.com'
), then thedomain
value would be'example.com'
resource
- If theJID
is of the form'user@example.com/res'
(or even'example.com/res'
), then theresource
value would be'res'
bare
- The bareJID
contains only the local and domain sections, eg'user@example.com'
full
- The fullJID
contains the local, domain, and resource sections, eg'user@example.com/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:
client.on('message', (message) => {
/*
{
from: JID,
to: JID,
body: 'Message',
}
*/
})
I order to get presence, you have to send your presence first when session starts.
Example:
client.on('session:started', () => {
client.sendPresence();
});
client.on('presence', (presence) => {
/*
{ lang:"en",
id:"12345",
to: JID,
from: JID,
priority:0,
type:"available" // Type
}
*/
});
You will get pretty much any data going through your client as raw XML. Great for debugging.
Example:
client.on('raw:incoming', (xml) => {
/*
<presence xmlns="jabber:client" to="jid@example.com" type="chat" id="id" from="jid2@example.com" />
<message xmlns="jabber:client" to="jid@example.com" type="chat" id="id" from="jid2@example.com">
<body>Hi!</body>
</message>
*/
});
Same as raw:incoming, only for outgoing.
Example:
client.on('raw:outgoing', (xml) => {
/*
<presence xmlns="jabber:client" to="jid@example.com" type="chat" id="id" from="jid2@example.com" />
<message xmlns="jabber:client" to="jid@example.com" type="chat" id="id" from="jid2@example.com">
<body>Hi!</body>
</message>
*/
});
Example:
{
type: 'subscribe',
to: JID,
from: JID
}
Example:
{
type: 'unsubscribed',
to: JID,
from: JID
}