Skip to content
This repository has been archived by the owner on Jun 13, 2023. It is now read-only.

After subscribing, no events handled, even though in React and websocket.org, it seems that the parse-server is working. #36

Closed
rodsfreitas opened this issue May 23, 2016 · 2 comments

Comments

@rodsfreitas
Copy link

rodsfreitas commented May 23, 2016

After lots of headaches, trials, errors and studying the examples, I couldn't receive any event on iOS after subscribing to Parse LiveQuery.

There's another thread on stack overflow with the same problem: http://stackoverflow.com/questions/37012451/livequery-not-responding

and now mine:
http://stackoverflow.com/questions/37381388/parse-livequery-subscription-doesnt-receive-any-events

I have configured a parse-server running LiveQuery on Amazon EC2 instance, on port 9091, with no proxy, firewall configurations made. It seems to be working fine, because we tested on React and using http://www.websocket.org/echo.html, telling that the connection was successful.

However on iOS, I couldn't make LiveQuery work, even though the handleSubscribe seems to be ok.

I've created a simple viewController to try it:

    import UIKit
    import Parse
    import ParseLiveQuery

    class StatsViewController: UIViewController {
        //MARK: - Outlets
        @IBAction func insertMessage(sender: AnyObject) {
            let message = Message();
            message.author = PFUser.currentUser()
            message.authorName = message.author?.username
            message.text = "Hello: \(NSDate())"
            message.roomName = "Test";

            message.saveInBackground();
        }

        //MARK: - Variables
        var myQuery: PFQuery {
            return (Message.query()?
                .whereKey("roomName", equalTo: "Test")
                .orderByAscending("createdAt"))!
        }

        var subscription: Subscription<Message>? = nil

        //MARK: - Lifecycle
        override func viewDidLoad() {
            super.viewDidLoad()

            //Registers the subclass
            Message.registerSubclass();
        }

        override func didReceiveMemoryWarning() {
            super.didReceiveMemoryWarning()
            // Dispose of any resources that can be recreated.
        }

        override func viewDidAppear(animated: Bool) {

            //1) queries for messages, working.
            myQuery.findObjectsInBackground().continueWithBlock() { res in
                for msg in ((res.result as? [Message]))! {
                    print(msg);
                }
                return nil
            }

            //2) try to subscribe and receive any information from the server
            subscription = myQuery.subscribe()

            subscription!.handleEvent { query, event in
                // Handle event
                print("any event, please?"); //no events handled after creating a new message
            }

            subscription!.handle(Event.Created) { query, object in
                // Called whenever an object was created
                print("any creation, please?"); //no events handled after creating a new message
            }

            subscription!.handleError { (query, err) in
                print("any error, please?"); //no errors handled
            }

            subscription!.handleSubscribe { query in
                print("subscribed")
            }
        }

    }

I also tried the subscription using the code in the parse example, like in

func subscribeToUpdates() {
    subscription = liveQueryClient
        .subscribe(messagesQuery)
        .handle(Event.Created) { _, message in
            self.printMessage(message)
    }
}

some information

  • subscriptions.handleSubscribe: prints "subscribed", but there's no way to check if it was successful
  • after inserting a new message or deleting a record on parse-dashboard, there's no event to be handled on iOS
  • there's no error or log in the parse-server
  • running parse-server 2.2.10 at port 9091

Is there any mistake or something missing in the subscription process?

Thanks!

@FredvanRijswijk
Copy link

I made a simpler version of the chatroom example and your example, I tested it and works fine https://github.com/FredvanRijswijk/ParseLiveQuery works only if you add a message for now

@tsanthosh
Copy link

Have the same issue. subscription.handleSubscribe prints "Subscribed" but couldn't get the events fired.

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

No branches or pull requests

4 participants