@dxos/rpc 2.19.6 → 2.19.7-dev.3aa68bc8

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/src/trace.ts ADDED
@@ -0,0 +1,42 @@
1
+ //
2
+ // Copyright 2021 DXOS.org
3
+ //
4
+
5
+ import { Event } from '@dxos/async';
6
+
7
+ import { MessageTrace } from './proto/gen/dxos/rpc';
8
+ import { RpcPort } from './rpc';
9
+
10
+ export class PortTracer {
11
+ readonly message = new Event<MessageTrace>();
12
+
13
+ private readonly _port: RpcPort;
14
+
15
+ constructor (
16
+ private readonly _wrappedPort: RpcPort
17
+ ) {
18
+ this._port = {
19
+ send: (msg: Uint8Array) => {
20
+ this.message.emit({
21
+ direction: MessageTrace.Direction.OUTGOING,
22
+ data: msg
23
+ });
24
+
25
+ return this._wrappedPort.send(msg);
26
+ },
27
+ subscribe: (cb: (msg: Uint8Array) => void) => {
28
+ return this._wrappedPort.subscribe(msg => {
29
+ this.message.emit({
30
+ direction: MessageTrace.Direction.INCOMING,
31
+ data: msg
32
+ });
33
+ cb(msg);
34
+ });
35
+ }
36
+ };
37
+ }
38
+
39
+ public get port () {
40
+ return this._port;
41
+ }
42
+ }
@@ -1,48 +0,0 @@
1
- //
2
- // Copyright 2020 DXOS.org
3
- //
4
-
5
- syntax = "proto3";
6
-
7
- package dxos.rpc;
8
-
9
- message RpcMessage {
10
- oneof content {
11
- Request request = 1;
12
- Response response = 2;
13
-
14
- /// Means that the node is open to receiving requests. Second stage of the hasnshake protocol.
15
- bool open = 3;
16
-
17
- StreamClose streamClose = 4;
18
- }
19
- }
20
-
21
- message Request {
22
- int32 id = 1;
23
- string method = 2;
24
- bytes payload = 3;
25
- bool stream = 4;
26
- }
27
-
28
- message Response {
29
- int32 id = 1;
30
- oneof content {
31
- bytes payload = 2;
32
- Error error = 3;
33
- // Sent when stream is closed without an error.
34
- bool close = 4;
35
- }
36
- }
37
-
38
- // Sent by client to end the streaming response.
39
- message StreamClose {
40
- int32 id = 1;
41
- }
42
-
43
-
44
- message Error {
45
- string name = 1;
46
- string message = 2;
47
- string stack = 3;
48
- }