Switch branches/tags
Nothing to show
Find file History
Pull request Compare This branch is 321 commits behind metajack:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Jabber-RPC Module

A strophe plugin for Jabber-RPC extension (XEP-0009).

See the XEP abstract :

This specification defines an XMPP protocol extension for transporting XML-RPC encoded requests and responses between two XMPP entities. The protocol supports all syntax and semantics of XML-RPC except that it uses XMPP instead of HTTP as the underlying transport.

This plugin does not aim at managing your flow of RPC. It is a simple helper to send and handle remote requests between two XMPP nodes.


Just link the rpc plugin below the strophe library in your HTML head section:

<!-- ... -->
<script type="text/javascript" src="strophe.min.js"></script>
<script type="text/javascript" src="strophe.rpc.js"></script>
<!-- ... -->

It's preferable to also use the service discovery plugin to respond correctly to disco#info requests. You can download it and add it as follow :

<!-- ... -->
<script type="text/javascript" src="strophe.min.js"></script>
<script type="text/javascript" src="strophe.disco.js"></script>
<script type="text/javascript" src="strophe.rpc.js"></script>
<!-- ... -->


The plugin prototype is accessible from the connection.rpc variable

Send an RPC

There are four functions to send RPC :

  • sendRequest(id, to, method, params)
    • method is the string name of the method to call
    • params is an array of parameters to send
  • sendResponse(id, to, result)
    • result is the object to send as the result of the request
  • sendError(id, to, code, message)
    • code is the number of the error
    • message is the message describing the error
  • sendXMLElement(id, to, xml)
    • xml is the XML Element that will be sent (whether it is properly formed or not)

The parameters id and to are respectively the id of the request and the the jid of the recipient.

Handle incoming RPCs

It is possible to handle incoming RPCs using the functions :

  • addRequestHandler
  • addResponseHandler
  • addXMLHandler

The handlers you pass to these functions take different parameters :

var responseHandler = function(id, from, result, error) {
	// error is a boolean
	// it is true if the response was an error message
	if (error === true) { ... }
	else { ... }

var requestHandler = function(id, from, method, parameters) { ... }

var xmlHandler = function(xml) { ... }

Note that the parser of this module won't throw any exception. However result, method and parameters will be set as null if the incoming message is not XML-RPC compliant.


By default, this plugin will accept RPC from everyone. However, it is possible to use a whitelist of JID to filter incoming RPCs.

Use the function addJidToWhiteList to accept JIDs. Note that it is possible to use a wildcard for the node or the domain.

Examples :

connection.rpc.addJidToWhiteList(["*@jabber.org", "me@*"]);

Tests & specs

I use the node module jasmine-runner for the tests. Install it and use it as follow :

$ npm install jasmine-runner
$ jasmine mon

The tests run in the browser at the address localhost:8124.