@@ -4,7 +4,9 @@ import 'dart:js_interop';
4
4
import 'package:dart_webrtc/dart_webrtc.dart' ;
5
5
import 'package:platform_detect/platform_detect.dart' ;
6
6
import 'package:web/web.dart' as web;
7
+ import 'package:webrtc_interface/webrtc_interface.dart' ;
7
8
9
+ import 'media_stream_impl.dart' ;
8
10
import 'media_stream_track_impl.dart' ;
9
11
import 'rtc_data_channel_impl.dart' ;
10
12
import 'rtc_dtmf_sender_impl.dart' ;
@@ -21,90 +23,90 @@ extension on web.RTCDataChannelInit {
21
23
*/
22
24
class RTCPeerConnectionWeb extends RTCPeerConnection {
23
25
RTCPeerConnectionWeb (this ._peerConnectionId, this ._jsPc) {
24
- final void Function (web.RTCDataChannelEvent ) toDataChannel =
26
+ _jsPc.addEventListener (
27
+ 'datachannel' ,
25
28
(web.RTCDataChannelEvent dataChannelEvent) {
26
- if (dataChannelEvent.channel != null ) {
27
- onDataChannel? .call (RTCDataChannelWeb (dataChannelEvent.channel! ));
28
- }
29
- };
29
+ onDataChannel? .call (RTCDataChannelWeb (dataChannelEvent.channel));
30
+ }.toJS);
30
31
31
- final void Function (web.RTCPeerConnectionIceEvent ) onIceCandidateCb =
32
+ _jsPc.addEventListener (
33
+ 'icecandidate' ,
32
34
(web.RTCPeerConnectionIceEvent iceEvent) {
33
- if (iceEvent.candidate != null ) {
34
- onIceCandidate? .call (_iceFromJs (iceEvent.candidate! ));
35
- }
36
- };
37
-
38
- _jsPc.addEventListener ('datachannel' , toDataChannel.toJS);
39
-
40
- _jsPc.addEventListener ('icecandidate' , onIceCandidateCb.toJS);
41
-
42
- void Function (JSAny ) onIceConnectionStateChange = (_) {
43
- _iceConnectionState =
44
- iceConnectionStateForString (_jsPc.iceConnectionState);
45
- onIceConnectionState? .call (_iceConnectionState! );
46
-
47
- if (browser.isFirefox) {
48
- switch (_iceConnectionState! ) {
49
- case RTCIceConnectionState .RTCIceConnectionStateNew :
50
- _connectionState = RTCPeerConnectionState .RTCPeerConnectionStateNew ;
51
- break ;
52
- case RTCIceConnectionState .RTCIceConnectionStateChecking :
53
- _connectionState =
54
- RTCPeerConnectionState .RTCPeerConnectionStateConnecting ;
55
- break ;
56
- case RTCIceConnectionState .RTCIceConnectionStateConnected :
57
- _connectionState =
58
- RTCPeerConnectionState .RTCPeerConnectionStateConnected ;
59
- break ;
60
- case RTCIceConnectionState .RTCIceConnectionStateFailed :
61
- _connectionState =
62
- RTCPeerConnectionState .RTCPeerConnectionStateFailed ;
63
- break ;
64
- case RTCIceConnectionState .RTCIceConnectionStateDisconnected :
65
- _connectionState =
66
- RTCPeerConnectionState .RTCPeerConnectionStateDisconnected ;
67
- break ;
68
- case RTCIceConnectionState .RTCIceConnectionStateClosed :
69
- _connectionState =
70
- RTCPeerConnectionState .RTCPeerConnectionStateClosed ;
71
- break ;
72
- default :
73
- break ;
74
- }
75
- onConnectionState? .call (_connectionState! );
76
- }
77
- };
35
+ if (iceEvent.candidate != null ) {
36
+ onIceCandidate? .call (_iceFromJs (iceEvent.candidate! ));
37
+ }
38
+ }.toJS);
78
39
79
40
_jsPc.addEventListener (
80
- 'iceconnectionstatechange' , onIceConnectionStateChange.toJS);
81
-
82
- void Function (JSAny ) onIceGatheringStateChange = (_) {
41
+ 'iceconnectionstatechange' ,
42
+ (web.Event _) {
43
+ _iceConnectionState =
44
+ iceConnectionStateForString (_jsPc.iceConnectionState);
45
+ onIceConnectionState? .call (_iceConnectionState! );
46
+
47
+ if (browser.isFirefox) {
48
+ switch (_iceConnectionState! ) {
49
+ case RTCIceConnectionState .RTCIceConnectionStateNew :
50
+ _connectionState =
51
+ RTCPeerConnectionState .RTCPeerConnectionStateNew ;
52
+ break ;
53
+ case RTCIceConnectionState .RTCIceConnectionStateChecking :
54
+ _connectionState =
55
+ RTCPeerConnectionState .RTCPeerConnectionStateConnecting ;
56
+ break ;
57
+ case RTCIceConnectionState .RTCIceConnectionStateConnected :
58
+ _connectionState =
59
+ RTCPeerConnectionState .RTCPeerConnectionStateConnected ;
60
+ break ;
61
+ case RTCIceConnectionState .RTCIceConnectionStateFailed :
62
+ _connectionState =
63
+ RTCPeerConnectionState .RTCPeerConnectionStateFailed ;
64
+ break ;
65
+ case RTCIceConnectionState .RTCIceConnectionStateDisconnected :
66
+ _connectionState =
67
+ RTCPeerConnectionState .RTCPeerConnectionStateDisconnected ;
68
+ break ;
69
+ case RTCIceConnectionState .RTCIceConnectionStateClosed :
70
+ _connectionState =
71
+ RTCPeerConnectionState .RTCPeerConnectionStateClosed ;
72
+ break ;
73
+ default :
74
+ break ;
75
+ }
76
+ onConnectionState? .call (_connectionState! );
77
+ }
78
+ }.toJS);
79
+
80
+ jsutil.setProperty (_jsPc, 'onicegatheringstatechange' , js.allowInterop ((_) {
83
81
_iceGatheringState = iceGatheringStateforString (_jsPc.iceGatheringState);
84
82
onIceGatheringState? .call (_iceGatheringState! );
85
83
};
86
-
87
- _jsPc.onicegatheringstatechange = onIceGatheringStateChange.toJS;
88
-
89
- void Function (JSAny ) onSignalingStateChange = (_) {
90
- _signalingState = signalingStateForString (_jsPc.signalingState);
91
- onSignalingState? .call (_signalingState! );
92
- };
93
-
94
- _jsPc.addEventListener ('signalingstatechange' , onSignalingStateChange.toJS);
84
+ _jsPc.addEventListener (
85
+ 'signalingstatechange' ,
86
+ (web.Event _) {
87
+ _signalingState = signalingStateForString (_jsPc.signalingState);
88
+ onSignalingState? .call (_signalingState! );
89
+ }.toJS);
95
90
96
91
if (! browser.isFirefox) {
97
92
final void Function (JSAny ) onConnectionStateChange = (_) {
98
93
_connectionState = peerConnectionStateForString (_jsPc.connectionState);
99
94
onConnectionState? .call (_connectionState! );
100
95
};
101
96
_jsPc.addEventListener (
102
- 'connectionstatechange' , onConnectionStateChange.toJS);
97
+ 'connectionstatechange' ,
98
+ (web.Event _) {
99
+ _connectionState =
100
+ peerConnectionStateForString (_jsPc.connectionState);
101
+ onConnectionState? .call (_connectionState! );
102
+ }.toJS);
103
103
}
104
104
105
- void Function (JSAny ) onNegotationNeeded = (_) {
106
- onRenegotiationNeeded? .call ();
107
- };
105
+ _jsPc.addEventListener (
106
+ 'negotiationneeded' ,
107
+ (web.Event _) {
108
+ onRenegotiationNeeded? .call ();
109
+ }.toJS);
108
110
109
111
_jsPc.addEventListener ('negotiationneeded' , onNegotationNeeded.toJS);
110
112
0 commit comments