11import 'dart:async' ;
2+ import 'dart:collection' ;
23import 'dart:js_interop' ;
4+ import 'dart:js_interop_unsafe' ;
35
46import 'package:dart_webrtc/dart_webrtc.dart' ;
5- import 'package:platform_detect/platform_detect.dart' ;
67import 'package:web/web.dart' as web;
78
89import 'media_stream_track_impl.dart' ;
@@ -42,7 +43,7 @@ class RTCPeerConnectionWeb extends RTCPeerConnection {
4243 iceConnectionStateForString (_jsPc.iceConnectionState);
4344 onIceConnectionState? .call (_iceConnectionState! );
4445
45- if (browser .isFirefox) {
46+ if (web. Device .isFirefox) {
4647 switch (_iceConnectionState! ) {
4748 case RTCIceConnectionState .RTCIceConnectionStateNew :
4849 _connectionState = RTCPeerConnectionState .RTCPeerConnectionStateNew ;
@@ -91,7 +92,7 @@ class RTCPeerConnectionWeb extends RTCPeerConnection {
9192
9293 _jsPc.addEventListener ('signalingstatechange' , onSignalingStateChange.toJS);
9394
94- if (! browser .isFirefox) {
95+ if (! web. Device .isFirefox) {
9596 final void Function (JSAny ) onConnectionStateChange = (_) {
9697 _connectionState = peerConnectionStateForString (_jsPc.connectionState);
9798 onConnectionState? .call (_connectionState! );
@@ -157,7 +158,7 @@ class RTCPeerConnectionWeb extends RTCPeerConnection {
157158 @override
158159 Future <RTCIceConnectionState ?> getIceConnectionState () async {
159160 _iceConnectionState = iceConnectionStateForString (_jsPc.iceConnectionState);
160- if (browser .isFirefox) {
161+ if (web. Device .isFirefox) {
161162 switch (_iceConnectionState! ) {
162163 case RTCIceConnectionState .RTCIceConnectionStateNew :
163164 _connectionState = RTCPeerConnectionState .RTCPeerConnectionStateNew ;
@@ -194,7 +195,8 @@ class RTCPeerConnectionWeb extends RTCPeerConnection {
194195
195196 @override
196197 Future <RTCPeerConnectionState ?> getConnectionState () async {
197- if (browser.isFirefox) {
198+ /// platform is Firefox
199+ if (web.Device .isFirefox) {
198200 await getIceConnectionState ();
199201 } else {
200202 _connectionState = peerConnectionStateForString (_jsPc.connectionState);
@@ -312,7 +314,7 @@ class RTCPeerConnectionWeb extends RTCPeerConnection {
312314
313315 @override
314316 Future <List <StatsReport >> getStats ([MediaStreamTrack ? track]) async {
315- var stats;
317+ web. RTCStatsReport stats;
316318 if (track != null ) {
317319 var jsTrack = (track as MediaStreamTrackWeb ).jsTrack;
318320 stats = await _jsPc.getStats (jsTrack).toDart;
@@ -321,10 +323,20 @@ class RTCPeerConnectionWeb extends RTCPeerConnection {
321323 }
322324
323325 var report = < StatsReport > [];
324- stats.forEach ((key, value) {
325- report.add (
326- StatsReport (value['id' ], value['type' ], value['timestamp' ], value));
327- });
326+ stats.callMethodVarArgs ('forEach' .toJS, [
327+ (JSObject value, JSAny key) {
328+ var map = value.dartify () as LinkedHashMap <Object ?, Object ?>;
329+ var stats = < String , dynamic > {};
330+ for (var entry in map.entries) {
331+ stats[(entry.key as JSString ).toDart] = entry.value;
332+ }
333+ report.add (StatsReport (
334+ value.getProperty <JSString >('id' .toJS).toDart,
335+ value.getProperty <JSString >('type' .toJS).toDart,
336+ value.getProperty <JSNumber >('timestamp' .toJS).toDartDouble,
337+ stats));
338+ }.toJS,
339+ ]);
328340 return report;
329341 }
330342
0 commit comments