GithubHelp home page GithubHelp logo

Comments (5)

adamhartford avatar adamhartford commented on August 19, 2024

Well, I can reproduce this. It also happens with Mobile Safari and a plain web client against my test SignalR server. Is it feasible to reconnect when the app enters the foreground?

from swiftr.

top2tech avatar top2tech commented on August 19, 2024

If I add manual reconnect on disconnected, it will reconnect after the app enters the foreground. Looks like this is a workaround.

The built in auto reconnect on disconnected seems not to kick in for this scenario.

from swiftr.

adamhartford avatar adamhartford commented on August 19, 2024

Commit 1bd2784 to SwiftR.js removed the 5 second auto-reconnect. I did this so you could stop/start the connection yourself without it reconnecting automatically after you stop. This would mean you need to reconnect manually on the disconnected event. I could make an autoReconnect property that lets you opt in/out of this behavior.

I don't know if there's some best practice for doing this with SignalR. FWIW, in my own use, I've never needed to stop/start the connection, and always relied on a 5 second auto-reconnect.

from swiftr.

top2tech avatar top2tech commented on August 19, 2024

Thanks, the manual reconnect works well so far.

from swiftr.

adamhartford avatar adamhartford commented on August 19, 2024

FYI, for anyone else that reads this: As of commit 8e3a34d, you could also use an error handler like this to reconnect on timeout:

connection.error = { error in 
  print("Error: \(error)")

  if let source = error?["source"] as? String where source == "TimeoutException" {
      print("Connection timed out. Restarting...")
      connection.start()
  }
}

from swiftr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.