protocol 8. (#134)

* protocol 8.

* add FastConnectOptions.

* update.

* fix.

* Deprecated the top connect method.

* Add fast connect button in example.

* Create a Listener before connecting.

* Force protocol-v7 for deprecated APIs.

* remove commented out line.

* relative path import.

* update.
This commit is contained in:
CloudWebRTC
2022-07-11 19:54:08 +08:00
committed by GitHub
parent 66d4052ada
commit 3d8bf96651
8 changed files with 122 additions and 18 deletions
+47 -11
View File
@@ -24,6 +24,7 @@ class _ConnectPageState extends State<ConnectPage> {
static const _storeKeySimulcast = 'simulcast';
static const _storeKeyAdaptiveStream = 'adaptive-stream';
static const _storeKeyDynacast = 'dynacast';
static const _storeKeyFastConnect = 'fast-connect';
final _uriCtrl = TextEditingController();
final _tokenCtrl = TextEditingController();
@@ -31,6 +32,7 @@ class _ConnectPageState extends State<ConnectPage> {
bool _adaptiveStream = true;
bool _dynacast = true;
bool _busy = false;
bool _fastConnect = false;
@override
void initState() {
@@ -58,6 +60,7 @@ class _ConnectPageState extends State<ConnectPage> {
_simulcast = prefs.getBool(_storeKeySimulcast) ?? true;
_adaptiveStream = prefs.getBool(_storeKeyAdaptiveStream) ?? true;
_dynacast = prefs.getBool(_storeKeyDynacast) ?? true;
_fastConnect = prefs.getBool(_storeKeyFastConnect) ?? false;
});
}
@@ -69,6 +72,7 @@ class _ConnectPageState extends State<ConnectPage> {
await prefs.setBool(_storeKeySimulcast, _simulcast);
await prefs.setBool(_storeKeyAdaptiveStream, _adaptiveStream);
await prefs.setBool(_storeKeyDynacast, _dynacast);
await prefs.setBool(_storeKeyFastConnect, _fastConnect);
}
Future<void> _connect(BuildContext ctx) async {
@@ -84,24 +88,36 @@ class _ConnectPageState extends State<ConnectPage> {
print('Connecting with url: ${_uriCtrl.text}, '
'token: ${_tokenCtrl.text}...');
// Try to connect to a room
//create new room
final room = Room();
// Create a Listener before connecting
final listener = room.createListener();
// Try to connect to the room
// This will throw an Exception if it fails for any reason.
final room = await LiveKitClient.connect(
await room.connect(
_uriCtrl.text,
_tokenCtrl.text,
roomOptions: RoomOptions(
adaptiveStream: _adaptiveStream,
dynacast: _dynacast,
defaultVideoPublishOptions: VideoPublishOptions(
simulcast: _simulcast,
),
defaultScreenShareCaptureOptions: const ScreenShareCaptureOptions(
useiOSBroadcastExtension: true)),
adaptiveStream: _adaptiveStream,
dynacast: _dynacast,
defaultVideoPublishOptions: VideoPublishOptions(
simulcast: _simulcast,
),
defaultScreenShareCaptureOptions:
const ScreenShareCaptureOptions(useiOSBroadcastExtension: true),
),
fastConnectOptions: _fastConnect
? FastConnectOptions(
microphone: const TrackOption(enabled: true),
camera: const TrackOption(enabled: true),
)
: null,
);
await Navigator.push<void>(
ctx,
MaterialPageRoute(builder: (_) => RoomPage(room)),
MaterialPageRoute(builder: (_) => RoomPage(room, listener)),
);
} catch (error) {
print('Could not connect $error');
@@ -134,6 +150,13 @@ class _ConnectPageState extends State<ConnectPage> {
});
}
void _setFastConnect(bool? value) async {
if (value == null || _fastConnect == value) return;
setState(() {
_fastConnect = value;
});
}
@override
Widget build(BuildContext context) => Scaffold(
body: Container(
@@ -195,6 +218,19 @@ class _ConnectPageState extends State<ConnectPage> {
],
),
),
Padding(
padding: const EdgeInsets.only(bottom: 5),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text('Fast Connect'),
Switch(
value: _fastConnect,
onChanged: (value) => _setFastConnect(value),
),
],
),
),
Padding(
padding: const EdgeInsets.only(bottom: 25),
child: Row(
+10 -5
View File
@@ -11,9 +11,11 @@ import '../widgets/participant.dart';
class RoomPage extends StatefulWidget {
//
final Room room;
final EventsListener<RoomEvent> listener;
const RoomPage(
this.room, {
this.room,
this.listener, {
Key? key,
}) : super(key: key);
@@ -24,16 +26,19 @@ class RoomPage extends StatefulWidget {
class _RoomPageState extends State<RoomPage> {
//
List<Participant> participants = [];
late final EventsListener<RoomEvent> _listener = widget.room.createListener();
EventsListener<RoomEvent> get _listener => widget.listener;
bool get fastConnection => widget.room.engine.fastConnectOptions != null;
@override
void initState() {
super.initState();
widget.room.addListener(_onRoomDidUpdate);
_setUpListeners();
_sortParticipants();
WidgetsBindingCompatible.instance
?.addPostFrameCallback((_) => _askPublish());
WidgetsBindingCompatible.instance?.addPostFrameCallback((_) {
if (!fastConnection) {
_askPublish();
}
});
}
@override