@@ -19,19 +19,17 @@ Can use any Stream multiplexer: defaults to [libp2p-mplex] over a WebSocket.
1919
2020# Usage  
2121
22- Starting with the [ protobuf-project]  repository on the "starpc" branch.
22+ Start with the [ protobuf-project]  template repository on the "starpc" branch.
23+ 
24+ [ protobuf-project ] : https://github.com/aperturerobotics/protobuf-project/tree/starpc 
2325
2426Use "git add" to add your new .proto files, then ` yarn gen `  to generate the
25- TypeScript and Go code for them .
27+ TypeScript and Go code.
2628
2729# Examples  
2830
29- See the [ protobuf-project]  template on the "starpc" branch.
30- 
3131The demo/boilerplate project implements the Echo example below.
3232
33- [ protobuf-project ] : https://github.com/aperturerobotics/protobuf-project/tree/starpc 
34- 
3533This repository uses protowrap, see the [ Makefile] ( ./Makefile ) .
3634
3735## Protobuf  
@@ -118,6 +116,7 @@ This example demonstrates both the server and client:
118116import  { pipe  } from  ' it-pipe' 
119117import  { createHandler , createMux , Server , Client , Conn  } from  ' srpc' 
120118import  { EchoerDefinition , EchoerServer , runClientTest  } from  ' srpc/echo' 
119+ import  { pushable  } from  ' it-pushable' 
121120
122121const   mux =  createMux ()
123122const   echoer =  new  EchoerServer ()
@@ -129,20 +128,31 @@ const serverConn = new Conn(server)
129128pipe (clientConn , serverConn , clientConn )
130129const   client =  new  Client (clientConn .buildOpenStreamFunc ())
131130
131+ //  call the unary rpc
132132console .log (' Calling Echo: unary call...'  )
133133let  result =  await  demoServiceClient .Echo ({
134134  body: ' Hello world!'  ,
135135})
136136console .log (' success: output'  , result .body )
137137
138- const  clientRequestStream  =   new   Observable < EchoMsg >( subscriber   =>  { 
139-    subscriber . next ({body:  ' Hello world from streaming request. '  })
140-    subscriber . complete ( )
141- } )
138+ //  create a client -> server stream 
139+ const  clientRequestStream  =   pushable < EchoMsg >({objectMode:  true })
140+ clientRequestStream . push ({body:  ' Hello world from streaming request. ' } )
141+ clientRequestStream . end ( )
142142
143+ //  call the client -> server streaming rpc
143144console .log (' Calling EchoClientStream: client -> server...'  )
144145result  =  await  demoServiceClient .EchoClientStream (clientRequestStream )
145146console .log (' success: output'  , result .body )
147+ 
148+ //  call the server -> client streaming rpc
149+ console .log (' Calling EchoServerStream: server -> client...'  )
150+ const   serverStream =  demoServiceClient .EchoServerStream ({
151+   body: ' Hello world from server to client streaming request.'  ,
152+ })
153+ for  await  (const   msg of  serverStream ) {
154+   console .log (' server: output'  , msg .body )
155+ }
146156``` 
147157
148158## WebSocket  
0 commit comments