johanbrandhorst / protobuf

GopherJS Bindings for ProtobufJS and gRPC-Web
MIT License
81 stars 16 forks source link

Allow forcing WebSocket as DialOption to address #35 #36

Closed mame82 closed 5 years ago

mame82 commented 5 years ago

As discussed, PR to enable WebSocket usage globally on Client creation via DialOption.

Example usage for a service called P4WNP1:

import pb "../proto/gopherjs" //refers to code generated by protoc-gen-gopherjs without further modifications

... snip ...

func main() {
    ...snip...
    cl := pb.NewP4WNP1Client(addr, grpcweb.ForceWebsocket) //client creation, forcing WebSocket usage
    ...snip...
}
mame82 commented 5 years ago

The failing test on git diff --exit-codeis weird, because I can't spot anything in the results which was caused by my changes. Hope you can handle this for me

johanbrandhorst commented 5 years ago

The failure is just a dependency change - it looks like all the tests passed otherwise. I will just clean it up a little bit and merge it, you've done all the hard work :).

johanbrandhorst commented 5 years ago

I changed it from a DialOption to a CallOption so it can be set per-call. In your case you could use it for that single call or you can use grpcweb.WithDefaultCallOptions(grpcweb.ForceWebsocketTransport()) when dialling. Also added some tests, and it works :).

mame82 commented 5 years ago

Works well. Thx so much !