starpc 0.3.6 → 0.4.0
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/Makefile +2 -1
- package/dist/echo/client-test.js +1 -1
- package/dist/echo/{echo.d.ts → echo.pb.d.ts} +0 -0
- package/dist/echo/{echo.js → echo.pb.js} +0 -0
- package/dist/echo/index.d.ts +1 -1
- package/dist/echo/index.js +1 -1
- package/dist/echo/server.d.ts +1 -1
- package/dist/srpc/client-rpc.d.ts +1 -1
- package/dist/srpc/client.d.ts +5 -5
- package/dist/srpc/client.js +19 -19
- package/dist/srpc/common-rpc.d.ts +2 -2
- package/dist/srpc/common-rpc.js +1 -1
- package/dist/srpc/index.d.ts +1 -1
- package/dist/srpc/packet.d.ts +1 -1
- package/dist/srpc/packet.js +1 -1
- package/dist/srpc/{rpcproto.d.ts → rpcproto.pb.d.ts} +0 -0
- package/dist/srpc/{rpcproto.js → rpcproto.pb.js} +0 -0
- package/dist/srpc/server-rpc.d.ts +1 -1
- package/dist/srpc/server.d.ts +1 -1
- package/dist/srpc/stream.d.ts +1 -1
- package/echo/client-test.ts +1 -1
- package/echo/{echo.ts → echo.pb.ts} +0 -0
- package/echo/index.ts +1 -1
- package/echo/server.ts +1 -1
- package/integration/integration.ts +2 -2
- package/package.json +1 -1
- package/srpc/broadcast-channel.ts +1 -1
- package/srpc/client-rpc.ts +1 -1
- package/srpc/client.go +2 -2
- package/srpc/client.ts +23 -23
- package/srpc/common-rpc.ts +2 -2
- package/srpc/index.ts +1 -1
- package/srpc/{rpc-stream.go → msg-stream.go} +11 -11
- package/srpc/muxed-conn.go +1 -1
- package/srpc/packet.ts +1 -1
- package/srpc/{rpcproto.ts → rpcproto.pb.ts} +0 -0
- package/srpc/server-pipe.go +1 -1
- package/srpc/server-rpc.go +1 -1
- package/srpc/server-rpc.ts +1 -1
- package/srpc/server.go +5 -0
- package/srpc/server.ts +1 -1
- package/srpc/stream.ts +1 -1
- package/srpc/websocket.go +1 -1
package/Makefile
CHANGED
|
@@ -99,9 +99,10 @@ gents: $(PROTOWRAP) node_modules
|
|
|
99
99
|
-I $$(pwd)/vendor \
|
|
100
100
|
--plugin=./node_modules/.bin/protoc-gen-ts_proto \
|
|
101
101
|
--ts_proto_out=$$(pwd)/vendor \
|
|
102
|
+
--ts_proto_opt=esModuleInterop=true \
|
|
103
|
+
--ts_proto_opt=fileSuffix=.pb \
|
|
102
104
|
--ts_proto_opt=forceLong=long \
|
|
103
105
|
--ts_proto_opt=oneof=unions \
|
|
104
|
-
--ts_proto_opt=esModuleInterop=true \
|
|
105
106
|
--ts_proto_opt=outputServices=default,outputServices=generic-definitions \
|
|
106
107
|
--proto_path $$(pwd)/vendor \
|
|
107
108
|
--print_structure \
|
package/dist/echo/client-test.js
CHANGED
|
File without changes
|
|
File without changes
|
package/dist/echo/index.d.ts
CHANGED
package/dist/echo/index.js
CHANGED
package/dist/echo/server.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Observable } from 'rxjs';
|
|
2
|
-
import { Echoer, EchoMsg } from './echo';
|
|
2
|
+
import { Echoer, EchoMsg } from './echo.pb.js';
|
|
3
3
|
export declare class EchoerServer implements Echoer {
|
|
4
4
|
Echo(request: EchoMsg): Promise<EchoMsg>;
|
|
5
5
|
EchoServerStream(request: EchoMsg): Observable<EchoMsg>;
|
package/dist/srpc/client.d.ts
CHANGED
|
@@ -2,11 +2,11 @@ import { Observable } from 'rxjs';
|
|
|
2
2
|
import type { TsProtoRpc } from './ts-proto-rpc.js';
|
|
3
3
|
import type { OpenStreamFunc } from './stream.js';
|
|
4
4
|
export declare class Client implements TsProtoRpc {
|
|
5
|
-
private
|
|
6
|
-
private
|
|
7
|
-
constructor(
|
|
8
|
-
|
|
9
|
-
private
|
|
5
|
+
private openStreamFn;
|
|
6
|
+
private _openStreamFn?;
|
|
7
|
+
constructor(openStreamFn?: OpenStreamFunc);
|
|
8
|
+
setOpenStreamFn(openStreamFn?: OpenStreamFunc): Promise<OpenStreamFunc>;
|
|
9
|
+
private initOpenStreamFn;
|
|
10
10
|
request(service: string, method: string, data: Uint8Array): Promise<Uint8Array>;
|
|
11
11
|
clientStreamingRequest(service: string, method: string, data: Observable<Uint8Array>): Promise<Uint8Array>;
|
|
12
12
|
serverStreamingRequest(service: string, method: string, data: Uint8Array): Observable<Uint8Array>;
|
package/dist/srpc/client.js
CHANGED
|
@@ -19,31 +19,31 @@ function writeClientStream(call, data) {
|
|
|
19
19
|
}
|
|
20
20
|
// Client implements the ts-proto Rpc interface with the drpcproto protocol.
|
|
21
21
|
export class Client {
|
|
22
|
-
constructor(
|
|
23
|
-
this.
|
|
22
|
+
constructor(openStreamFn) {
|
|
23
|
+
this.openStreamFn = this.setOpenStreamFn(openStreamFn);
|
|
24
24
|
}
|
|
25
|
-
//
|
|
26
|
-
|
|
27
|
-
if (this.
|
|
28
|
-
if (
|
|
29
|
-
this.
|
|
30
|
-
this.
|
|
25
|
+
// setOpenStreamFn updates the openStreamFn for the Client.
|
|
26
|
+
setOpenStreamFn(openStreamFn) {
|
|
27
|
+
if (this._openStreamFn) {
|
|
28
|
+
if (openStreamFn) {
|
|
29
|
+
this._openStreamFn(openStreamFn);
|
|
30
|
+
this._openStreamFn = undefined;
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
else {
|
|
34
|
-
if (
|
|
35
|
-
this.
|
|
34
|
+
if (openStreamFn) {
|
|
35
|
+
this.openStreamFn = Promise.resolve(openStreamFn);
|
|
36
36
|
}
|
|
37
37
|
else {
|
|
38
|
-
this.
|
|
38
|
+
this.initOpenStreamFn();
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
-
return this.
|
|
41
|
+
return this.openStreamFn;
|
|
42
42
|
}
|
|
43
|
-
//
|
|
44
|
-
|
|
43
|
+
// initOpenStreamFn creates the empty Promise for openStreamFn.
|
|
44
|
+
initOpenStreamFn() {
|
|
45
45
|
const openPromise = new Promise((resolve, reject) => {
|
|
46
|
-
this.
|
|
46
|
+
this._openStreamFn = (conn, err) => {
|
|
47
47
|
if (err) {
|
|
48
48
|
reject(err);
|
|
49
49
|
}
|
|
@@ -52,8 +52,8 @@ export class Client {
|
|
|
52
52
|
}
|
|
53
53
|
};
|
|
54
54
|
});
|
|
55
|
-
this.
|
|
56
|
-
return this.
|
|
55
|
+
this.openStreamFn = openPromise;
|
|
56
|
+
return this.openStreamFn;
|
|
57
57
|
}
|
|
58
58
|
// request starts a non-streaming request.
|
|
59
59
|
async request(service, method, data) {
|
|
@@ -131,8 +131,8 @@ export class Client {
|
|
|
131
131
|
// throws any error starting the rpc call
|
|
132
132
|
// if data == null and data.length == 0, sends a separate data packet.
|
|
133
133
|
async startRpc(rpcService, rpcMethod, data) {
|
|
134
|
-
const
|
|
135
|
-
const conn = await
|
|
134
|
+
const openStreamFn = await this.openStreamFn;
|
|
135
|
+
const conn = await openStreamFn();
|
|
136
136
|
const call = new ClientRPC(rpcService, rpcMethod);
|
|
137
137
|
pipe(conn, parseLengthPrefixTransform(), decodePacketSource, call, encodePacketSource, prependLengthPrefixTransform(), conn);
|
|
138
138
|
await call.writeCallStart(data || undefined);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Source, Sink } from 'it-stream-types';
|
|
2
|
-
import type { CallData, CallStart } from './rpcproto.js';
|
|
3
|
-
import { Packet } from './rpcproto.js';
|
|
2
|
+
import type { CallData, CallStart } from './rpcproto.pb.js';
|
|
3
|
+
import { Packet } from './rpcproto.pb.js';
|
|
4
4
|
export declare class CommonRPC {
|
|
5
5
|
sink: Sink<Packet>;
|
|
6
6
|
source: AsyncIterable<Packet>;
|
package/dist/srpc/common-rpc.js
CHANGED
package/dist/srpc/index.d.ts
CHANGED
package/dist/srpc/packet.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Transform } from 'it-stream-types';
|
|
2
|
-
import { Packet } from './rpcproto.js';
|
|
2
|
+
import { Packet } from './rpcproto.pb.js';
|
|
3
3
|
export declare const decodePacketSource: (source: import("it-stream-types").Source<Uint8Array | Uint8Array[]>) => AsyncIterable<Packet>;
|
|
4
4
|
export declare const encodePacketSource: (source: import("it-stream-types").Source<Packet | Packet[]>) => AsyncIterable<Uint8Array>;
|
|
5
5
|
export declare function prependLengthPrefixTransform(): Transform<Uint8Array>;
|
package/dist/srpc/packet.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { encode as lengthPrefixEncode, decode as lengthPrefixDecode, } from 'it-length-prefixed';
|
|
2
|
-
import { Packet } from './rpcproto.js';
|
|
2
|
+
import { Packet } from './rpcproto.pb.js';
|
|
3
3
|
import { buildDecodeMessageTransform, buildEncodeMessageTransform, } from './message.js';
|
|
4
4
|
// decodePacketSource decodes packets from a binary data stream.
|
|
5
5
|
export const decodePacketSource = buildDecodeMessageTransform(Packet);
|
|
File without changes
|
|
File without changes
|
package/dist/srpc/server.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Stream } from '@libp2p/interface-connection';
|
|
|
2
2
|
import { Duplex } from 'it-stream-types';
|
|
3
3
|
import { Mux } from './mux.js';
|
|
4
4
|
import { ServerRPC } from './server-rpc.js';
|
|
5
|
-
import { Packet } from './rpcproto.js';
|
|
5
|
+
import { Packet } from './rpcproto.pb.js';
|
|
6
6
|
import { StreamHandler } from './conn.js';
|
|
7
7
|
export declare class Server implements StreamHandler {
|
|
8
8
|
private mux;
|
package/dist/srpc/stream.d.ts
CHANGED
package/echo/client-test.ts
CHANGED
|
File without changes
|
package/echo/index.ts
CHANGED
package/echo/server.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { WebSocketConn } from '../srpc/websocket'
|
|
2
|
-
import { runClientTest } from '../echo'
|
|
1
|
+
import { WebSocketConn } from '../srpc/websocket.js'
|
|
2
|
+
import { runClientTest } from '../echo/client-test.js'
|
|
3
3
|
import WebSocket from 'isomorphic-ws'
|
|
4
4
|
|
|
5
5
|
async function runRPC() {
|
package/package.json
CHANGED
|
@@ -46,8 +46,8 @@ export class BroadcastChannelIterable<T> implements Duplex<T> {
|
|
|
46
46
|
queue.push(ev.data)
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
|
-
this.readChannel.addEventListener('message', messageListener)
|
|
50
49
|
|
|
50
|
+
this.readChannel.addEventListener('message', messageListener)
|
|
51
51
|
return () => {
|
|
52
52
|
this.readChannel.removeEventListener('message', messageListener)
|
|
53
53
|
}
|
package/srpc/client-rpc.ts
CHANGED
package/srpc/client.go
CHANGED
|
@@ -19,7 +19,7 @@ type Client interface {
|
|
|
19
19
|
|
|
20
20
|
// OpenStreamFunc opens a stream with a remote.
|
|
21
21
|
// msgHandler must not be called concurrently.
|
|
22
|
-
type OpenStreamFunc = func(ctx context.Context, msgHandler
|
|
22
|
+
type OpenStreamFunc = func(ctx context.Context, msgHandler PacketHandler) (Writer, error)
|
|
23
23
|
|
|
24
24
|
// client implements Client with a transport.
|
|
25
25
|
type client struct {
|
|
@@ -89,7 +89,7 @@ func (c *client) NewStream(ctx context.Context, service, method string, firstMsg
|
|
|
89
89
|
return nil, err
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
return
|
|
92
|
+
return NewMsgStream(ctx, clientRPC.writer, clientRPC.dataCh), nil
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
// _ is a type assertion
|
package/srpc/client.ts
CHANGED
|
@@ -29,36 +29,36 @@ function writeClientStream(call: ClientRPC, data: Observable<Uint8Array>) {
|
|
|
29
29
|
|
|
30
30
|
// Client implements the ts-proto Rpc interface with the drpcproto protocol.
|
|
31
31
|
export class Client implements TsProtoRpc {
|
|
32
|
-
//
|
|
33
|
-
private
|
|
34
|
-
//
|
|
35
|
-
private
|
|
32
|
+
// openStreamFn is a promise which contains the OpenStreamFunc.
|
|
33
|
+
private openStreamFn: Promise<OpenStreamFunc>
|
|
34
|
+
// _openStreamFn resolves openStreamFn.
|
|
35
|
+
private _openStreamFn?: (conn?: OpenStreamFunc, err?: Error) => void
|
|
36
36
|
|
|
37
|
-
constructor(
|
|
38
|
-
this.
|
|
37
|
+
constructor(openStreamFn?: OpenStreamFunc) {
|
|
38
|
+
this.openStreamFn = this.setOpenStreamFn(openStreamFn)
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
//
|
|
42
|
-
public
|
|
43
|
-
if (this.
|
|
44
|
-
if (
|
|
45
|
-
this.
|
|
46
|
-
this.
|
|
41
|
+
// setOpenStreamFn updates the openStreamFn for the Client.
|
|
42
|
+
public setOpenStreamFn(openStreamFn?: OpenStreamFunc): Promise<OpenStreamFunc> {
|
|
43
|
+
if (this._openStreamFn) {
|
|
44
|
+
if (openStreamFn) {
|
|
45
|
+
this._openStreamFn(openStreamFn)
|
|
46
|
+
this._openStreamFn = undefined
|
|
47
47
|
}
|
|
48
48
|
} else {
|
|
49
|
-
if (
|
|
50
|
-
this.
|
|
49
|
+
if (openStreamFn) {
|
|
50
|
+
this.openStreamFn = Promise.resolve(openStreamFn)
|
|
51
51
|
} else {
|
|
52
|
-
this.
|
|
52
|
+
this.initOpenStreamFn()
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
|
-
return this.
|
|
55
|
+
return this.openStreamFn
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
//
|
|
59
|
-
private
|
|
58
|
+
// initOpenStreamFn creates the empty Promise for openStreamFn.
|
|
59
|
+
private initOpenStreamFn(): Promise<OpenStreamFunc> {
|
|
60
60
|
const openPromise = new Promise<OpenStreamFunc>((resolve, reject) => {
|
|
61
|
-
this.
|
|
61
|
+
this._openStreamFn = (conn?: OpenStreamFunc, err?: Error) => {
|
|
62
62
|
if (err) {
|
|
63
63
|
reject(err)
|
|
64
64
|
} else if (conn) {
|
|
@@ -66,8 +66,8 @@ export class Client implements TsProtoRpc {
|
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
})
|
|
69
|
-
this.
|
|
70
|
-
return this.
|
|
69
|
+
this.openStreamFn = openPromise
|
|
70
|
+
return this.openStreamFn
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
// request starts a non-streaming request.
|
|
@@ -168,8 +168,8 @@ export class Client implements TsProtoRpc {
|
|
|
168
168
|
rpcMethod: string,
|
|
169
169
|
data: Uint8Array | null
|
|
170
170
|
): Promise<ClientRPC> {
|
|
171
|
-
const
|
|
172
|
-
const conn = await
|
|
171
|
+
const openStreamFn = await this.openStreamFn
|
|
172
|
+
const conn = await openStreamFn()
|
|
173
173
|
const call = new ClientRPC(rpcService, rpcMethod)
|
|
174
174
|
pipe(
|
|
175
175
|
conn,
|
package/srpc/common-rpc.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Source, Sink } from 'it-stream-types'
|
|
2
2
|
import { pushable } from 'it-pushable'
|
|
3
3
|
|
|
4
|
-
import type { CallData, CallStart } from './rpcproto.js'
|
|
5
|
-
import { Packet } from './rpcproto.js'
|
|
4
|
+
import type { CallData, CallStart } from './rpcproto.pb.js'
|
|
5
|
+
import { Packet } from './rpcproto.pb.js'
|
|
6
6
|
|
|
7
7
|
// CommonRPC is common logic between server and client RPCs.
|
|
8
8
|
export class CommonRPC {
|
package/srpc/index.ts
CHANGED
|
@@ -5,8 +5,8 @@ import (
|
|
|
5
5
|
"io"
|
|
6
6
|
)
|
|
7
7
|
|
|
8
|
-
//
|
|
9
|
-
type
|
|
8
|
+
// MsgStream implements the stream interface passed to implementations.
|
|
9
|
+
type MsgStream struct {
|
|
10
10
|
// ctx is the stream context
|
|
11
11
|
ctx context.Context
|
|
12
12
|
// writer is the stream writer
|
|
@@ -15,10 +15,10 @@ type RPCStream struct {
|
|
|
15
15
|
dataCh chan []byte
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
//
|
|
18
|
+
// NewMsgStream constructs a new Stream with a ClientRPC.
|
|
19
19
|
// dataCh should be closed when no more messages will arrive.
|
|
20
|
-
func
|
|
21
|
-
return &
|
|
20
|
+
func NewMsgStream(ctx context.Context, writer Writer, dataCh chan []byte) *MsgStream {
|
|
21
|
+
return &MsgStream{
|
|
22
22
|
ctx: ctx,
|
|
23
23
|
writer: writer,
|
|
24
24
|
dataCh: dataCh,
|
|
@@ -26,12 +26,12 @@ func NewRPCStream(ctx context.Context, writer Writer, dataCh chan []byte) *RPCSt
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
// Context is canceled when the Stream is no longer valid.
|
|
29
|
-
func (r *
|
|
29
|
+
func (r *MsgStream) Context() context.Context {
|
|
30
30
|
return r.ctx
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
// MsgSend sends the message to the remote.
|
|
34
|
-
func (r *
|
|
34
|
+
func (r *MsgStream) MsgSend(msg Message) error {
|
|
35
35
|
select {
|
|
36
36
|
case <-r.ctx.Done():
|
|
37
37
|
return context.Canceled
|
|
@@ -48,7 +48,7 @@ func (r *RPCStream) MsgSend(msg Message) error {
|
|
|
48
48
|
|
|
49
49
|
// MsgRecv receives an incoming message from the remote.
|
|
50
50
|
// Parses the message into the object at msg.
|
|
51
|
-
func (r *
|
|
51
|
+
func (r *MsgStream) MsgRecv(msg Message) error {
|
|
52
52
|
select {
|
|
53
53
|
case <-r.Context().Done():
|
|
54
54
|
return context.Canceled
|
|
@@ -61,16 +61,16 @@ func (r *RPCStream) MsgRecv(msg Message) error {
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
// CloseSend signals to the remote that we will no longer send any messages.
|
|
64
|
-
func (r *
|
|
64
|
+
func (r *MsgStream) CloseSend() error {
|
|
65
65
|
outPkt := NewCallDataPacket(nil, false, true, nil)
|
|
66
66
|
return r.writer.WritePacket(outPkt)
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
// Close closes the stream.
|
|
70
|
-
func (r *
|
|
70
|
+
func (r *MsgStream) Close() error {
|
|
71
71
|
_ = r.writer.Close()
|
|
72
72
|
return nil
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
// _ is a type assertion
|
|
76
|
-
var _ Stream = ((*
|
|
76
|
+
var _ Stream = ((*MsgStream)(nil))
|
package/srpc/muxed-conn.go
CHANGED
|
@@ -14,7 +14,7 @@ func NewClientWithMuxedConn(conn network.MuxedConn) Client {
|
|
|
14
14
|
|
|
15
15
|
// NewOpenStreamWithMuxedConn constructs a OpenStream func with a MuxedConn.
|
|
16
16
|
func NewOpenStreamWithMuxedConn(conn network.MuxedConn) OpenStreamFunc {
|
|
17
|
-
return func(ctx context.Context, msgHandler
|
|
17
|
+
return func(ctx context.Context, msgHandler PacketHandler) (Writer, error) {
|
|
18
18
|
mstrm, err := conn.OpenStream(ctx)
|
|
19
19
|
if err != nil {
|
|
20
20
|
return nil, err
|
package/srpc/packet.ts
CHANGED
|
File without changes
|
package/srpc/server-pipe.go
CHANGED
|
@@ -9,7 +9,7 @@ import (
|
|
|
9
9
|
// Stream with the given Server. Starts read pumps for both. Starts the
|
|
10
10
|
// HandleStream function on the server in a separate goroutine.
|
|
11
11
|
func NewServerPipe(server *Server) OpenStreamFunc {
|
|
12
|
-
return func(ctx context.Context, msgHandler
|
|
12
|
+
return func(ctx context.Context, msgHandler PacketHandler) (Writer, error) {
|
|
13
13
|
srvPipe, clientPipe := net.Pipe()
|
|
14
14
|
go func() {
|
|
15
15
|
_ = server.HandleStream(ctx, srvPipe)
|
package/srpc/server-rpc.go
CHANGED
|
@@ -133,7 +133,7 @@ func (r *ServerRPC) HandleCallData(pkt *CallData) error {
|
|
|
133
133
|
func (r *ServerRPC) invokeRPC() {
|
|
134
134
|
// ctx := r.ctx
|
|
135
135
|
serviceID, methodID := r.service, r.method
|
|
136
|
-
strm :=
|
|
136
|
+
strm := NewMsgStream(r.ctx, r.writer, r.dataCh)
|
|
137
137
|
ok, err := r.mux.InvokeMethod(serviceID, methodID, strm)
|
|
138
138
|
if err == nil && !ok {
|
|
139
139
|
err = ErrUnimplemented
|
package/srpc/server-rpc.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Sink } from 'it-stream-types'
|
|
2
2
|
|
|
3
|
-
import type { CallData, CallStart } from './rpcproto.js'
|
|
3
|
+
import type { CallData, CallStart } from './rpcproto.pb.js'
|
|
4
4
|
import { CommonRPC } from './common-rpc.js'
|
|
5
5
|
import { InvokeFn } from './handler.js'
|
|
6
6
|
import { Mux } from './mux.js'
|
package/srpc/server.go
CHANGED
|
@@ -20,6 +20,11 @@ func NewServer(mux Mux) *Server {
|
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
// GetMux returns the mux.
|
|
24
|
+
func (s *Server) GetMux() Mux {
|
|
25
|
+
return s.mux
|
|
26
|
+
}
|
|
27
|
+
|
|
23
28
|
// HandleStream handles an incoming ReadWriteCloser stream.
|
|
24
29
|
func (s *Server) HandleStream(ctx context.Context, rwc io.ReadWriteCloser) error {
|
|
25
30
|
subCtx, subCtxCancel := context.WithCancel(ctx)
|
package/srpc/server.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { pipe } from 'it-pipe'
|
|
|
4
4
|
|
|
5
5
|
import { Mux } from './mux.js'
|
|
6
6
|
import { ServerRPC } from './server-rpc.js'
|
|
7
|
-
import { Packet } from './rpcproto.js'
|
|
7
|
+
import { Packet } from './rpcproto.pb.js'
|
|
8
8
|
import {
|
|
9
9
|
parseLengthPrefixTransform,
|
|
10
10
|
prependLengthPrefixTransform,
|
package/srpc/stream.ts
CHANGED
package/srpc/websocket.go
CHANGED
|
@@ -43,7 +43,7 @@ func (w *WebSocketConn) AcceptStream() (io.ReadWriteCloser, error) {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
// OpenStream tries to open a stream with the remote.
|
|
46
|
-
func (w *WebSocketConn) OpenStream(ctx context.Context, msgHandler
|
|
46
|
+
func (w *WebSocketConn) OpenStream(ctx context.Context, msgHandler PacketHandler) (Writer, error) {
|
|
47
47
|
muxedStream, err := w.mconn.OpenStream(ctx)
|
|
48
48
|
if err != nil {
|
|
49
49
|
return nil, err
|