Coder Social home page Coder Social logo

Comments (17)

palpatim avatar palpatim commented on May 30, 2024 3

@shannon-hager-skookum

Yes, I think it makes sense to reopen this, scoped to the simplified state I mentioned in the comment above. The biggest question in my mind is how we actually accomplish the "connected" state, since right now there's no really great hook from the underlying subscription connection that the service has begun fulfilling it. In testing, I'm working around this by inspecting the list of topics available on a subscription--once it moves to a non-empty list, then I'm interpreting that to mean the service is delivering subscriptions. But I'm not sure that's reliable, and I am sure I'd rather have a service-blessed mechanism for detecting that state. :) So part of this feature request will be to investigate the "right" way of fulfilling the "connected" state.

from aws-mobile-appsync-sdk-ios.

palpatim avatar palpatim commented on May 30, 2024 2

Clarification on the proposed statuses:

public enum SubscriptionWatcherStatus {
    /// The subscription is in process of connecting
    case connecting

    /// The subscription has connected and is receiving events from the service
    case connected

    /// The subscription has been disconnected because of a lifecycle event or manual disconnect request
    case disconnected

    /// The subscription is in an error state. The enum's associated value will provide more details, including recovery options if available.
    case error(AWSAppSyncSubscriptionError)
 }

from aws-mobile-appsync-sdk-ios.

palpatim avatar palpatim commented on May 30, 2024 1

@fans3210

Regarding your use case description:

UseCase:
For a chat app, normally I will unsubscribe all topics when the app entered background to reduce the battery and data cost. By exposing the detailed connection status to the developer, when app enters foreground again, I can manually handle retrieval of the chat messages I missed during the disconnection period.

AppSync currently suspends network activity when it enters the background, and resumes when the app resumes foreground. In addition, the recently-added Delta Sync feature basically does just what you specify: when creating a new sync subscription, the system will query for only the changes since the last successful sync.

Does that meet your needs for this use case?

If so, I'd like to scope down this feature request to providing better notification of an initial connection. Currently, there's no way to know that a subscription has been established and will start receiving updates, only that you've either a) received a new subscription message; or b) disconnected.

I propose a simplified state like:

public enum SubscriptionWatcherStatus {
    case connecting
    case connected
    case disconnected
    case error(AWSAppSyncSubscriptionError)
 }

and an appropriate refactoring of AWSAppSyncSubscriptionError to be enum, rather than struct, based, similar to what you show in your gist

Thoughts?

from aws-mobile-appsync-sdk-ios.

rohandubal avatar rohandubal commented on May 30, 2024

Hello @fans3210

Thanks for the feedback. Can you elaborate a little more?

For e.g. Do you want these states at a client level or at a subscription level? Can you elaborate the use-cases which you are targeting?

Thanks
Rohan

from aws-mobile-appsync-sdk-ios.

fans3210 avatar fans3210 commented on May 30, 2024

@rohandubal . I think the connection status for each topic should be on the client side like other xmpp service providers eg: Quickblox. Currently I applied this in my private fork of this repo. Currently what I did is some simple logics like below:

public typealias NonDisconnectionMQTTStateHandler = (MQTTStatus) -> Void

public func subscribeToCreateNewConversation(otherMQTTConnectionStateHandler: @escaping NonDisconnectionMQTTStateHandler, simpleResultHandler handler: @escaping SimpleSubResultHandler<Bool>) -> AWSAppSyncSubscriptionWatcher<NewConversationSubSubscription>? {
xxxxxx
}

I expose the connection status in the subscribe function temporarily. But I think a better place is in a delegation method like:
just for example:
func connectionStatusChanged(for watcher: toplic:)

UseCase:
For a chat app, normally I will unsubscribe all topics when the app entered background to reduce the battery and data cost. By exposing the detailed connection status to the developer, when app enters foreground again, I can manually handle retrieval of the chat messages I missed during the disconnection period.

from aws-mobile-appsync-sdk-ios.

MarioBajr avatar MarioBajr commented on May 30, 2024

Hi @fans3210, I have a branch fixing this waiting for #28 to be merged.
Feel free to test and check if it meets your needs.
https://github.com/EFEducationFirstMobile/aws-mobile-appsync-sdk-ios/tree/feature/observableSubscriptionState
or apply this diff on top of #28 https://gist.github.com/MarioBajr/d297cc0144a6e8fca4f6bd559946484b

from aws-mobile-appsync-sdk-ios.

fans3210 avatar fans3210 commented on May 30, 2024

@MarioBajr . Amazing. Tks

from aws-mobile-appsync-sdk-ios.

frankmuellr avatar frankmuellr commented on May 30, 2024

@rohandubal Looks like this PR was merged a while back. Can this issue be closed?

from aws-mobile-appsync-sdk-ios.

MarioBajr avatar MarioBajr commented on May 30, 2024

Hi @muellerfr,
I believe that you're referring to this PR #75 , and it hasn't been merged yet. In order to create the observable subscriptions status PR on top of the master branch I need the #28 to be accepted and merged.

from aws-mobile-appsync-sdk-ios.

fans3210 avatar fans3210 commented on May 30, 2024

@palpatim Sorry I don't know this issue is still opened. U guys did amazing jobs. The refactor is totally fine. Will reopen this issue when someone else requires such feature again. Thanks!

from aws-mobile-appsync-sdk-ios.

shannon-hager-skookum avatar shannon-hager-skookum commented on May 30, 2024

@palpatim I know this issue is closed but are you still planning to add the SubscriptionWatcherStatus enum?

from aws-mobile-appsync-sdk-ios.

achager avatar achager commented on May 30, 2024

@palpatim Would you be able to elaborate on what is considered the "connected" state in this scenario? Is it more than the web socket itself being open?

from aws-mobile-appsync-sdk-ios.

palpatim avatar palpatim commented on May 30, 2024

There is a delay between the time the socket is opened/connected to the server and the time the service begins delivering subscription updates to that socket. In our integration tests, we rely on either a hardcoded timeout or the aforementioned topic count to accommodate that.

from aws-mobile-appsync-sdk-ios.

achager avatar achager commented on May 30, 2024

@palpatim Those proposed status look good and should cover our use cases. Thanks!

from aws-mobile-appsync-sdk-ios.

palpatim avatar palpatim commented on May 30, 2024

Working on an implementation of this now.

from aws-mobile-appsync-sdk-ios.

palpatim avatar palpatim commented on May 30, 2024

This should be coming later today, but in the meantime, the API changes are as follows:

// New typealias:
public typealias SubscriptionStatusChangeHandler = (AWSAppSyncSubscriptionWatcherStatus) -> Void

// New status enum

/// The status of a SubscriptionWatcher
public enum AWSAppSyncSubscriptionWatcherStatus {
    /// The subscription is in process of connecting
    case connecting

    /// The subscription has connected and is receiving events from the service
    case connected

    /// The subscription has been disconnected because of a lifecycle event or manual disconnect request
    case disconnected

    /// The subscription is in an error state. The enum's associated value will provide more details, including recovery options if available.
    case error(AWSAppSyncSubscriptionError)
}


// New `statusChangeHandler` option to the AppSyncClient `subscribe()` method:

public func subscribe<Subscription: GraphQLSubscription>(subscription: Subscription,
                                                         queue: DispatchQueue = DispatchQueue.main,
                                                         statusChangeHandler: SubscriptionStatusChangeHandler? = nil,
                                                         resultHandler: @escaping SubscriptionResultHandler<Subscription>) throws -> AWSAppSyncSubscriptionWatcher<Subscription>?

The statusChangeHandler will be invoked upon status changes to the watcher's underlying MQTT client. This is specifically useful for monitoring when the watcher moves to .connected status, as it indicates that the watcher client has received a SUBACK from the MQTT broker and is receiving subscription messages from the service. At that point, it would be safe to update the UI with appropriate messaging, or issue a "catch up" query (in the case of a reconnect operation, as will be done automatically by Delta Sync in the sync method)

At this point, I expect the changes to be wholly additive, so they shouldn't break any existing implementations.

from aws-mobile-appsync-sdk-ios.

palpatim avatar palpatim commented on May 30, 2024

Sorry for missing the update on this issue, but we believe this was fixed by #196, and refined by @rohandubal on subsequent commits. I'm closing this issue but please do open a new one if you see use cases that aren't covered by this status reporting.

from aws-mobile-appsync-sdk-ios.

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.