instrumentisto / medea-jason

Mozilla Public License 2.0
2 stars 2 forks source link

Make `MediaManagerHandle.onDeviceChange` support broadcasting #104

Closed SleepySquash closed 1 year ago

SleepySquash commented 1 year ago

Background

MediaManagerHandle.onDeviceChange is called every time the list of connected devices change.

Problem to solve

If there's multiple MediaManagerHandles (all point out to the same media manager under the hood, I suppose), then changing the onDeviceChange callback overwrites any previous callback being set.

This is an essential problem, since our application uses separate MediaManagerHandles in a call and in a microphone/camera/output switch modal, all having their own onDeviceChange callbacks to do different logic.

Also it's impossible to remove the callback set, which should be possible.

Possible solutions

  1. Use addListener/removeListener approach. Library stores the list of callbacks to invoke, addListener adds that callback and removeListener removes it.
  2. Use a StreamController.broadcast, which is more preferred to my humble opinion, as API returns a Stream and developer may use it as they wish.