grpc / grpc-web

gRPC for Web Clients
https://grpc.io
Apache License 2.0
8.59k stars 765 forks source link

No events when using server-side streaming RPC with React Native (with `mode=grpcweb`) #1345

Closed VincentMarnier closed 1 year ago

VincentMarnier commented 1 year ago

Hello, I am using grpc-web with React Native for my client and ASP.NET + Grpc.AspNetCore.Web package for my server. So far unary calls work wonderfuly, yet when I try to use server-side streaming RPC, I receive no events. If the server ends the connection, every events from the begining of the connection are raised all at once. It feels like events are not flushed as soon as possible or something. My problem seems not to come from the server as it works if I am using grpc-web from a C# client (source: https://learn.microsoft.com/en-us/aspnet/core/grpc/grpcweb?view=aspnetcore-7.0#configure-grpc-web-with-the-net-grpc-client).

My code exactly:

const chatClient = new ChatClient("my_hostname")
const request = new JoinRoomRequest();
request.setRoomid(roomId);
chatClient.joinRoom(request)
  .on('error', error => {
    console.log('ERROR!')
    console.error(error)
  })
  .on('metadata', metadata => {
    console.log('METADATA!')
    console.log(metadata);
  })
  .on("data", ev => {
    console.log('DATA!')
    console.log(ev)
  })
  .on('status', status => {
    console.log('STATUS!')
    console.log(status);
  })
  .on('end', () => {
    console.log('END!')
  });

ChatClient is generated using: protoc -I=Chat/ --js_out=import_style=commonjs,binary:webclient/Chat/src/APIClient --grpc-web_out=import_style=typescript,mode=grpcweb:webclient/Chat/src/APIClient Chat/*.proto

Is there something I am missing?

VincentMarnier commented 1 year ago

Just so you know, it works if I use mode=grpcwebtext and --js_out=import_style=commonjs instead of mode=grpcweb and --js_out=import_style=commonjs,binary.

I will stick with text for now so. Not sure if it is an issue from grpc-web or if I misunderstood something out there. I'm leaving it open in case it is a bug, feel free to close it if it is not!

sampajano commented 1 year ago

Hi thanks for the report!

Actually, i think what you've observed is expected — streaming is currently only supported with mode=grpcwebtext but not mode=grpcweb, as documented here.. :)

I'm sorry for the inconvenience but for now you need to use grpcwebtext if you want server streaming. :)

I'm closing this issue but feel free to reopen or follow up with more details if needed. Thanks!