Files
client-sdk-flutter/lib/src/transport.dart
T
Hiroshi HorieandGitHub ab31ddabb9 Apply Flutter best practices [Non-Breaking] (#2)
* Add flutter_lints package

* Use key in widget constructors

lint: use_key_in_widget_constructors

* Unnecessary new keyword

lint: unnecessary_new

* Prefer const with constant constructors

* Exclude protobuf files from analyzer

* Private field could be final

* Annotate overridden members

* Use initializing formals when possible

* Don't access members with `this` unless avoiding shadowing

* Prefer is! operator

* Use isEmpty instead of length

* Use collection literals when possible

* Revert comment changes

* Cleaner null testing

* Misc fixes

* Avoid using `forEach` with a function literal

* Prefer `final` over `var` where applicable

* Enforce stricter type-checking

* Ignore VS Code files

* Flutter format

* Prefer using lowerCamelCase for constant names

* flutter format -l 100

* Disable `avoid_print` for examples

* Slight improvements to example

Should solve lint error: no_logic_in_create_state
2021-08-31 16:35:07 +09:00

37 lines
960 B
Dart

import 'package:flutter_webrtc/flutter_webrtc.dart';
/// a wrapper around PeerConnection
class PCTransport {
RTCPeerConnection pc;
List<RTCIceCandidate> pendingCandidates = [];
bool restartingIce = false;
PCTransport(this.pc);
Future<void> setRemoteDescription(RTCSessionDescription sd) async {
await pc.setRemoteDescription(sd);
await Future.forEach<RTCIceCandidate>(pendingCandidates, (candidate) async {
await pc.addCandidate(candidate);
});
pendingCandidates.clear();
restartingIce = false;
}
Future<void> addIceCandidate(RTCIceCandidate candidate) async {
final desc = await getRemoteDescription();
if (desc != null && !restartingIce) {
return pc.addCandidate(candidate);
}
pendingCandidates.add(candidate);
}
Future<RTCSessionDescription?> getRemoteDescription() async {
if (pc.iceConnectionState == null) {
return null;
}
return pc.getRemoteDescription();
}
}