@atproto/ws-client 0.1.1 → 0.1.3
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/CHANGELOG.md +15 -0
- package/package.json +3 -2
- package/tests/keepalive.test.ts +17 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @atproto/ws-client
|
|
2
2
|
|
|
3
|
+
## 0.1.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#5151](https://github.com/bluesky-social/atproto/pull/5151) [`a51c45d`](https://github.com/bluesky-social/atproto/commit/a51c45d38f6bd7b8765f640e564cf921d52162e7) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Update dependencies
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`f2cf8f7`](https://github.com/bluesky-social/atproto/commit/f2cf8f7fc5f3a10847f2e6d785e5fa2244ee8cfb), [`a51c45d`](https://github.com/bluesky-social/atproto/commit/a51c45d38f6bd7b8765f640e564cf921d52162e7), [`f2cf8f7`](https://github.com/bluesky-social/atproto/commit/f2cf8f7fc5f3a10847f2e6d785e5fa2244ee8cfb)]:
|
|
10
|
+
- @atproto/common@0.6.4
|
|
11
|
+
|
|
12
|
+
## 0.1.2
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- [#5117](https://github.com/bluesky-social/atproto/pull/5117) [`8a4c88b`](https://github.com/bluesky-social/atproto/commit/8a4c88b0f63fb2d82b1391d64c54e0c760fac48b) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Make tests less flaky in CI
|
|
17
|
+
|
|
3
18
|
## 0.1.1
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atproto/ws-client",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Websocket client library",
|
|
6
6
|
"keywords": [
|
|
@@ -18,11 +18,12 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"ws": "^8.12.0",
|
|
21
|
-
"@atproto/common": "^0.6.
|
|
21
|
+
"@atproto/common": "^0.6.4"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@types/ws": "^8.5.4",
|
|
25
25
|
"get-port": "^6.1.2",
|
|
26
|
+
"http-terminator": "^3.2.0",
|
|
26
27
|
"jest": "^30.0.0"
|
|
27
28
|
},
|
|
28
29
|
"type": "module",
|
package/tests/keepalive.test.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { once } from 'node:events'
|
|
2
|
+
import { createServer } from 'node:http'
|
|
3
|
+
import { AddressInfo } from 'node:net'
|
|
4
|
+
// eslint-disable-next-line import/default
|
|
5
|
+
import httpTerminator from 'http-terminator'
|
|
2
6
|
import { WebSocketServer } from 'ws'
|
|
3
7
|
import { wait } from '@atproto/common'
|
|
4
8
|
import { CloseCode, WebSocketKeepAlive } from '../src/index.js'
|
|
@@ -7,11 +11,17 @@ describe('WebSocketKeepAlive', () => {
|
|
|
7
11
|
it('uses a heartbeat to reconnect if a connection is dropped', async () => {
|
|
8
12
|
// we run a server that, on first connection, pauses for longer than the heartbeat interval (doesn't return "pong"s)
|
|
9
13
|
// on second connection, it sends a message and then closes
|
|
10
|
-
|
|
11
|
-
const server =
|
|
14
|
+
|
|
15
|
+
const server = createServer()
|
|
16
|
+
|
|
17
|
+
// make sure to always close the server (even in case of test failure)
|
|
18
|
+
const { terminate } = httpTerminator.createHttpTerminator({ server })
|
|
19
|
+
await using _ = { [Symbol.asyncDispose]: async () => terminate() }
|
|
20
|
+
|
|
21
|
+
const wsServer = new WebSocketServer({ server })
|
|
12
22
|
let firstConnection = true
|
|
13
23
|
let firstWasClosed = false
|
|
14
|
-
|
|
24
|
+
wsServer.on('connection', async (socket) => {
|
|
15
25
|
if (firstConnection === true) {
|
|
16
26
|
firstConnection = false
|
|
17
27
|
socket.pause()
|
|
@@ -32,6 +42,9 @@ describe('WebSocketKeepAlive', () => {
|
|
|
32
42
|
}
|
|
33
43
|
})
|
|
34
44
|
|
|
45
|
+
await once(server.listen(0), 'listening')
|
|
46
|
+
const port = (server.address() as AddressInfo).port
|
|
47
|
+
|
|
35
48
|
const wsKeepAlive = new WebSocketKeepAlive({
|
|
36
49
|
getUrl: async () => `ws://localhost:${port}`,
|
|
37
50
|
heartbeatIntervalMs: 500,
|
|
@@ -45,6 +58,5 @@ describe('WebSocketKeepAlive', () => {
|
|
|
45
58
|
expect(messages).toHaveLength(1)
|
|
46
59
|
expect(Buffer.from(messages[0]).toString()).toBe('test message')
|
|
47
60
|
expect(firstWasClosed).toBe(true)
|
|
48
|
-
server.close()
|
|
49
61
|
})
|
|
50
62
|
})
|