@sockethub/client 5.0.0-alpha.4 → 5.0.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +127 -0
- package/dist/sockethub-client.js +553 -2557
- package/dist/sockethub-client.min.js +19 -2
- package/package.json +33 -41
- package/coverage/tmp/coverage-39188-1663949482444-0.json +0 -1
- package/dist/sockethub-client.d.ts +0 -14
- package/dist/sockethub-client.js.map +0 -1
- package/dist/sockethub-client.min.js.LICENSE.txt +0 -24
- package/src/sockethub-client.test.ts +0 -237
- package/src/sockethub-client.ts +0 -176
- package/tsconfig.json +0 -20
- package/webpack.minified.config.js +0 -14
- package/webpack.normal.config.js +0 -14
package/README.md
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# @sockethub/client
|
|
2
|
+
|
|
3
|
+
JavaScript client for [Sockethub](https://github.com/sockethub/sockethub) - a protocol
|
|
4
|
+
gateway that translates ActivityStreams messages into various protocols (XMPP, IRC, RSS, etc.).
|
|
5
|
+
|
|
6
|
+
Works in Node.js and browsers.
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
### Node.js
|
|
11
|
+
|
|
12
|
+
`$ npm install @sockethub/client`
|
|
13
|
+
|
|
14
|
+
### Bun
|
|
15
|
+
|
|
16
|
+
`$ bun install @sockethub/client`
|
|
17
|
+
|
|
18
|
+
#### CommonJS
|
|
19
|
+
|
|
20
|
+
```javascript
|
|
21
|
+
const SockethubClient = require('@sockethub/client');
|
|
22
|
+
const io = require('@socket.io-client');
|
|
23
|
+
const SOCKETHUB_SERVER = 'http://localhost:10550';
|
|
24
|
+
const sc = SockethubClient(io(SOCKETHUB_SERVER));
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
#### ESM
|
|
28
|
+
|
|
29
|
+
```javascript
|
|
30
|
+
import SockethubClient from '@sockethub/client';
|
|
31
|
+
import { io } from '@socket.io-client';
|
|
32
|
+
const SOCKETHUB_SERVER = 'http://localhost:10550';
|
|
33
|
+
const sc = SockethubClient(io(SOCKETHUB_SERVER));
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Browser
|
|
37
|
+
|
|
38
|
+
The browser bundle is available in the dist folder:
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
import '@sockethub/client/dist/sockethub-client.js';
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
You can place it somewhere accessible from the web and include
|
|
45
|
+
it via a `script` tag.
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
<script src="http://example.com/sockethub-client.js" type="module"></script>
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Once included in a web-page, the `SockethubClient` base object
|
|
52
|
+
should be on the global scope.
|
|
53
|
+
|
|
54
|
+
## Quick Start
|
|
55
|
+
|
|
56
|
+
```javascript
|
|
57
|
+
import SockethubClient from '@sockethub/client';
|
|
58
|
+
import { io } from 'socket.io-client';
|
|
59
|
+
|
|
60
|
+
const socket = io('http://localhost:10550', { path: '/sockethub' });
|
|
61
|
+
const sc = new SockethubClient(socket);
|
|
62
|
+
|
|
63
|
+
sc.socket.on('message', (msg) => console.log(msg));
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
See the [Client Guide](../../docs/client-guide.md) for detailed usage and examples.
|
|
67
|
+
|
|
68
|
+
## API
|
|
69
|
+
|
|
70
|
+
- **`new SockethubClient(socket)`** - Create client instance
|
|
71
|
+
- **`sc.socket.emit(event, data)`** - Send messages
|
|
72
|
+
- **`sc.socket.on(event, handler)`** - Listen for messages
|
|
73
|
+
- **`sc.clearCredentials()`** - Clear stored credentials
|
|
74
|
+
- **`sc.ActivityStreams`** - ActivityStreams library
|
|
75
|
+
|
|
76
|
+
## Security & State Management
|
|
77
|
+
|
|
78
|
+
### Automatic Reconnection
|
|
79
|
+
|
|
80
|
+
The SockethubClient automatically handles brief network disconnections by storing connection state in
|
|
81
|
+
memory and replaying it when the connection is re-established.
|
|
82
|
+
|
|
83
|
+
#### What Gets Stored
|
|
84
|
+
|
|
85
|
+
- Credentials (passwords, tokens, API keys)
|
|
86
|
+
- Actor definitions
|
|
87
|
+
- Platform connections
|
|
88
|
+
- Channel/room joins
|
|
89
|
+
|
|
90
|
+
#### Storage Location
|
|
91
|
+
|
|
92
|
+
**All state is stored ONLY in JavaScript memory.** Nothing is persisted to:
|
|
93
|
+
|
|
94
|
+
- localStorage
|
|
95
|
+
- sessionStorage
|
|
96
|
+
- Cookies
|
|
97
|
+
- IndexedDB
|
|
98
|
+
- Disk
|
|
99
|
+
|
|
100
|
+
#### Lifetime
|
|
101
|
+
|
|
102
|
+
State exists only during the current browser tab session:
|
|
103
|
+
|
|
104
|
+
- ✅ Survives brief network interruptions
|
|
105
|
+
- ❌ Cleared on page refresh
|
|
106
|
+
- ❌ Cleared when tab closes
|
|
107
|
+
- ❌ Not shared between tabs
|
|
108
|
+
|
|
109
|
+
#### Server Restart Behavior
|
|
110
|
+
|
|
111
|
+
If the Sockethub server restarts:
|
|
112
|
+
|
|
113
|
+
1. Client socket will automatically reconnect
|
|
114
|
+
2. Client will replay stored credentials
|
|
115
|
+
3. **Server must validate replayed credentials** (may be expired/revoked)
|
|
116
|
+
4. Server should implement session validation to handle stale replays
|
|
117
|
+
|
|
118
|
+
#### Disabling Automatic Replay
|
|
119
|
+
|
|
120
|
+
If you need to disable automatic credential replay for security reasons:
|
|
121
|
+
|
|
122
|
+
```javascript
|
|
123
|
+
// Clear credentials before they can be replayed
|
|
124
|
+
sc.socket.on('disconnect', () => {
|
|
125
|
+
sc.clearCredentials();
|
|
126
|
+
});
|
|
127
|
+
```
|