@dxos/messaging 0.4.9 → 0.4.10-main.0be5154

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/messaging",
3
- "version": "0.4.9",
3
+ "version": "0.4.10-main.0be5154",
4
4
  "description": "Messaging",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -19,23 +19,23 @@
19
19
  "dependencies": {
20
20
  "isomorphic-ws": "^4.0.1",
21
21
  "ws": "^8.14.2",
22
- "@dxos/codec-protobuf": "0.4.9",
23
- "@dxos/async": "0.4.9",
24
- "@dxos/invariant": "0.4.9",
25
- "@dxos/context": "0.4.9",
26
- "@dxos/keys": "0.4.9",
27
- "@dxos/node-std": "0.4.9",
28
- "@dxos/rpc": "0.4.9",
29
- "@dxos/log": "0.4.9",
30
- "@dxos/protocols": "0.4.9",
31
- "@dxos/util": "0.4.9"
22
+ "@dxos/async": "0.4.10-main.0be5154",
23
+ "@dxos/codec-protobuf": "0.4.10-main.0be5154",
24
+ "@dxos/context": "0.4.10-main.0be5154",
25
+ "@dxos/invariant": "0.4.10-main.0be5154",
26
+ "@dxos/log": "0.4.10-main.0be5154",
27
+ "@dxos/node-std": "0.4.10-main.0be5154",
28
+ "@dxos/keys": "0.4.10-main.0be5154",
29
+ "@dxos/protocols": "0.4.10-main.0be5154",
30
+ "@dxos/rpc": "0.4.10-main.0be5154",
31
+ "@dxos/util": "0.4.10-main.0be5154"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@types/node": "^18.11.9",
35
35
  "earljs": "~0.1.10",
36
36
  "typescript": "^5.2.2",
37
37
  "wait-for-expect": "^3.0.2",
38
- "@dxos/signal": "0.4.9"
38
+ "@dxos/signal": "0.4.10-main.0be5154"
39
39
  },
40
40
  "publishConfig": {
41
41
  "access": "public"
@@ -125,6 +125,7 @@ export class SignalClient implements SignalMethods {
125
125
  private readonly _host: string,
126
126
  private readonly _onMessage: (params: { author: PublicKey; recipient: PublicKey; payload: Any }) => Promise<void>,
127
127
  private readonly _onSwarmEvent: (params: { topic: PublicKey; swarmEvent: SwarmEvent }) => Promise<void>,
128
+ private readonly _getMetadata?: () => any,
128
129
  ) {
129
130
  if (!this._host.startsWith('wss://') && !this._host.startsWith('ws://')) {
130
131
  throw new Error(`Signal server requires a websocket URL. Provided: ${this._host}`);
@@ -309,6 +310,7 @@ export class SignalClient implements SignalMethods {
309
310
 
310
311
  this._reconnectTask!.schedule();
311
312
  },
313
+ getMetadata: this._getMetadata,
312
314
  },
313
315
  });
314
316
  } catch (err: any) {
@@ -30,6 +30,7 @@ export type SignalCallbacks = {
30
30
  onDisconnected?: () => void;
31
31
 
32
32
  onError?: (error: Error) => void;
33
+ getMetadata?: () => any;
33
34
  };
34
35
 
35
36
  export type SignalRPCClientParams = {
@@ -164,6 +165,7 @@ export class SignalRPCClient {
164
165
  const swarmStream = this._rpc.rpc.Signal.join({
165
166
  swarm: topic.asUint8Array(),
166
167
  peer: peerId.asUint8Array(),
168
+ metadata: this._callbacks?.getMetadata?.(),
167
169
  });
168
170
  await swarmStream.waitUntilReady();
169
171
  return swarmStream;
@@ -190,6 +192,7 @@ export class SignalRPCClient {
190
192
  author: author.asUint8Array(),
191
193
  recipient: recipient.asUint8Array(),
192
194
  payload,
195
+ metadata: this._callbacks?.getMetadata?.(),
193
196
  });
194
197
  }
195
198
  }
@@ -5,3 +5,4 @@
5
5
  export * from './memory-signal-manager';
6
6
  export * from './signal-manager';
7
7
  export * from './websocket-signal-manager';
8
+ export * from './utils';
@@ -0,0 +1,42 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import { invariant } from '@dxos/invariant';
6
+ import { log } from '@dxos/log';
7
+ import { type DevicesService, type IdentityService } from '@dxos/protocols/proto/dxos/client/services';
8
+ import { DeviceKind } from '@dxos/protocols/proto/dxos/client/services';
9
+
10
+ export const setIdentityTags = ({
11
+ identityService,
12
+ devicesService,
13
+ setTag,
14
+ }: {
15
+ identityService: IdentityService;
16
+ devicesService: DevicesService;
17
+ setTag: (k: string, v: string) => void;
18
+ }) => {
19
+ identityService.queryIdentity().subscribe((idqr) => {
20
+ if (!idqr?.identity?.identityKey) {
21
+ log('empty response from identity service', { idqr });
22
+ return;
23
+ }
24
+
25
+ setTag('identityKey', idqr.identity.identityKey.truncate());
26
+ });
27
+
28
+ devicesService.queryDevices().subscribe((dqr) => {
29
+ if (!dqr || !dqr.devices || dqr.devices.length === 0) {
30
+ log('empty response from device service', { device: dqr });
31
+ return;
32
+ }
33
+ invariant(dqr, 'empty response from device service');
34
+
35
+ const thisDevice = dqr.devices.find((device) => device.kind === DeviceKind.CURRENT);
36
+ if (!thisDevice) {
37
+ log('no current device', { device: dqr });
38
+ return;
39
+ }
40
+ setTag('deviceKey', thisDevice.deviceKey.truncate());
41
+ });
42
+ };
@@ -42,7 +42,10 @@ export class WebsocketSignalManager implements SignalManager {
42
42
 
43
43
  private readonly _instanceId = PublicKey.random().toHex();
44
44
 
45
- constructor(private readonly _hosts: Runtime.Services.Signal[]) {
45
+ constructor(
46
+ private readonly _hosts: Runtime.Services.Signal[],
47
+ private readonly _getMetadata?: () => any,
48
+ ) {
46
49
  log('Created WebsocketSignalManager', { hosts: this._hosts });
47
50
  for (const host of this._hosts) {
48
51
  if (this._servers.has(host.server)) {
@@ -52,6 +55,7 @@ export class WebsocketSignalManager implements SignalManager {
52
55
  host.server,
53
56
  async (message) => this.onMessage.emit(message),
54
57
  async (data) => this.swarmEvent.emit(data),
58
+ this._getMetadata,
55
59
  );
56
60
  server.statusChanged.on(() => this.statusChanged.emit(this.getStatus()));
57
61