mediadevices icon indicating copy to clipboard operation
mediadevices copied to clipboard

Reduce mediadevices complexity

Open lherman-cs opened this issue 4 years ago • 2 comments

As of now, mediadevices uses many interfaces:

While using interfaces makes the design very flexible, it doesn't give that benefit for free. Following are some of the downsides:

  • Create some boilerplates and reduce maintainability because interfaces don't have implementation details. So, we'll always end up with 1 type for the interface and another type for the struct.
  • Increase API complexity if we overuse interfaces. Every time we use an interface, it adds a layer of indirection to the actual definition, which is ok if they're only a few defined interfaces. But, the problem quickly arises when we have multiple of them and they're spread all over the place in a package.
  • Reduce docs readability. I think this is similar to the second point. Since using interfaces adds an extra layer of indirection, it requires more thought process to the reader.

While I've laid out some of the downsides of using interfaces above, I still think that they're great and should be used appropriately. So, I think we should try to get rid of some of the interfaces and replace them with structs, we should remove the ones that don't require flexibilities.

In my opinion, we should convert MediaDevices and MediaStream interfaces to structs.

Note: Hopefully when pion/webrtc v3 is ready, Tracker and LocalTrack interfaces can get merged to pion/webrtc.

lherman-cs avatar Apr 19 '20 03:04 lherman-cs

@at-wat Do you have some thoughts on this?

lherman-cs avatar Apr 19 '20 03:04 lherman-cs

Do you still think this is something to do ? Do you have any new though now that pion/webrtc v3 is out ?

EmrysMyrddin avatar Jul 25 '22 20:07 EmrysMyrddin