XMPP For The Web/Win ::: XMPP-FTW (1.18.0) Flattr this

XEP-0009 Jabber RPC

Make a request

In order to make a request we use the `xmpp.rpc.perform` event as follows:

    socket.send(
        'xmpp.rpc.perform',
        {
            "to": "rpc.evilprofessor.co.uk",
            "method": "server.restart",
         /* "params": [] */
        },
        function(error, data) { console.log(error, data) }
    )
    

For more information about parameters in JSON see here.

Results from a request

Results are returned as follows:

    [
        { type: 'string', value: 'restarting' }
    ]
    

Again see the section on parameters for more information.

Receive a request

It is also possible to receive RPCs and these appear as follows:

    socket.on('xmpp.rpc.request', function(data) {
        console.log(data)
    })
    

With data looking a follows:

    {
        from: 'rpc.evilprofessor.co.uk',
        method: 'client.restart',
        id: 'rpc:request:1',
     /* params: [] */
    }
    

Responding to a request

Respond to a request as follows using the `xmpp.rpc.result` event:

    socket.send(
        'xmpp.rpc.result',
        {
            "to": "rpc.evilprofessor.co.uk",
            "id": "rpc:request:1",
         /* "params": [] */
        },
        function(error, data) { console.log(error, data) }
    )

The callback here is optional, if provided it can be used to receive errors (else `xmpp.client.error` is used. On successful sending of the message the data argument will simply be true.

Parameters in JSON

The general format for parameters is as follows:

    { type: %type%, value: %value% }
    

Valid XMPP types are:

This plugin does not check types (but will perform conversion where possible, and non-standard types may be ignored.

struct and array may be nested and examples will be given below:

    [
        { type: 'boolean', value: true },
        { type: 'i4', value: '123' },
        { type: 'int', value: '999' },
        { type: 'double', value: '10.66' },
        { type: 'string', value: 'a string' },
        { type: 'base64', value: 'ba5e64' },
        { type: 'dateTime.iso8601', value: '2013-10-16T09:00:00Z' },
        /* Array */
        { type: 'array', value: [
            { type: 'string', value: 'one' },
            { type: 'int', value: 2 }
        ]},
        /* Nested array */
        { type: 'array', value: [{
            type: 'array',
            value: [
                { type: 'int', value: 2 }
            ]
        }]},
        /* Struct */
        { type: 'struct', value: [
            { type: 'string', value: 'one', name: 'PageNumber' },
            { type: 'int', value: 2, name: 'RPP' }
        ]},
        /* Nested struct */
        { type: 'struct', value: [{
            type: 'struct',
            value: [
                { type: 'int', value: 2, name: 'PageNumber' }
            ],
            name: 'Paging'
        }]}
    ]
    

Pages

Fork me on GitHub