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

Adjusting the reconnection behaviour of WebSocketTransport #1333

Closed
ketenshi opened this issue Jul 29, 2020 · 8 comments
Closed

Adjusting the reconnection behaviour of WebSocketTransport #1333

ketenshi opened this issue Jul 29, 2020 · 8 comments
Labels
apollo-websockets question Issues that have a question which should be addressed
Milestone

Comments

@ketenshi
Copy link
Contributor

ketenshi commented Jul 29, 2020

Hello!

I have a similar setup to #1224 but with the caveat of requiring the user to login again in some cases. With an invalid connectingPayload the server closes the connection immediately, and WebSocketTransport will keep retrying. The connectingPayload can be updated with the new authentication token after the user logs in again.

I would like to add in the ability to either prevent WebSocketTransport from reconnecting or be able to pause the websocket.

If we go the route of adjusting the reconnection behaviour I was thinking of adding something similar to HTTPNetworkTransportRetryDelegate but that kind of goes against the idea of passing reconnect as part of the initialization. So maybe having a getter/setter might be best.

Hope that I can get some guidance/feedback on this. Thanks!

@designatednerd
Copy link
Contributor

Does closeConnection on WebSocketTransport do what you need it to? That explicitly sets reconnect.value to false.

@ketenshi
Copy link
Contributor Author

I'd like to keep existing subscriptions so unfortunately closeConnection isn't viable.

@designatednerd designatednerd added apollo-websockets question Issues that have a question which should be addressed labels Jul 29, 2020
@designatednerd
Copy link
Contributor

So you're thinking more like this:

  public func pauseWebSocketConnection() {
    self.reconnect.value = false
    self.websocket.disconnect()
  }
  
  public func resumeWebSocketConnection(autoReconnect: Bool = true) {
    self.reconnect.value = autoReconnect
    self.websocket.connect()
  }

I think that could work with a sufficient documentation warning that if you call pause you have to manually call resume.

@ketenshi
Copy link
Contributor Author

Yes that's essentially what I want. Thanks for the suggestion, I'll have something in the next few days.

@designatednerd
Copy link
Contributor

Eh, if that's all you need i'll just do it and throw in a test 😇

@ketenshi
Copy link
Contributor Author

Ok, thank you so much!

@tanchendong1992
Copy link

好的,非常感谢你!

你好 我想问下 如果 在 APP 进入后台时,手动断开长连接. APP 重新唤起时连接长连接呢

@designatednerd designatednerd added this to the 0.31.0 milestone Aug 20, 2020
@designatednerd
Copy link
Contributor

This has shipped with 0.31.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
apollo-websockets question Issues that have a question which should be addressed
Projects
None yet
Development

No branches or pull requests

3 participants