Apollo-ios: Adjusting the reconnection behaviour of `WebSocketTransport`

Created on 29 Jul 2020  ·  8Comments  ·  Source: apollographql/apollo-ios

Hello!

I have a similar setup to https://github.com/apollographql/apollo-ios/pull/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!

apollo-websockets question

All 8 comments

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

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

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.

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

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

Ok, thank you so much!

好的,非常感谢你!

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

This has shipped with 0.31.0.

Was this page helpful?
0 / 5 - 0 ratings