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
+3
View File
@@ -64,6 +64,7 @@ class Engine extends Disposable with EventsEmittable<EngineEvent> {
ConnectOptions connectOptions;
RoomOptions roomOptions;
FastConnectOptions? fastConnectOptions;
bool _subscriberPrimary = false;
@@ -100,12 +101,14 @@ class Engine extends Disposable with EventsEmittable<EngineEvent> {
String token, {
ConnectOptions? connectOptions,
RoomOptions? roomOptions,
FastConnectOptions? fastConnectOptions,
}) async {
this.url = url;
this.token = token;
// update new options (if exists)
this.connectOptions = connectOptions ?? this.connectOptions;
this.roomOptions = roomOptions ?? this.roomOptions;
this.fastConnectOptions = fastConnectOptions;
_updateConnectionState(ConnectionState.connecting);
+30
View File
@@ -14,6 +14,8 @@ import '../participant/remote.dart';
import '../proto/livekit_models.pb.dart' as lk_models;
import '../proto/livekit_rtc.pb.dart' as lk_rtc;
import '../support/disposable.dart';
import '../track/local/audio.dart';
import '../track/local/video.dart';
import '../track/track.dart';
import '../types/other.dart';
import 'engine.dart';
@@ -117,12 +119,14 @@ class Room extends DisposableChangeNotifier with EventsEmittable<RoomEvent> {
String token, {
ConnectOptions? connectOptions,
RoomOptions? roomOptions,
FastConnectOptions? fastConnectOptions,
}) =>
engine.connect(
url,
token,
connectOptions: connectOptions,
roomOptions: roomOptions,
fastConnectOptions: fastConnectOptions,
);
void _setUpSignalListeners() => _signalListener
@@ -141,6 +145,32 @@ class Room extends DisposableChangeNotifier with EventsEmittable<RoomEvent> {
info: event.response.participant,
);
if (connectOptions.protocolVersion.index >= ProtocolVersion.v8.index &&
engine.fastConnectOptions != null) {
var options = engine.fastConnectOptions!;
var audio = options.microphone;
if (audio.enabled != null && audio.enabled == true) {
_localParticipant!.setMicrophoneEnabled(true);
} else if (audio.track != null) {
_localParticipant!.publishAudioTrack(audio.track as LocalAudioTrack);
}
var video = options.camera;
if (video.enabled != null && video.enabled == true) {
_localParticipant!.setCameraEnabled(true);
} else if (video.track != null) {
_localParticipant!.publishVideoTrack(video.track as LocalVideoTrack);
}
var screen = options.screen;
if (screen.enabled != null && screen.enabled == true) {
_localParticipant!.setScreenShareEnabled(true);
} else if (screen.track != null) {
_localParticipant!.publishVideoTrack(screen.track as LocalVideoTrack);
}
}
for (final info in event.response.otherParticipants) {
logger.fine('Creating RemoteParticipant: ${info.sid}(${info.identity}) '
'tracks:${info.tracks.map((e) => e.sid)}');
+1
View File
@@ -45,6 +45,7 @@ extension ProtocolVersionExt on ProtocolVersion {
ProtocolVersion.v5: '5',
ProtocolVersion.v6: '6',
ProtocolVersion.v7: '7',
ProtocolVersion.v8: '8',
}[this]!;
}
+12 -1
View File
@@ -1,5 +1,6 @@
import 'core/room.dart';
import 'options.dart';
import 'types/other.dart';
/// Main entry point to connect to a room.
/// {@category Room}
@@ -9,6 +10,8 @@ class LiveKitClient {
/// Convenience method for connecting to a LiveKit server.
/// Returns a [Room] upon a successful connect or throws when it fails.
/// Alternatively, it is possible to instantiate [Room] and call [Room.connect] directly.
@Deprecated(
'Use `Room.connect` instead, This method is deprecated above Protocol v8.')
static Future<Room> connect(
String url,
String token, {
@@ -16,11 +19,19 @@ class LiveKitClient {
RoomOptions? roomOptions,
}) async {
final room = Room();
ConnectOptions copyOptions = ConnectOptions(
autoSubscribe:
connectOptions != null ? connectOptions.autoSubscribe : true,
rtcConfiguration: connectOptions != null
? connectOptions.rtcConfiguration
: const RTCConfiguration(),
protocolVersion: ProtocolVersion.v7,
);
try {
await room.connect(
url,
token,
connectOptions: connectOptions,
connectOptions: copyOptions,
roomOptions: roomOptions,
);
return room;
+18 -1
View File
@@ -8,6 +8,23 @@ import 'types/other.dart';
import 'types/video_encoding.dart';
import 'types/video_parameters.dart';
class TrackOption<E extends Object, T extends Object> {
final E? enabled;
final T? track;
const TrackOption({this.enabled, this.track});
}
class FastConnectOptions {
FastConnectOptions({
this.microphone = const TrackOption(enabled: false),
this.camera = const TrackOption(enabled: false),
this.screen = const TrackOption(enabled: false),
});
final TrackOption<bool, LocalAudioTrack> microphone;
final TrackOption<bool, LocalVideoTrack> camera;
final TrackOption<bool, LocalVideoTrack> screen;
}
/// Options used when connecting to the server.
class ConnectOptions {
/// Auto-subscribe to existing and new [RemoteTrackPublication]s after
@@ -24,7 +41,7 @@ class ConnectOptions {
const ConnectOptions({
this.autoSubscribe = true,
this.rtcConfiguration = const RTCConfiguration(),
this.protocolVersion = ProtocolVersion.v7,
this.protocolVersion = ProtocolVersion.v8,
});
}
+1
View File
@@ -14,6 +14,7 @@ enum ProtocolVersion {
v5,
v6, // Session migration
v7, // Remote unpublish
v8,
}
/// Connection state type used throughout the SDK.