Comments (18)
Websocket support has been released in 0.6.1
, which is currently @latest
on npm.
As this is still opt-in support it must be enabled explicitly on both the client and server:
Enable Websocket support in the grpc-web Golang package:
grpcweb.WrapServer(grpcServer, grpcweb.WithWebsockets(true), grpcweb.WithWebsocketOriginFunc(func(req *http.Request) bool {
return true
}))
Specify that the client should use the Websocket transport factory for the rpc:
const myClient = grpc.client(MyService.MyMethod, {
host: myHost,
transport: grpc.WebsocketTransportFactory,
});
client.send(myFirstMsg);
client.send(mySecondMsg);
client.finishSend();
Whilst you can use transport: grpc.WebsocketTransportFactory
with grpc.unary
and grpc.invoke
, only grpc.client
allows client-streaming and bidi-streaming rpcs.
from grpc-web.
@johanbrandhorst that woudl be great.
Just for fun, I am playing around with exposing dgraph into react at the moment with gopherjs binding.
from grpc-web.
Please see #137
from grpc-web.
The tests contain examples of using bidi streaming: https://github.com/improbable-eng/grpc-web/blob/master/test/ts/src/client.websocket.spec.ts#L77
from grpc-web.
My gopherjs grpc-web library has been using the websocket transport by default since release v0.6.0. The demo at https://grpcweb.jbrandhorst.com uses it.
from grpc-web.
Currently websockets are not supported and neither is bidirectional streaming. @MarcusLongmuir is working on adding websocket support - https://github.com/MarcusLongmuir/grpc-web/tree/websockets
from grpc-web.
thanks @easyCZ :)
Have been using this:
https://github.com/johanbrandhorst/grpcweb-example
& for react front end this:
https://github.com/myitcv/react
It allows using protobuf for all Gets and Sets with a react front end.
Uses Websockets under the hood.
All the react code is written in golang too. Transpiled with gopherjs.
Not saying its the way to go, as there are drawbacks for sure.
But just putting here for reference.
@MarcusLongmuir
from grpc-web.
Only just discovered this issue, I'm the author of the GopherJS gRPC-Web bindings that add the websocket proxy for client-side and bidirectional streaming, happy to provide any lessons learned for getting this kind of thing into gRPC-Web.
from grpc-web.
Any update on websockets support?
from grpc-web.
since websocket support has merged(#137 ), does any one know client stream is possible now?
from grpc-web.
Yes, client side streaming and bidirectional streaming is possible with websockets enabled in the proxy
from grpc-web.
from grpc-web.
from grpc-web.
great news, so what's the next release time? and a bidi example would be helpful.
from grpc-web.
IIUC, the new websocket support will do an HTTP request for a single method call, which is then upgraded to a websocket. The websocket is used to transport the request body and the response, which allows streaming.
The new websocket support will not use a single websocket connection and multiplex multiple requests over this single connection (e.g. like normally happens on the grpc HTTP/2 transport).
Did I get that right?
from grpc-web.
Yes, that's right. It's not using websockets for request multiplexing. If you're interested, I think the websocket proxy code is an example of very nicely using the Go net/http
interfaces to encapsulate this fairly complex code: https://github.com/improbable-eng/grpc-web/blob/master/go/grpcweb/websocket_wrapper.go
from grpc-web.
@johanbrandhorst Have you tried this with the gopherjs client yet ? Not sure if you already are using it.
from grpc-web.
from grpc-web.
Related Issues (20)
- grpcwebproxy websocket connection fails with specific origin HOT 2
- QUIC and HTTP3 support HOT 1
- Status codes and error messages are displayed incorrectly on the angular client. HOT 4
- Golang Grpc Web Server UnaryInterceptor is not triggered by grpc-web Client HOT 1
- Get client stream method return HOT 3
- ReferenceError: self is not defined when trying to call a grpc-web function from a CLI/server application HOT 3
- grpcwebproxy - Help Proxying existing GRPC service HOT 1
- Add support of bufbuild/protobuf-es HOT 3
- Changing route to the root of the host HOT 1
- Lack of grpc Trailers-Only support in the wrapHandler function
- Is there any way to use Nginx or Envoy with this project? HOT 1
- Question: What is the status of `go/grpcwebproxy` project? HOT 3
- grpc-web: Importing as ESModule in Node HOT 1
- grpcwebproxy `--allowed_headers` param is case-sensitive for WebSocket
- Grpc client unexpected behavior HOT 1
- Project status
- grpc-web. `Response closed without headers` but no way to get the status code.
- grpcwebproxy: 400 bad request on websocket connection attempts HOT 1
- How to set a fieldmask on a grpc request? HOT 1
- Bump nhooyr.io/websocket HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from grpc-web.