LCOV - code coverage report
Current view: top level - lib/src/voip/utils - stream_helper.dart (source / functions) Hit Total Coverage
Test: merged.info Lines: 5 25 20.0 %
Date: 2024-09-04 20:26:16 Functions: 0 0 -

          Line data    Source code
       1             : import 'package:collection/collection.dart';
       2             : import 'package:random_string/random_string.dart';
       3             : import 'package:webrtc_interface/webrtc_interface.dart';
       4             : 
       5             : import 'package:matrix/matrix.dart';
       6             : 
       7           2 : Future<void> stopMediaStream(MediaStream? stream) async {
       8             :   if (stream != null) {
       9           2 :     for (final track in stream.getTracks()) {
      10             :       try {
      11           0 :         await track.stop();
      12             :       } catch (e, s) {
      13           0 :         Logs().e('[VOIP] stopping track ${track.id} failed', e, s);
      14             :       }
      15             :     }
      16             :     try {
      17           2 :       await stream.dispose();
      18             :     } catch (e, s) {
      19           0 :       Logs().e('[VOIP] disposing stream ${stream.id} failed', e, s);
      20             :     }
      21             :   }
      22             : }
      23             : 
      24           0 : void setTracksEnabled(List<MediaStreamTrack> tracks, bool enabled) {
      25           0 :   for (final element in tracks) {
      26           0 :     element.enabled = enabled;
      27             :   }
      28             : }
      29             : 
      30           0 : Future<bool> hasMediaDevice(
      31             :     WebRTCDelegate delegate, MediaInputKind mediaInputKind) async {
      32           0 :   final devices = await delegate.mediaDevices.enumerateDevices();
      33             :   return devices
      34           0 :       .where((device) => device.kind == mediaInputKind.name)
      35           0 :       .isNotEmpty;
      36             : }
      37             : 
      38           0 : Future<void> updateMediaDevice(
      39             :   WebRTCDelegate delegate,
      40             :   MediaKind kind,
      41             :   List<RTCRtpSender> userRtpSenders, [
      42             :   MediaStreamTrack? track,
      43             : ]) async {
      44             :   final sender = userRtpSenders
      45           0 :       .firstWhereOrNull((element) => element.track!.kind == kind.name);
      46           0 :   await sender?.track?.stop();
      47             :   if (track != null) {
      48           0 :     await sender?.replaceTrack(track);
      49             :   } else {
      50           0 :     final stream = await delegate.mediaDevices.getUserMedia({kind.name: true});
      51             :     MediaStreamTrack? track;
      52           0 :     if (kind == MediaKind.audio) {
      53           0 :       track = stream.getAudioTracks().firstOrNull;
      54           0 :     } else if (kind == MediaKind.video) {
      55           0 :       track = stream.getVideoTracks().firstOrNull;
      56             :     }
      57             :     if (track != null) {
      58           0 :       await sender?.replaceTrack(track);
      59             :     }
      60             :   }
      61             : }
      62             : 
      63           2 : String genCallID() {
      64           8 :   return '${DateTime.now().millisecondsSinceEpoch}${randomAlphaNumeric(16)}';
      65             : }

Generated by: LCOV version 1.14