watchMultiple method

Stream<List<CloudMediaItem>> watchMultiple(
  1. List<String> mediaIds
)

Watch multiple media items simultaneously.

Emits the full updated list whenever any item changes.

watcher.watchMultiple([id1, id2, id3]).listen((items) {
  print('${items.length} items updated');
});

Implementation

Stream<List<CloudMediaItem>> watchMultiple(List<String> mediaIds) {
  final controller = StreamController<List<CloudMediaItem>>.broadcast();
  final current = <String, CloudMediaItem>{};

  for (final id in mediaIds) {
    CloudMedia.watch(id).listen((item) {
      current[id] = item;
      controller.add(current.values.toList());
    });
  }

  return controller.stream;
}