Git Product home page Git Product logo

Comments (13)

mahadevTW avatar mahadevTW commented on August 25, 2024

Always try to connect, and through an error "Swift ddp connection closed with error 1000, clean true "
and in loop try to connect -> again fail->again subscription fail....

from swiftddp.

siegesmund avatar siegesmund commented on August 25, 2024

Can you share the code you're trying to run to connect and subscribe?

from swiftddp.

mahadevTW avatar mahadevTW commented on August 25, 2024

I have a code given below. Once error come "Swift ddp connection closed with error 1000, clean true " it tries to reconnect , So calls Meteor.connect but fail to subscribe and shows "already subscribed" and same cycle repeats. Also I don't get any updates from server. And also I am not getting any 'pong' messages, although i am having good network connection, still it gives me error periodically.
. I am new at swift so it may be my implementation mistake. Thanking you in anticipation.

`func connectToServer(collectionId: String) -> Bool {
Meteor.connect(Config.URL) {
self.subscribe(collectionId)
}
return true
}

private func subscribe(collectionId : String) {
    Meteor.subscribe("collection name" , params: [collectionId]) {
        self.collectionId = collectionId
        self.collectionSubscriptionIsReady("connected")
    }
}


private func collectionSubscriptionIsReady(result : String) {
    print("Subscribed to collectoin ");
    delagate?.connected(result)
}`

from swiftddp.

siegesmund avatar siegesmund commented on August 25, 2024

I don't see anything obviously wrong, but you're wrapping all of the Meteor methods in your own class, and I wonder how you're using that class.

  1. First, have you enabled logging? swift Meteor.client.logLevel = .Debug before you connect. That would enable you to see pongs, as well as other debug messages.
  2. Where are you making your connection and subscription? You should only do this once in the app, and doing this in your AppDelegate is a good place to do it.

from swiftddp.

SwapnilBGaikwad avatar SwapnilBGaikwad commented on August 25, 2024

I have one app in which I need to subscribe to the one collection with specific ID as like mahadevTW's code.
If user want to open another data set in same collection with different ID, So we need to subscribe to the another Data Set from the same collection. So I need to unsubscribe and again resubscribe to the same collection with new ID.
Once reconnection is done it shows "Swift ddp connection closed with error 1000, clean true " and it will again subscribe and the cycle continues.

Due to different ID I need to call subscribe multiple times , which leads to previous error "connection closed"
My Server side code of publish is as follows :

Meteor.publish('collection', function (id) { return Collecion.find({$or:[{_id:id},{rootId:id}]}); });

And subscribe code is similar to MahadevTW.
So Is their be any appropriate way to resubscribe to the same collection with different parameters.

from swiftddp.

siegesmund avatar siegesmund commented on August 25, 2024

Thanks @SwapnilBGaikwad and @mahadevTW . I haven't encountered this issue before. I think there's an issue here, but it's tough to say what the issue is without being able to run the code. Would it be possible for one or both of you create a github repo with code that reproduces this issue?

from swiftddp.

SwapnilBGaikwad avatar SwapnilBGaikwad commented on August 25, 2024

I have created the repo on git hub which will shows the above connection closed error.
Here is the link of git hub repo.

https://github.com/SwapnilBGaikwad/SampleSwiftDDPCode.git

I have connected to the meteor site called http://www.mindit.xyz/create/zxg6nK4gdvNnL9yof
So please tell me proper way to deal with such situation in which I need to
subscribe to the collection with the same collection name but with different collection id.

from swiftddp.

siegesmund avatar siegesmund commented on August 25, 2024

@SwapnilBGaikwad

I see now what you are doing.

Please see the todos example. It illustrates exactly what you are trying to do.

The short answer is: handle your subscription when you instantiate your view controller. Unsubscribe to the subscription when the view controller will disappear. viewWillDisappear is a good place to do this, as shown in the example.

Second, and importantly, you should only instantiate Meteor once, and this should probably be done in your app delegate. Again, see the example. You are trying to reconnect each time the user moves to MapTableViewController via your MeteorTracker class that wraps Meteor. This is wrong. So, one connection per app session.

I would get rid of the MeteorTracker class. Unless you instantiate MeteorTracker in AppDelegate, and remove the subscription logic from it, you really can't handle the subscriptions correctly. And if you do that, it's not doing much as a wrapper.

Finally, I ran your code for about 15 minutes, in several sessions and didn't get the "Swift ddp connection closed with error 1000, clean true ."

from swiftddp.

SwapnilBGaikwad avatar SwapnilBGaikwad commented on August 25, 2024

Thank you for your suggest I have implemented in my app and seems to be working fine.
But now I need to open my app from using custom URL scheme.
So when I opened for first time and subscribed and pressed home then try to open the app with new subscription parameter (id) passed in URL. So it says already subscribed and new subscription fails as expected.
In this condition , is their be any way to reset the things that are already subscribed when entered in AppDelegate method :

func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool

from swiftddp.

siegesmund avatar siegesmund commented on August 25, 2024

I'm not sure I understand what you're trying to do. The way to reset a subscription is to unsubscribe from the publication.

from swiftddp.

SwapnilBGaikwad avatar SwapnilBGaikwad commented on August 25, 2024

If I opened app and subscribed with specific subscription parameter (id).
Now my app is connected and subscribed state.
In my app I am unsubscribing the collection in viewWillDisappear.
If subscription is done app and user then open app using URL scheme
e.g. myapp://id
then it simple say already subscribed as expected.
So I need to know in such a condition how to unsubscribe to collection.

If I unsubscribe when app goes in background then user will not get updates when user open the app present in background.

from swiftddp.

siegesmund avatar siegesmund commented on August 25, 2024

In this instance, I think the appropriate action is to unsubscribe and then resubscribe. Unsubscribe from your publications when the app will enter the background, and resubscribe when when the app becomes active again.

from swiftddp.

SwapnilBGaikwad avatar SwapnilBGaikwad commented on August 25, 2024

Your suggestion really helped me to resolve all of the error.
Thanks for your support.
👍

from swiftddp.

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.