@@ -25,8 +25,29 @@ void loopBackTest() async {
2525 var localVideo = RTCVideoElement ();
2626 local! .append (localVideo.htmlElement);
2727
28- //var pc = await createPeerConnection({});
29- //pc.onAddStream = (MediaStream stream) {};
28+ var remote = html.document.querySelector ('#remote' );
29+ var remotelVideo = RTCVideoElement ();
30+ remote! .append (remotelVideo.htmlElement);
31+
32+ var pc2 = await createPeerConnection ({});
33+ pc2.onTrack = (event) {
34+ if (event.track.kind == 'video' ) {
35+ remotelVideo.srcObject = event.streams[0 ];
36+ }
37+ };
38+ pc2.onConnectionState = (state) {
39+ print ('connectionState $state ' );
40+ };
41+
42+ pc2.onIceConnectionState = (state) {
43+ print ('iceConnectionState $state ' );
44+ };
45+
46+ var pc1 = await createPeerConnection ({});
47+
48+ pc1.onIceCandidate = (candidate) => pc2.addCandidate (candidate);
49+ pc2.onIceCandidate = (candidate) => pc1.addCandidate (candidate);
50+
3051 var stream =
3152 await navigator.mediaDevices.getUserMedia ({'audio' : true , 'video' : true });
3253 /*.getUserMedia(MediaStreamConstraints(audio: true, video: true))*/
@@ -56,12 +77,26 @@ void loopBackTest() async {
5677 }
5778 }
5879
59- /*
60- stream.oninactive = (Event event) {
61- print('oninactive: stream.id => ${event.target.id}');
62- localVideo.srcObject = null;
63- };
64- */
65- //await pc.addStream(stream);
80+ stream.getTracks ().forEach ((track) async {
81+ await pc1.addTrack (track, stream);
82+ });
83+
84+ var offer = await pc1.createOffer ();
85+
86+ await pc2.addTransceiver (
87+ kind: RTCRtpMediaType .RTCRtpMediaTypeAudio ,
88+ init: RTCRtpTransceiverInit (direction: TransceiverDirection .RecvOnly ));
89+ await pc2.addTransceiver (
90+ kind: RTCRtpMediaType .RTCRtpMediaTypeVideo ,
91+ init: RTCRtpTransceiverInit (direction: TransceiverDirection .RecvOnly ));
92+
93+ await pc1.setLocalDescription (offer);
94+ await pc2.setRemoteDescription (offer);
95+ var answer = await pc2.createAnswer ({});
96+ await pc2.setLocalDescription (answer);
97+
98+ await pc1.setRemoteDescription (answer);
99+
100+ localVideo.muted = true ;
66101 localVideo.srcObject = stream;
67102}
0 commit comments