Skip to content
Permalink
Browse files

Update stream management doc

  • Loading branch information...
legastero committed Jul 10, 2019
1 parent 4b146a8 commit ddb4a1362b794165cc7f4b042135bca7bd9a605c
Showing with 8 additions and 6 deletions.
  1. +6 −4 docs/Using_Stream_Management.md
  2. +1 −1 src/client.js
  3. +1 −1 src/plugins/carbons.js
@@ -8,7 +8,7 @@

Stream management is enabled automatically if your server offers it during stream negotiation.

You can turn it _off_ if necessary when configuring a client:
You can turn it off, if necessary, when configuring a client:

```typescript
import * as XMPP from 'stanza';
@@ -62,9 +62,9 @@ const messageStorage = new Map();
Then we need to track every message that we send:

```typescript
client.on('message:sent', msg => {
client.on('message:sent', (msg, viaCarbon) => {
messageStorage.set(msg.id, {
serverReceived: false,
serverReceived: viaCarbon,
mucReceived: false,
failedToSend: false
});
@@ -75,7 +75,9 @@ Now, there are several things that should be noted at this point.

First, we use the `message:sent` event to capture the `id` of outgoing messages instead of using the return value of `client.sendMessage()` or manually generating and passing `id` values to `sendMessage()`. Doing it this way ensures we capture _all_ outgoing messages, without worrying about where `sendMessage()` was called.

Second, we are storing three flags to represent multiple situations:
Second, we are looking at the `viaCarbon` flag to distinguish if this was a message sent locally, or it came from a [XEP-0280 message carbon](https://xmpp.org/extensions/xep-0280.html). If it came from a carbon, then the server has clearly received the original message.

Third, we are storing three flags to represent multiple situations:

- The server has received our message.
- If we are sending a message to a MUC, the MUC service has received our message.
@@ -341,7 +341,7 @@ export default class Client extends WildEmitter {
}
const Message = this.stanzas.getMessage();
const msg = new Message(data);
this.emit('message:sent', msg.toJSON());
this.emit('message:sent', msg.toJSON(), false);
this.send(msg);
return data.id;
}
@@ -60,7 +60,7 @@ export default function(client) {
// Treat the carbon copied message however we would
// have originally treated it ourself.
if (msg.from.bare === client.jid.bare) {
client.emit('message:sent', msg);
client.emit('message:sent', msg, true);
} else {
client.emit('message', msg);
}

0 comments on commit ddb4a13

Please sign in to comment.
You can’t perform that action at this time.