tmc / grpc-websocket-proxy

A proxy to transparently upgrade grpc-gateway streaming endpoints to use websockets
MIT License
553 stars 72 forks source link

Add a client example #3

Open johanbrandhorst opened 7 years ago

johanbrandhorst commented 7 years ago

Either using gopherjs or pure JS, just to illustrate how the MethodOverrideParam interacts with the grpc-gateway exposed gRPC methods. Probably an example of authentication too would be nice.

prince-mishra commented 7 years ago

@tmc @johanbrandhorst Can you please add an example client code? I cannot get my head around it. I have a "streamingCall" exposed over gRPC. How do I interact with it once I add the wsproxy?

johanbrandhorst commented 7 years ago

@prince-mishra you'll need to write a websocket client. It'll depend very much on how you're talking to your server. You can look at https://github.com/johanbrandhorst/gopherjs-grpc-websocket/blob/master/client/client.go for a GopherJS example of how to use the websocket.

prince-mishra commented 7 years ago

@johanbrandhorst Thank you so much! That helps a lot. I'll be testing it out in the browser.

prince-mishra commented 7 years ago

@johanbrandhorst using your go client code as referrence, I was able to connect and send messages to the proxy layer. The goes like this:

var wsUri = "ws://localhost:8089/v1/bidi";

websocket = new WebSocket(wsUri);

....

websocket.send(message);

This means I need to open new websockets for every API. Is there a way to reuse the websocket on client side? Can I use the existing websocket for /v1/bidi and /api2/bidi2?

johanbrandhorst commented 7 years ago

I'm afraid I don't know enough about websockets, but it appears you'll need to create a new websocket for each API endpoint. Also the connection will be closed when the bidi stream is closed so you'll need to create a new websocket every time to want to make the call.