listDevices method

dynamic listDevices (
  1. Function callback,
  2. Map config
)

Implementation

static listDevices(Function callback, Map config) {
  if (config == null) {
    config = {
      'audio': true,
      'video': true,
    };
    MediaDevices.getUserMedia(config).then((MediaStream stream) {
      MediaDevices.getSources().then((devices) {
        Janus.debug(devices.toString());
        callback(devices);
        // Get rid of the now useless stream
        try {
          List<MediaStreamTrack> audioTracks = stream.getAudioTracks();
          for (var mst in audioTracks) {
            if (mst != null) mst.dispose();
          }
          List<MediaStreamTrack> videoTracks = stream.getVideoTracks();
          for (var mst in videoTracks) {
            if (mst != null) mst.dispose();
          }
        } catch (e) {
          Janus.error(e);
        }
      }).catchError((err) => Janus.error(err));
    }).catchError((err) => Janus.error(err));
  }
}