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
Use addListener/removeListener approach. Library stores the list of callbacks to invoke, addListener adds that callback and removeListener removes it.
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.
Background
MediaManagerHandle.onDeviceChange
is called every time the list of connected devices change.Problem to solve
If there's multiple
MediaManagerHandle
s (all point out to the same media manager under the hood, I suppose), then changing theonDeviceChange
callback overwrites any previous callback being set.This is an essential problem, since our application uses separate
MediaManagerHandle
s in a call and in a microphone/camera/output switch modal, all having their ownonDeviceChange
callbacks to do different logic.Also it's impossible to remove the callback set, which should be possible.
Possible solutions
addListener
/removeListener
approach. Library stores the list of callbacks to invoke,addListener
adds that callback andremoveListener
removes it.StreamController.broadcast
, which is more preferred to my humble opinion, as API returns aStream
and developer may use it as they wish.