Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can we get any callback when Bidirectional stream gets disconnected by the server. #1841

Open
araisuki opened this issue Mar 24, 2024 · 2 comments
Labels

Comments

@araisuki
Copy link

What are you trying to achieve?

We are connected to our backend service and backend exposes a bidirectional stream which used to for continuous audio streaming. We are facing an problem that this bidirectional stream automatically closes by the backend service by default it gets disconnected if we keep the stream idle for 30 sec(configuration in our backend). So we wont keep the stream idle for more than 30sec.
Still in some rare scenario the stream gets disconnect by the backend service, My question is is there any way to client to get to know about the stream disconnection via any callback? When the service disconnects we get a delegate callback, But I am unable get any details on callback option when the stream disconnects.

Here is our backend protos

service Mic { rpc AudioStream(stream MicRequest) returns (stream MicResponse); rpc SendNoteType(NoteType) returns (google.protobuf.Empty); }

Here is the swift code that connects to the stream

mobileAsMicBidiStream = mobileAsMicClient.audioStream(handler: { response in self.serialResponseQueue.async { self.micResponseHandler.handleMicResponse(micResponse: response, stream: self) } })

What have you tried so far?

Tried searching for any callbacks on stream disconnection but couldn't find any details on that.

@glbrntt
Copy link
Collaborator

glbrntt commented Mar 25, 2024

Still in some rare scenario the stream gets disconnect by the backend service, My question is is there any way to client to get to know about the stream disconnection via any callback? When the service disconnects we get a delegate callback, But I am unable get any details on callback option when the stream disconnects.

You can add a callback to the status future which indicates when the RPC has finished. Extending your example this would be something like:

mobileAsMicBidiStream.whenSuccess { status in 
  // ...
}

@araisuki
Copy link
Author

araisuki commented Mar 25, 2024

@glbrntt The bidirectional stream mobileAsMicBidiStream doesn't expose any method whenSuccess, Are you saying whenever I send a message in mobileAsMicBidiStream using the method sendMessage should we listen for success or failure? I have attached the code below

mobileAsMicBidiStream?.sendMessage(request).whenComplete({

})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants