Skip to content

Commit

Permalink
Update stream management doc
Browse files Browse the repository at this point in the history
  • Loading branch information
legastero committed Jul 10, 2019
1 parent 4b146a8 commit ddb4a13
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions docs/Using_Stream_Management.md
Expand Up @@ -8,7 +8,7 @@


Stream management is enabled automatically if your server offers it during stream negotiation. 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 ```typescript
import * as XMPP from 'stanza'; import * as XMPP from 'stanza';
Expand Down Expand Up @@ -62,9 +62,9 @@ const messageStorage = new Map();
Then we need to track every message that we send: Then we need to track every message that we send:


```typescript ```typescript
client.on('message:sent', msg => { client.on('message:sent', (msg, viaCarbon) => {
messageStorage.set(msg.id, { messageStorage.set(msg.id, {
serverReceived: false, serverReceived: viaCarbon,
mucReceived: false, mucReceived: false,
failedToSend: false failedToSend: false
}); });
Expand All @@ -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. 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. - The server has received our message.
- If we are sending a message to a MUC, the MUC service has received our message. - If we are sending a message to a MUC, the MUC service has received our message.
Expand Down
2 changes: 1 addition & 1 deletion src/client.js
Expand Up @@ -341,7 +341,7 @@ export default class Client extends WildEmitter {
} }
const Message = this.stanzas.getMessage(); const Message = this.stanzas.getMessage();
const msg = new Message(data); const msg = new Message(data);
this.emit('message:sent', msg.toJSON()); this.emit('message:sent', msg.toJSON(), false);
this.send(msg); this.send(msg);
return data.id; return data.id;
} }
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/carbons.js
Expand Up @@ -60,7 +60,7 @@ export default function(client) {
// Treat the carbon copied message however we would // Treat the carbon copied message however we would
// have originally treated it ourself. // have originally treated it ourself.
if (msg.from.bare === client.jid.bare) { if (msg.from.bare === client.jid.bare) {
client.emit('message:sent', msg); client.emit('message:sent', msg, true);
} else { } else {
client.emit('message', msg); client.emit('message', msg);
} }
Expand Down

0 comments on commit ddb4a13

Please sign in to comment.