@@ -25,6 +25,13 @@ void loopBackTest() async {
2525 var localVideo = RTCVideoElement ();
2626 local! .append (localVideo.htmlElement);
2727
28+ //var pc = await createPeerConnection({});
29+ //pc.onAddStream = (MediaStream stream) {};
30+ var stream =
31+ await navigator.mediaDevices.getUserMedia ({'audio' : true , 'video' : true });
32+ /*.getUserMedia(MediaStreamConstraints(audio: true, video: true))*/
33+ print ('getDisplayMedia: stream.id => ${stream .id }' );
34+
2835 navigator.mediaDevices.ondevicechange = (event) async {
2936 var list = await navigator.mediaDevices.enumerateDevices ();
3037 print ('ondevicechange: ' );
@@ -37,28 +44,24 @@ void loopBackTest() async {
3744 list.forEach ((e) {
3845 print ('${e .runtimeType }: ${e .label }, type => ${e .kind }' );
3946 });
40- var sinkId =
41- list.where ((element) => element.kind == 'audiooutput' ).last.deviceId;
42- try {
43- await navigator.mediaDevices
44- .selectAudioOutput (AudioOutputOptions (deviceId: sinkId));
45- } catch (e) {
46- print ('selectAudioOutput error: ${e .toString ()}' );
47- await localVideo.setSinkId (sinkId);
47+ var outputList = list.where ((element) => element.kind == 'audiooutput' );
48+ if (outputList.isNotEmpty) {
49+ var sinkId = outputList.last.deviceId;
50+ try {
51+ await navigator.mediaDevices
52+ .selectAudioOutput (AudioOutputOptions (deviceId: sinkId));
53+ } catch (e) {
54+ print ('selectAudioOutput error: ${e .toString ()}' );
55+ await localVideo.setSinkId (sinkId);
56+ }
4857 }
4958
50- var pc = await createPeerConnection ({});
51- pc.onAddStream = (MediaStream stream) {};
52- var stream =
53- await navigator.mediaDevices.getUserMedia ({'audio' : true , 'video' : true });
54- /*.getUserMedia(MediaStreamConstraints(audio: true, video: true))*/
55- print ('getDisplayMedia: stream.id => ${stream .id }' );
5659 /*
5760 stream.oninactive = (Event event) {
5861 print('oninactive: stream.id => ${event.target.id}');
5962 localVideo.srcObject = null;
6063 };
6164 */
62- await pc.addStream (stream);
65+ // await pc.addStream(stream);
6366 localVideo.srcObject = stream;
6467}
0 commit comments