minor internal refactor
This commit is contained in:
@@ -35,13 +35,13 @@ class Engine extends Disposable with EventsEmittable<EngineEvent> {
|
||||
final PeerConnectionCreate _peerConnectionCreate;
|
||||
|
||||
@internal
|
||||
PCTransport? publisher;
|
||||
Transport? publisher;
|
||||
|
||||
@internal
|
||||
PCTransport? subscriber;
|
||||
Transport? subscriber;
|
||||
|
||||
@internal
|
||||
PCTransport? get primary => _subscriberPrimary ? subscriber : publisher;
|
||||
Transport? get primary => _subscriberPrimary ? subscriber : publisher;
|
||||
|
||||
// data channels for packets
|
||||
rtc.RTCDataChannel? _reliableDCPub;
|
||||
@@ -330,10 +330,9 @@ class Engine extends Disposable with EventsEmittable<EngineEvent> {
|
||||
.copyWith(iceServers: serverIceServers);
|
||||
}
|
||||
|
||||
publisher =
|
||||
await PCTransport.create(_peerConnectionCreate, rtcConfiguration);
|
||||
publisher = await Transport.create(_peerConnectionCreate, rtcConfiguration);
|
||||
subscriber =
|
||||
await PCTransport.create(_peerConnectionCreate, rtcConfiguration);
|
||||
await Transport.create(_peerConnectionCreate, rtcConfiguration);
|
||||
|
||||
publisher?.pc.onIceCandidate = (rtc.RTCIceCandidate candidate) {
|
||||
logger.fine('publisher onIceCandidate');
|
||||
|
||||
@@ -69,7 +69,7 @@ class SignalClient extends Disposable with EventsEmittable<SignalEvent> {
|
||||
WebSocketEventHandlers(
|
||||
onData: _onSocketData,
|
||||
onDispose: _onSocketDispose,
|
||||
onError: _handleError,
|
||||
onError: _onSocketError,
|
||||
),
|
||||
);
|
||||
// Successful connection
|
||||
@@ -218,7 +218,7 @@ class SignalClient extends Disposable with EventsEmittable<SignalEvent> {
|
||||
}
|
||||
}
|
||||
|
||||
void _handleError(dynamic error) {
|
||||
void _onSocketError(dynamic error) {
|
||||
logger.warning('received websocket error $error');
|
||||
}
|
||||
|
||||
|
||||
@@ -10,22 +10,22 @@ import '../support/disposable.dart';
|
||||
import '../types/other.dart';
|
||||
import '../utils.dart';
|
||||
|
||||
typedef PCTransportOnOffer = void Function(rtc.RTCSessionDescription offer);
|
||||
typedef TransportOnOffer = void Function(rtc.RTCSessionDescription offer);
|
||||
typedef PeerConnectionCreate = Future<rtc.RTCPeerConnection> Function(
|
||||
Map<String, dynamic> configuration,
|
||||
[Map<String, dynamic> constraints]);
|
||||
|
||||
/// a wrapper around PeerConnection
|
||||
class PCTransport extends Disposable {
|
||||
class Transport extends Disposable {
|
||||
final rtc.RTCPeerConnection pc;
|
||||
final List<rtc.RTCIceCandidate> _pendingCandidates = [];
|
||||
bool restartingIce = false;
|
||||
bool renegotiate = false;
|
||||
PCTransportOnOffer? onOffer;
|
||||
TransportOnOffer? onOffer;
|
||||
Function? _cancelDebounce;
|
||||
|
||||
// private constructor
|
||||
PCTransport._(this.pc) {
|
||||
Transport._(this.pc) {
|
||||
//
|
||||
onDispose(() async {
|
||||
_cancelDebounce?.call();
|
||||
@@ -58,12 +58,12 @@ class PCTransport extends Disposable {
|
||||
});
|
||||
}
|
||||
|
||||
static Future<PCTransport> create(PeerConnectionCreate peerConnectionCreate,
|
||||
static Future<Transport> create(PeerConnectionCreate peerConnectionCreate,
|
||||
[RTCConfiguration? rtcConfig]) async {
|
||||
rtcConfig ??= const RTCConfiguration();
|
||||
logger.fine('[PCTransport] creating ${rtcConfig.toMap()}');
|
||||
final _ = await peerConnectionCreate(rtcConfig.toMap());
|
||||
return PCTransport._(_);
|
||||
return Transport._(_);
|
||||
}
|
||||
|
||||
late final negotiate = Utils.createDebounceFunc(
|
||||
|
||||
Reference in New Issue
Block a user