LCOV - code coverage report
Current view: top level - lib/src/voip/utils - stream_helper.dart (source / functions) Coverage Total Hit
Test: merged.info Lines: 20.0 % 25 5
Test Date: 2025-01-14 13:39:53 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,
      32              :   MediaInputKind mediaInputKind,
      33              : ) async {
      34            0 :   final devices = await delegate.mediaDevices.enumerateDevices();
      35              :   return devices
      36            0 :       .where((device) => device.kind == mediaInputKind.name)
      37            0 :       .isNotEmpty;
      38              : }
      39              : 
      40            0 : Future<void> updateMediaDevice(
      41              :   WebRTCDelegate delegate,
      42              :   MediaKind kind,
      43              :   List<RTCRtpSender> userRtpSenders, [
      44              :   MediaStreamTrack? track,
      45              : ]) async {
      46              :   final sender = userRtpSenders
      47            0 :       .firstWhereOrNull((element) => element.track!.kind == kind.name);
      48            0 :   await sender?.track?.stop();
      49              :   if (track != null) {
      50            0 :     await sender?.replaceTrack(track);
      51              :   } else {
      52            0 :     final stream = await delegate.mediaDevices.getUserMedia({kind.name: true});
      53              :     MediaStreamTrack? track;
      54            0 :     if (kind == MediaKind.audio) {
      55            0 :       track = stream.getAudioTracks().firstOrNull;
      56            0 :     } else if (kind == MediaKind.video) {
      57            0 :       track = stream.getVideoTracks().firstOrNull;
      58              :     }
      59              :     if (track != null) {
      60            0 :       await sender?.replaceTrack(track);
      61              :     }
      62              :   }
      63              : }
      64              : 
      65            2 : String genCallID() {
      66            8 :   return '${DateTime.now().millisecondsSinceEpoch}${randomAlphaNumeric(16)}';
      67              : }
        

Generated by: LCOV version 2.0-1