Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support error & loading progress feedback to browser clients via MediaLibraryService #1322

Open
Ethan1983 opened this issue Apr 28, 2024 · 7 comments
Assignees
Labels

Comments

@Ethan1983
Copy link

MediaLibraryService to support loading progress feedback to connected browsers

MediaLibraryService loads data from the filesystem and knows the total number of files in advance and would like to provide progress feedback to connected browsers. Likewise, would also like to notify of any errors.

Proposed solution

MediaLibraryService to support a loading and error API/protocol which could be invoked by the service for every onGetChildren request. This could support a bundle for any custom application specific payload. Connected browsers can use the payload to update UI to give more useful feedback than just displaying an infinite loading indicator. Load, data and error states is a typical flow in any application and an out of box support would be nice.

Alternatives considered

Alternative is to use custom messages via sendCustomCommand on the media session and this needs some coordination on the browser side between different callbacks. Also, this kind of custom solutions is duplicated across different applications.

@tonihei
Copy link
Collaborator

tonihei commented May 2, 2024

If I understand the proposal correctly, this should already work by calling MediaBrowser.subscribe first, which returns onChildrenChanged with the total number of children and then the browser can request the items individually with getChildren(..., pageSize=1,..). Would that work for your use case?

@Ethan1983
Copy link
Author

If I understand the proposal correctly, this should already work by calling MediaBrowser.subscribe first, which returns onChildrenChanged with the total number of children and then the browser can request the items individually with getChildren(..., pageSize=1,..). Would that work for your use case?

Thanks. So in this case, when the service doesn't have the data in onChildrenChanged and it will return a ListenableFuture. How will the loading progress (like % downloaded) be relayed to the client?

@tonihei
Copy link
Collaborator

tonihei commented May 20, 2024

onChildrenChanged will just notify about the number of items, which should ideally be quick. And the the MediaBrowser can do something like:

public void onChildrenChanged(..., int ItemCount,...) {
  AtomicInteger loadedItems = new AtomicInteger(0); 
  updateProgressBar(0);
  for (int i = 0; i < itemCount; i  ) {
    ListenableFuture<..> childFuture = getChildren(..., /* page */ i, /* pageSize */ 1, ...);
    Futures.addCallback(childFuture, new FutureCallback<>() {
        public void onSuccess(...) {
           loadedItems  ;
           updateProgressBar(loadedItems / itemCount);
        }

        public void onFailure(...) { }
    });
  }
}

@Ethan1983
Copy link
Author

onChildrenChanged will just notify about the number of items, which should ideally be quick. And the the MediaBrowser can do something like:

public void onChildrenChanged(..., int ItemCount,...) {
  AtomicInteger loadedItems = new AtomicInteger(0); 
  updateProgressBar(0);
  for (int i = 0; i < itemCount; i  ) {
    ListenableFuture<..> childFuture = getChildren(..., /* page */ i, /* pageSize */ 1, ...);
    Futures.addCallback(childFuture, new FutureCallback<>() {
        public void onSuccess(...) {
           loadedItems  ;
           updateProgressBar(loadedItems / itemCount);
        }

        public void onFailure(...) { }
    });
  }
}

In our case, the total number of items isn't known in advance and determining that itself takes a while from the service end.

@tonihei
Copy link
Collaborator

tonihei commented Jun 17, 2024

In our case, the total number of items isn't known in advance and determining that itself takes a while from the service end.

In this case I can only recommend sending sendCustomCommand, as you already pointed out yourself. Do you have another API in mind that would you would really like to see in the library? I can't really see a good way to fit your feature request into the existing APIs, so I'm curious if you already had something in mind.

@Ethan1983
Copy link
Author

In our case, the total number of items isn't known in advance and determining that itself takes a while from the service end.

In this case I can only recommend sending sendCustomCommand, as you already pointed out yourself. Do you have another API in mind that would you would really like to see in the library? I can't really see a good way to fit your feature request into the existing APIs, so I'm curious if you already had something in mind.

On top of my head, APIs could leverage the existing notify pattern from service end, notifyLoading(Bundle), notifyError(Bundle) and clients could have callbacks similar to onChildrenChanged.

@tonihei
Copy link
Collaborator

tonihei commented Jun 24, 2024

Thanks, in this case sending a custom message is probably most useful still because the requirements for such a loading callback may be quite different between apps. I can only imagine that having a dedicated method makes sense when where is a generic controller that can display the progress from all apps. The proposed notifyLoading(bundle) method is very similar to sendCustomCommand(progressCommand, bundle) in your code in the end as well.

In the interest of providing a reactive interface, you may also want to publish a small number of items initially, and then later call notifyChildrenChanged once your backend has loaded more items.

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

No branches or pull requests

3 participants