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

XEP-0084 User Avatar

Publish avatar data

Image data can be published using the following method. Note: Published images should be of png type.

        socket.send(
            'xmpp.avatar.upload'
            { 
                "content": "... IMAGE DATA ...",
             /* "id": "sha-1 of the image data"
            },
            function(error, data) { console.log(error, data) }
        )
        

If no id is provided then a sha-1 hash will be calculated on the server and returned to the user as part of the result response.

Example response:

        {
          id: 'sha-1 of the image data'
        }
        

Publish avatar meta data

        socket.send(
            'xmpp.avatar.metadata',
            {
                "bytes": "1234",
                "id": "sha-1 of image data",
                "type": "image/png",
             /* "width": 64, */
             /* "height": 64, */
             /* "url": "http://evilprofessor.co.uk/avatar.png", */
             /* "additional": [ ], */
             /* "disable": true */
            },
            function(error, data) { console.log(error, data) }
        )
        

On successful publishing of metadata the data parameter will simply have a value of true.

If a value of true is passed for the disable key then avatar metadata publishing is disabled, all other data is ignored.

If the user wishes to provide additional avatars located at some URL &/or in another format then this can be completed using the additional key. Additional avatars should use the same fields as the main metadata information and also the url key will be required.

        {
            "additional": [
                {
                    "bytes": 988,
                    "id": "sha-1 of the jpeg avatar",
                    "url": "http://evilprofessor.co.uk/avatar.jpg",
                    "type": "image/jpeg"
                },
                {
                    "bytes": 1344,
                    "id": "sha-1 of the gif avatar",
                    "url": "http://evilprofessor.co.uk/avatar.gif",
                    "type": "image/gif"
                }
            ]
        }
        

See http://xmpp.org/extensions/xep-0084.html#example-10 .

Retrieve avatar data

In order to retrieve a user's avatar data the following call is made. Avatar ID can come from a presence update or meta data retrieval (see later).

        socket.send(
            'xmpp.avatar.data'
            { 
                "of": "lloyd@evilprofessor.co.uk",
                "id": " ...123456abcdef... "
            },
            function(error, data) { console.log(error, data) }
        )
        

A successful response will return data as follows:

        {
            content: "... IMAGE DATA ..."
        }
        

Notifications

Notifications to updates to avatar meta data are recieved as follows:

        {
            "from": {
                "domain": "evilprofessor.co.uk",
                "user": "lloyd"
            },
            "avatars": [
                {
                    "bytes": 1235,
                    "type": "image/png",
                    "id": "... sha-1 of image data ..."
                },
                {
                    "bytes": 998,
                    "type": "image/jpeg",
                    "id": "... sha-1 of jpeg image data ..."
                }
            ]
        }
        

If avatar publishing has been disabled by the remote user then the avatars key will not be present and a key of disabled will be present and have a value of true.

Pages

Fork me on GitHub