Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
395 changes: 212 additions & 183 deletions CHANGELOG.md

Large diffs are not rendered by default.

49 changes: 45 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,51 @@ XMPP applications.

## Quick Links

* [Homepage](https://strophe.im/strophejs/)
* [Documentation](https://strophe.im/strophejs)
* [Mailing list](https://groups.google.com/g/strophe)
* [Community Plugins](https://github.com/strophe/strophejs-plugins)
- [Homepage](https://strophe.im/strophejs/)
- [Documentation](https://strophe.im/strophejs)
- [Mailing list](https://groups.google.com/g/strophe)
- [Community Plugins](https://github.com/strophe/strophejs-plugins)

## Stream Management (XEP-0198)

Since version 4.1.0, Strophe.js natively supports
[XEP-0198 Stream Management](https://xmpp.org/extensions/xep-0198.html) on websocket
connections: sent stanzas are acknowledged by the server, and a dropped connection can be
resumed without losing them.

It is off by default; opt in when creating the connection:

```javascript
const conn = new Strophe.Connection(service, {
enableStreamManagement: true,
// Optional fine-tuning:
streamManagement: {
maxUnacked: 5, // request an ack every N sent stanzas
requestResume: true, // ask the server for a resumable session
},
});
```

After connecting, `conn.hasResumed()` tells you whether the previous session was resumed
(skip re-fetching the roster, re-joining rooms etc.) or a fresh session was established.
Resumable state is kept in `sessionStorage` by default; pass a custom
`streamManagement.storage` backend to change that.

### Sharing a connection between tabs

With the `worker` connection option, all tabs of your application share a single websocket
connection through a SharedWorker. Point it at `dist/shared-connection-worker.js`.

One tab is assigned the `primary` role and drives the connection; the others attach to it
as `secondary` and are promoted automatically if the primary tab goes away (see
`Connection.onRoleChanged`). When Stream Management is enabled, the XEP-0198 engine runs
inside the worker itself, so a single SM session covers all tabs and a stanza sent from
any tab survives resumption.

Messages and presences sent from one tab are reflected to all the other tabs, so every tab
can render what any other tab sent (override `Connection.onForeignStanzaSent` to receive them).
They are deliberately kept out of the regular stanza handlers, which only see _received_
traffic.

## Support in different environments

Expand Down
2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ export default [...compat.extends("eslint:recommended"), {
"valid-jsdoc": "off",
"vars-on-top": "off",
"wrap-iife": ["error", "any"],
"wrap-regex": "error",
"wrap-regex": "off",
"yield-star-spacing": "error",
yoda: "off",
},
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@
"scripts": {
"types": "tsc",
"build": "tsc && rollup -c",
"lint": "eslint src/*.ts",
"lint": "eslint src",
"clean": "make clean",
"doc": "make doc",
"test": "npm run build && vitest run && npm run lint",
"prettier": "prettier --write src/*.ts"
"prettier": "prettier --write \"src/**/*.ts\""
},
"volo": {
"url": "https://raw.githubusercontent.com/strophe/strophejs/release-{version}/strophe.js"
Expand Down
13 changes: 13 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,17 @@ export default [
},
plugins: [typescript(tsConfig)],
},
// Shared-connection worker: a self-contained classic (non-module) worker
// script; point the Connection `worker` option at this file's URL.
{
input: 'src/shared-connection-worker.ts',
output: {
name: 'StropheSharedConnectionWorker',
file: 'dist/shared-connection-worker.js',
format: 'iife',
exports: 'named',
sourcemap: true,
},
plugins: [typescript(tsConfig)],
},
];
Loading
Loading