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