Book Image

Practical XMPP

By : Lloyd Watkin, Steven Watkin, Koelle
Book Image

Practical XMPP

By: Lloyd Watkin, Steven Watkin, Koelle

Overview of this book

XMPP (eXtensible Messaging and Presence Protocol) is a messaging protocol that enables communication between two or more devices via the Internet. With this book, developers will learn about the fundamentals of XMPP, be able to work with the core functionality both server-side and in the browser, as well as starting to explore several of the protocol extensions. You will not only have a solid grasp of XMPP and how it works, but will also be able to use the protocol to build real-world applications that utilize the power of XMPP. By the end of this book, you will know more about networking applications in general, and have a good understanding of how to extend XMPP, as well as using it in sample applications.
Table of Contents (11 chapters)
Free Chapter
1
1. An Introduction to XMPP and Installing Our First Server

Telling the server we're online


Once the client is connected, we'll need to tell the server that we're online so that it knows to route any stanzas sent to the bare JID (bot@localhost) through to our script. To do this, we'll need to build a stanza using the library that comes as part of node-xmpp-client called Less than XML or ltx.

We can access ltx via the client object we loaded earlier. To send the presence data, we must first be online, so we'll add a function call in that event to send a presence stanza. Our code now becomes:

const Client = require('node-xmpp-client') 
  , ltx = Client.ltx 
 
const options = { 
  jid: 'bot@localhost', 
  password: 'tellnoone' 
} 
const client = new Client(options) 
client.on('online', (connectionDetails) => { 
  console.log('We are connected!') 
  console.log(connectionDetails) 
  sendPresence() 
}) 
 
const sendPresence = () => { 
  var stanza = new ltx.Element('presence...