@dxos/edge-client 0.8.1 → 0.8.2-main.12df754
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/dist/lib/browser/index.mjs +23 -17
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +22 -16
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +23 -17
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/edge-client.d.ts +7 -2
- package/dist/types/src/edge-client.d.ts.map +1 -1
- package/package.json +14 -14
- package/src/edge-client.test.ts +5 -4
- package/src/edge-client.ts +14 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/edge-client",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.2-main.12df754",
|
|
4
4
|
"description": "EDGE Client",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -36,21 +36,21 @@
|
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"isomorphic-ws": "^5.0.0",
|
|
38
38
|
"ws": "^8.14.2",
|
|
39
|
-
"@dxos/async": "0.8.
|
|
40
|
-
"@dxos/
|
|
41
|
-
"@dxos/credentials": "0.8.
|
|
42
|
-
"@dxos/
|
|
43
|
-
"@dxos/debug": "0.8.
|
|
44
|
-
"@dxos/invariant": "0.8.
|
|
45
|
-
"@dxos/
|
|
46
|
-
"@dxos/
|
|
47
|
-
"@dxos/
|
|
48
|
-
"@dxos/
|
|
49
|
-
"@dxos/protocols": "0.8.
|
|
50
|
-
"@dxos/util": "0.8.
|
|
39
|
+
"@dxos/async": "0.8.2-main.12df754",
|
|
40
|
+
"@dxos/crypto": "0.8.2-main.12df754",
|
|
41
|
+
"@dxos/credentials": "0.8.2-main.12df754",
|
|
42
|
+
"@dxos/context": "0.8.2-main.12df754",
|
|
43
|
+
"@dxos/debug": "0.8.2-main.12df754",
|
|
44
|
+
"@dxos/invariant": "0.8.2-main.12df754",
|
|
45
|
+
"@dxos/keyring": "0.8.2-main.12df754",
|
|
46
|
+
"@dxos/keys": "0.8.2-main.12df754",
|
|
47
|
+
"@dxos/log": "0.8.2-main.12df754",
|
|
48
|
+
"@dxos/node-std": "0.8.2-main.12df754",
|
|
49
|
+
"@dxos/protocols": "0.8.2-main.12df754",
|
|
50
|
+
"@dxos/util": "0.8.2-main.12df754"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@dxos/test-utils": "0.8.
|
|
53
|
+
"@dxos/test-utils": "0.8.2-main.12df754"
|
|
54
54
|
},
|
|
55
55
|
"publishConfig": {
|
|
56
56
|
"access": "public"
|
package/src/edge-client.test.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { describe, expect, onTestFinished, test } from 'vitest';
|
|
|
7
7
|
import { Trigger } from '@dxos/async';
|
|
8
8
|
import { Keyring } from '@dxos/keyring';
|
|
9
9
|
import { TextMessageSchema } from '@dxos/protocols/buf/dxos/edge/messenger_pb';
|
|
10
|
+
import { EdgeStatus } from '@dxos/protocols/proto/dxos/client/services';
|
|
10
11
|
import { openAndClose } from '@dxos/test-utils';
|
|
11
12
|
|
|
12
13
|
import { createEphemeralEdgeIdentity, createTestHaloEdgeIdentity } from './auth';
|
|
@@ -40,17 +41,17 @@ describe('EdgeClient', () => {
|
|
|
40
41
|
|
|
41
42
|
const { client } = await openNewClient(endpoint);
|
|
42
43
|
|
|
43
|
-
expect(client.
|
|
44
|
+
expect(client.status).toBe(EdgeStatus.NOT_CONNECTED);
|
|
44
45
|
admitConnection.wake();
|
|
45
|
-
await expect.poll(() => client.
|
|
46
|
+
await expect.poll(() => client.status).toBe(EdgeStatus.CONNECTED);
|
|
46
47
|
|
|
47
48
|
admitConnection.reset();
|
|
48
49
|
await closeConnection();
|
|
49
50
|
expect(client.isOpen).is.true;
|
|
50
|
-
await expect.poll(() => client.
|
|
51
|
+
await expect.poll(() => client.status).toBe(EdgeStatus.NOT_CONNECTED);
|
|
51
52
|
|
|
52
53
|
admitConnection.wake();
|
|
53
|
-
await expect.poll(() => client.
|
|
54
|
+
await expect.poll(() => client.status).toBe(EdgeStatus.CONNECTED);
|
|
54
55
|
});
|
|
55
56
|
|
|
56
57
|
test('set identity reconnects', async () => {
|
package/src/edge-client.ts
CHANGED
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { Trigger, scheduleMicroTask, TriggerState, PersistentLifecycle } from '@dxos/async';
|
|
5
|
+
import { Trigger, scheduleMicroTask, TriggerState, PersistentLifecycle, Event } from '@dxos/async';
|
|
6
6
|
import { Resource, type Lifecycle } from '@dxos/context';
|
|
7
7
|
import { log, logInfo } from '@dxos/log';
|
|
8
8
|
import { type Message } from '@dxos/protocols/buf/dxos/edge/messenger_pb';
|
|
9
|
+
import { EdgeStatus } from '@dxos/protocols/proto/dxos/client/services';
|
|
9
10
|
|
|
10
11
|
import { protocol } from './defs';
|
|
11
12
|
import { type EdgeIdentity, handleAuthChallenge } from './edge-identity';
|
|
@@ -20,11 +21,12 @@ export type MessageListener = (message: Message) => void;
|
|
|
20
21
|
export type ReconnectListener = () => void;
|
|
21
22
|
|
|
22
23
|
export interface EdgeConnection extends Required<Lifecycle> {
|
|
24
|
+
statusChanged: Event<EdgeStatus>;
|
|
23
25
|
get info(): any;
|
|
24
26
|
get identityKey(): string;
|
|
25
27
|
get peerKey(): string;
|
|
26
28
|
get isOpen(): boolean;
|
|
27
|
-
get
|
|
29
|
+
get status(): EdgeStatus;
|
|
28
30
|
setIdentity(identity: EdgeIdentity): void;
|
|
29
31
|
onMessage(listener: MessageListener): () => void;
|
|
30
32
|
onReconnected(listener: ReconnectListener): () => void;
|
|
@@ -45,6 +47,8 @@ export type MessengerConfig = {
|
|
|
45
47
|
* - Dispatches connection state and message notifications.
|
|
46
48
|
*/
|
|
47
49
|
export class EdgeClient extends Resource implements EdgeConnection {
|
|
50
|
+
public readonly statusChanged = new Event<EdgeStatus>();
|
|
51
|
+
|
|
48
52
|
private readonly _persistentLifecycle = new PersistentLifecycle<EdgeWsConnection>({
|
|
49
53
|
start: async () => this._connect(),
|
|
50
54
|
stop: async (state: EdgeWsConnection) => this._disconnect(state),
|
|
@@ -52,10 +56,8 @@ export class EdgeClient extends Resource implements EdgeConnection {
|
|
|
52
56
|
|
|
53
57
|
private readonly _messageListeners = new Set<MessageListener>();
|
|
54
58
|
private readonly _reconnectListeners = new Set<ReconnectListener>();
|
|
55
|
-
|
|
56
59
|
private readonly _baseWsUrl: string;
|
|
57
60
|
private readonly _baseHttpUrl: string;
|
|
58
|
-
|
|
59
61
|
private _currentConnection?: EdgeWsConnection = undefined;
|
|
60
62
|
private _ready = new Trigger();
|
|
61
63
|
|
|
@@ -72,13 +74,16 @@ export class EdgeClient extends Resource implements EdgeConnection {
|
|
|
72
74
|
public get info() {
|
|
73
75
|
return {
|
|
74
76
|
open: this.isOpen,
|
|
77
|
+
status: this.status,
|
|
75
78
|
identity: this._identity.identityKey,
|
|
76
79
|
device: this._identity.peerKey,
|
|
77
80
|
};
|
|
78
81
|
}
|
|
79
82
|
|
|
80
|
-
get
|
|
81
|
-
return Boolean(this._currentConnection) && this._ready.state === TriggerState.RESOLVED
|
|
83
|
+
get status(): EdgeStatus {
|
|
84
|
+
return Boolean(this._currentConnection) && this._ready.state === TriggerState.RESOLVED
|
|
85
|
+
? EdgeStatus.CONNECTED
|
|
86
|
+
: EdgeStatus.NOT_CONNECTED;
|
|
82
87
|
}
|
|
83
88
|
|
|
84
89
|
get identityKey() {
|
|
@@ -201,15 +206,18 @@ export class EdgeClient extends Resource implements EdgeConnection {
|
|
|
201
206
|
|
|
202
207
|
private async _disconnect(state: EdgeWsConnection) {
|
|
203
208
|
await state.close();
|
|
209
|
+
this.statusChanged.emit(this.status);
|
|
204
210
|
}
|
|
205
211
|
|
|
206
212
|
private _closeCurrentConnection(error: Error = new EdgeConnectionClosedError()) {
|
|
207
213
|
this._currentConnection = undefined;
|
|
208
214
|
this._ready.throw(error);
|
|
209
215
|
this._ready.reset();
|
|
216
|
+
this.statusChanged.emit(this.status);
|
|
210
217
|
}
|
|
211
218
|
|
|
212
219
|
private _notifyReconnected() {
|
|
220
|
+
this.statusChanged.emit(this.status);
|
|
213
221
|
for (const listener of this._reconnectListeners) {
|
|
214
222
|
try {
|
|
215
223
|
listener();
|