11// ignore_for_file: avoid_web_libraries_in_flutter, implementation_imports
22
3- import 'dart:html' as html;
43import 'dart:js_util' as jsutil;
54
65import 'package:dart_webrtc/src/media_stream_track_impl.dart' ;
76import 'package:flutter_webrtc/flutter_webrtc.dart' as rtc;
7+ import 'package:web/web.dart' as web;
88
99const audioContainerId = 'stream_audio_container' ;
1010const audioPrefix = 'stream_audio_' ;
@@ -13,46 +13,46 @@ void startAudio(String id, rtc.MediaStreamTrack track) {
1313 if (track is ! MediaStreamTrackWeb ) return ;
1414
1515 final elementId = audioPrefix + id;
16- var audioElement = html .document.getElementById (elementId);
16+ var audioElement = web .document.getElementById (elementId);
1717 if (audioElement == null ) {
18- audioElement = html. AudioElement ()
18+ audioElement = web. HTMLAudioElement ()
1919 ..id = elementId
2020 ..autoplay = true ;
2121 findOrCreateAudioContainer ().append (audioElement);
2222 }
2323
24- if (audioElement is ! html. AudioElement ) return ;
24+ if (audioElement is ! web. HTMLAudioElement ) return ;
2525
26- final audioStream = html .MediaStream ();
26+ final audioStream = web .MediaStream ();
2727 audioStream.addTrack (track.jsTrack);
2828 audioElement.srcObject = audioStream;
2929}
3030
3131void stopAudio (String id) {
32- final audioElement = html .document.getElementById (audioPrefix + id);
32+ final audioElement = web .document.getElementById (audioPrefix + id);
3333 if (audioElement != null ) {
34- if (audioElement is html. AudioElement ) {
34+ if (audioElement is web. HTMLAudioElement ) {
3535 audioElement.srcObject = null ;
3636 }
3737 audioElement.remove ();
3838 }
3939}
4040
4141void setSinkId (String id, String deviceId) {
42- final audioElement = html .document.getElementById (audioPrefix + id);
43- if (audioElement is html. AudioElement &&
42+ final audioElement = web .document.getElementById (audioPrefix + id);
43+ if (audioElement is web. HTMLAudioElement &&
4444 jsutil.hasProperty (audioElement, 'setSinkId' )) {
45- audioElement. setSinkId ( deviceId);
45+ jsutil. setProperty (audioElement, 'setSinkId' , deviceId);
4646 }
4747}
4848
49- html. DivElement findOrCreateAudioContainer () {
50- var div = html .document.getElementById (audioContainerId);
51- if (div != null ) return div as html. DivElement ;
49+ web. HTMLDivElement findOrCreateAudioContainer () {
50+ var div = web .document.getElementById (audioContainerId);
51+ if (div != null ) return div as web. HTMLDivElement ;
5252
53- div = html. DivElement ()
53+ div = web. HTMLDivElement ()
5454 ..id = audioContainerId
5555 ..style.display = 'none' ;
56- html .document.body? .append (div);
57- return div as html. DivElement ;
56+ web .document.body? .append (div);
57+ return div as web. HTMLDivElement ;
5858}
0 commit comments