https://github.com/strophe/strophejs-plugin-rsm
https://github.com/strophe/strophejs-plugin-rsm
Last synced: 9 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/strophe/strophejs-plugin-rsm
- Owner: strophe
- License: mit
- Created: 2017-01-25T13:38:33.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-07-14T21:07:28.000Z (almost 9 years ago)
- Last Synced: 2024-11-09T15:07:40.174Z (over 1 year ago)
- Language: JavaScript
- Size: 6.84 KB
- Stars: 2
- Watchers: 15
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# strophe.rsm.js
Plugin for [strophe.js](https://www.npmjs.com/package/strophe.js) providing Result Set Management (RSM) [XEP-0059](http://xmpp.org/extensions/xep-0059.html).
## Install
```bash
npm install strophejs-plugin-rsm
```
### ES6
```js
import 'strophejs-plugin-rsm';
```
### Browser
``` html
```
## Usage
Make sure [Strophe](https://www.npmjs.com/package/strophe.js) is installed and the plugin is imported into your app. With RSM is available to do paged stanza requests like so:
```js
require('strophejs-plugin-rsm');
var connection = new Strophe.Connection('wss://...');
var options = {
before: '',
isGroup: false,
max: 50,
};
var messages = [];
var queryid = connection.getUniqueId();
var stanza = $iq({ type: 'set' }).c('query', { xmlns: Strophe.NS.MAM, queryid });
var node = new Strophe.RSM(options);
stanza.cnode(node.toXML());
connection.addHandler((message: any) => {
var fin = getElementByTagName(message, 'fin', Strophe.NS.MAM);
var result = getElementByTagName(message, 'result', Strophe.NS.MAM);
if (fin && queryid === fin.getAttribute('queryid')) {
var paging = new Strophe.RSM({ xml: fin });
// `paging` is now our paged RSM object with the following attributes:
// paging.next()
// paging.previous()
// paging.toXML()
// paging.fromXMLElement()
return false;
} else if (result && queryid === result.getAttribute('queryid')) {
messages.push(message);
}
return true;
}, Strophe.NS.MAM);
connection.sendIQ(stanza, null, null);
```