Skip to content

Commit

Permalink
feat: support grpc-web client straming (#617)
Browse files Browse the repository at this point in the history
* grpc-web-go-server test use go module

* grpc-web: fix undefine message

* try websocket

* fix websocket

* merge rpcOptions and metadata

* use rxjs

* generate grpc-web client streaming

* update grpc-web generate code

* update test

* fix: grpc-web methodDesc

* feat: only client-stream example

* Run prettier.

Co-authored-by: Stephen Haberman <stephen.haberman@gmail.com>
  • Loading branch information
luhuaei and stephenh authored Jul 21, 2022
1 parent 60b0a91 commit d3e7f1f
Show file tree
Hide file tree
Showing 28 changed files with 3,765 additions and 95 deletions.
1 change: 1 addition & 0 deletions integration/grpc-web-go-server/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
grpc-web-go-server
10 changes: 3 additions & 7 deletions integration/grpc-web-go-server/build.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
#!/usr/bin/env bash

set -x
export GOPATH=$HOME/go

# See https://grpc.io/docs/languages/go/quickstart/
# go get google.golang.org/protobuf/cmd/protoc-gen-go
# go get google.golang.org/grpc/cmd/protoc-gen-go-grpc
#
# go get github.com/improbable-eng/grpc-web/go/grpcweb
GO111MODULE=on go mod tidy

go build

mkdir -p generated
protoc -I=. --go_out=generated/ --go-grpc_out=require_unimplemented_servers=false:generated/ example.proto

Binary file modified integration/grpc-web-go-server/example.bin
Binary file not shown.
4 changes: 3 additions & 1 deletion integration/grpc-web-go-server/example.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ option go_package = "lib/rpx";
service DashState {
rpc UserSettings(Empty) returns (DashUserSettingsState);
rpc ActiveUserSettingsStream(Empty) returns (stream DashUserSettingsState);
rpc ManyUserSettingsStream(stream DashUserSettingsState) returns (DashUserSettingsState);
rpc ChangeUserSettingsStream (stream DashUserSettingsState) returns (stream DashUserSettingsState) {}
}

message DashFlash {
Expand Down Expand Up @@ -65,4 +67,4 @@ message DashAPICredsDeleteReq {
string id = 3;
}

message Empty {}
message Empty {}
16 changes: 16 additions & 0 deletions integration/grpc-web-go-server/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,8 @@ export const Empty = {
export interface DashState {
UserSettings(request: Empty): Promise<DashUserSettingsState>;
ActiveUserSettingsStream(request: Empty): Observable<DashUserSettingsState>;
ManyUserSettingsStream(request: Observable<DashUserSettingsState>): Observable<DashUserSettingsState>;
ChangeUserSettingsStream(request: Observable<DashUserSettingsState>): Observable<DashUserSettingsState>;
}

export class DashStateClientImpl implements DashState {
Expand All @@ -601,6 +603,8 @@ export class DashStateClientImpl implements DashState {
this.rpc = rpc;
this.UserSettings = this.UserSettings.bind(this);
this.ActiveUserSettingsStream = this.ActiveUserSettingsStream.bind(this);
this.ManyUserSettingsStream = this.ManyUserSettingsStream.bind(this);
this.ChangeUserSettingsStream = this.ChangeUserSettingsStream.bind(this);
}
UserSettings(request: Empty): Promise<DashUserSettingsState> {
const data = Empty.encode(request).finish();
Expand All @@ -613,6 +617,18 @@ export class DashStateClientImpl implements DashState {
const result = this.rpc.serverStreamingRequest('rpx.DashState', 'ActiveUserSettingsStream', data);
return result.pipe(map((data) => DashUserSettingsState.decode(new _m0.Reader(data))));
}

ManyUserSettingsStream(request: Observable<DashUserSettingsState>): Observable<DashUserSettingsState> {
const data = request.pipe(map((request) => DashUserSettingsState.encode(request).finish()));
const promise = this.rpc.clientStreamingRequest('rpx.DashState', 'ManyUserSettingsStream', data);
return promise.then((data) => DashUserSettingsState.decode(new _m0.Reader(data)));
}

ChangeUserSettingsStream(request: Observable<DashUserSettingsState>): Observable<DashUserSettingsState> {
const data = request.pipe(map((request) => DashUserSettingsState.encode(request).finish()));
const result = this.rpc.bidirectionalStreamingRequest('rpx.DashState', 'ChangeUserSettingsStream', data);
return result.pipe(map((data) => DashUserSettingsState.decode(new _m0.Reader(data))));
}
}

/**
Expand Down
88 changes: 49 additions & 39 deletions integration/grpc-web-go-server/generated/lib/rpx/example.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d3e7f1f

Please sign in to comment.