Giter VIP home page Giter VIP logo

Comments (18)

MarcusLongmuir avatar MarcusLongmuir commented on September 4, 2024 19

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.

 avatar commented on September 4, 2024 2

@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.

easyCZ avatar easyCZ commented on September 4, 2024 2

Please see #137

from grpc-web.

johanbrandhorst avatar johanbrandhorst commented on September 4, 2024 2

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.

johanbrandhorst avatar johanbrandhorst commented on September 4, 2024 2

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.

easyCZ avatar easyCZ commented on September 4, 2024

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.

 avatar commented on September 4, 2024

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.

johanbrandhorst avatar johanbrandhorst commented on September 4, 2024

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.

abemedia avatar abemedia commented on September 4, 2024

Any update on websockets support?

from grpc-web.

dbskccc avatar dbskccc commented on September 4, 2024

since websocket support has merged(#137 ), does any one know client stream is possible now?

from grpc-web.

johanbrandhorst avatar johanbrandhorst commented on September 4, 2024

Yes, client side streaming and bidirectional streaming is possible with websockets enabled in the proxy

from grpc-web.

 avatar commented on September 4, 2024

from grpc-web.

jonnyreeves avatar jonnyreeves commented on September 4, 2024

from grpc-web.

dbskccc avatar dbskccc commented on September 4, 2024

great news, so what's the next release time? and a bidi example would be helpful.

from grpc-web.

matthijskooijman avatar matthijskooijman commented on September 4, 2024

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.

johanbrandhorst avatar johanbrandhorst commented on September 4, 2024

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.

 avatar commented on September 4, 2024

@johanbrandhorst Have you tried this with the gopherjs client yet ? Not sure if you already are using it.

from grpc-web.

 avatar commented on September 4, 2024

from grpc-web.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.