fix: add name to AudioPublishOptions. (#302)
* fix: add name to AudioPublishOptions. * remove name for Track. * remove name for Track. * update. * fix flutter analyzer. * update. * add Deprecated declaration for Track.name. * update.
This commit is contained in:
@@ -145,6 +145,8 @@ class _ConnectPageState extends State<ConnectPage> {
|
||||
roomOptions: RoomOptions(
|
||||
adaptiveStream: _adaptiveStream,
|
||||
dynacast: _dynacast,
|
||||
defaultAudioPublishOptions:
|
||||
const AudioPublishOptions(name: 'custom_audio_track_name'),
|
||||
defaultVideoPublishOptions: VideoPublishOptions(
|
||||
simulcast: _simulcast,
|
||||
),
|
||||
|
||||
+17
-5
@@ -139,6 +139,9 @@ class RoomOptions {
|
||||
|
||||
/// Options used when publishing video.
|
||||
class VideoPublishOptions {
|
||||
static const defaultCameraName = 'camera';
|
||||
static const defaultScreenShareName = 'screenshare';
|
||||
|
||||
/// The video codec to use.
|
||||
final String videoCodec;
|
||||
|
||||
@@ -152,6 +155,9 @@ class VideoPublishOptions {
|
||||
/// Defaults to true.
|
||||
final bool simulcast;
|
||||
|
||||
/// Name of the video track.
|
||||
final String? name;
|
||||
|
||||
final List<VideoParameters> videoSimulcastLayers;
|
||||
|
||||
final List<VideoParameters> screenShareSimulcastLayers;
|
||||
@@ -162,6 +168,7 @@ class VideoPublishOptions {
|
||||
this.simulcast = true,
|
||||
this.videoSimulcastLayers = const [],
|
||||
this.screenShareSimulcastLayers = const [],
|
||||
this.name,
|
||||
});
|
||||
|
||||
VideoPublishOptions copyWith({
|
||||
@@ -194,6 +201,8 @@ class AudioPreset {
|
||||
|
||||
/// Options used when publishing audio.
|
||||
class AudioPublishOptions {
|
||||
static const defaultMicrophoneName = 'microphone';
|
||||
|
||||
/// Whether to enable DTX (Discontinuous Transmission) or not.
|
||||
/// https://en.wikipedia.org/wiki/Discontinuous_transmission
|
||||
/// Defaults to true.
|
||||
@@ -207,11 +216,14 @@ class AudioPublishOptions {
|
||||
@Deprecated('Mic indicator will always turn off now when muted.')
|
||||
final bool stopMicTrackOnMute;
|
||||
|
||||
const AudioPublishOptions({
|
||||
this.dtx = true,
|
||||
this.audioBitrate = AudioPreset.music,
|
||||
this.stopMicTrackOnMute = true,
|
||||
});
|
||||
/// Name of the audio track.
|
||||
final String? name;
|
||||
|
||||
const AudioPublishOptions(
|
||||
{this.dtx = true,
|
||||
this.audioBitrate = AudioPreset.music,
|
||||
this.stopMicTrackOnMute = true,
|
||||
this.name});
|
||||
|
||||
@override
|
||||
String toString() => '${runtimeType}(dtx: ${dtx})';
|
||||
|
||||
@@ -57,7 +57,7 @@ class LocalParticipant extends Participant<LocalTrackPublication> {
|
||||
|
||||
final trackInfo = await room.engine.addTrack(
|
||||
cid: track.getCid(),
|
||||
name: track.name,
|
||||
name: publishOptions.name ?? AudioPublishOptions.defaultMicrophoneName,
|
||||
kind: track.kind,
|
||||
source: track.source.toPBType(),
|
||||
dtx: publishOptions.dtx,
|
||||
@@ -159,7 +159,10 @@ class LocalParticipant extends Participant<LocalTrackPublication> {
|
||||
|
||||
final trackInfo = await room.engine.addTrack(
|
||||
cid: track.getCid(),
|
||||
name: track.name,
|
||||
name: publishOptions.name ??
|
||||
(track.source == TrackSource.screenShareVideo
|
||||
? VideoPublishOptions.defaultScreenShareName
|
||||
: VideoPublishOptions.defaultCameraName),
|
||||
kind: track.kind,
|
||||
source: track.source.toPBType(),
|
||||
dimensions: dimensions,
|
||||
|
||||
@@ -10,7 +10,6 @@ import '../managers/event.dart';
|
||||
import '../proto/livekit_models.pb.dart' as lk_models;
|
||||
import '../publication/track_publication.dart';
|
||||
import '../support/disposable.dart';
|
||||
import '../track/track.dart';
|
||||
import '../types/other.dart';
|
||||
import '../types/participant_permissions.dart';
|
||||
|
||||
@@ -248,14 +247,11 @@ abstract class Participant<T extends TrackPublication>
|
||||
(source == TrackSource.microphone &&
|
||||
e.kind == lk_models.TrackType.AUDIO) ||
|
||||
(source == TrackSource.camera &&
|
||||
e.kind == lk_models.TrackType.VIDEO &&
|
||||
e.name != Track.screenShareName) ||
|
||||
e.kind == lk_models.TrackType.VIDEO) ||
|
||||
(source == TrackSource.screenShareVideo &&
|
||||
e.kind == lk_models.TrackType.VIDEO &&
|
||||
e.name == Track.screenShareName) ||
|
||||
e.kind == lk_models.TrackType.VIDEO) ||
|
||||
(source == TrackSource.screenShareAudio &&
|
||||
e.kind == lk_models.TrackType.AUDIO &&
|
||||
e.name == Track.screenShareName));
|
||||
e.kind == lk_models.TrackType.AUDIO));
|
||||
}
|
||||
|
||||
/// (Equality operator) [Participant.hashCode] is same as [sid.hashCode].
|
||||
|
||||
@@ -116,12 +116,12 @@ class RemoteParticipant extends Participant<RemoteTrackPublication> {
|
||||
final RemoteTrack track;
|
||||
if (pub.kind == lk_models.TrackType.VIDEO) {
|
||||
// video track
|
||||
track = RemoteVideoTrack(pub.name, pub.source, stream, mediaTrack,
|
||||
receiver: receiver);
|
||||
track =
|
||||
RemoteVideoTrack(pub.source, stream, mediaTrack, receiver: receiver);
|
||||
} else if (pub.kind == lk_models.TrackType.AUDIO) {
|
||||
// audio track
|
||||
track = RemoteAudioTrack(pub.name, pub.source, stream, mediaTrack,
|
||||
receiver: receiver);
|
||||
track =
|
||||
RemoteAudioTrack(pub.source, stream, mediaTrack, receiver: receiver);
|
||||
|
||||
var listener = track.createListener();
|
||||
listener.on<AudioPlaybackStarted>((event) {
|
||||
|
||||
@@ -62,9 +62,10 @@ abstract class TrackPublication<T extends Track> extends Disposable {
|
||||
updateFromInfo(info);
|
||||
}
|
||||
|
||||
/// True when the track is published with name [Track.screenShareName].
|
||||
/// True when the track is published with source [TrackSource.screenShareVideo].
|
||||
bool get isScreenShare =>
|
||||
kind == lk_models.TrackType.VIDEO && name == Track.screenShareName;
|
||||
kind == lk_models.TrackType.VIDEO &&
|
||||
source == TrackSource.screenShareVideo;
|
||||
|
||||
void updateFromInfo(lk_models.TrackInfo info) {
|
||||
_simulcasted = info.simulcast;
|
||||
|
||||
@@ -83,13 +83,11 @@ class LocalAudioTrack extends LocalTrack
|
||||
// private constructor
|
||||
@internal
|
||||
LocalAudioTrack(
|
||||
String name,
|
||||
TrackSource source,
|
||||
rtc.MediaStream stream,
|
||||
rtc.MediaStreamTrack track,
|
||||
this.currentOptions,
|
||||
) : super(
|
||||
name,
|
||||
lk_models.TrackType.AUDIO,
|
||||
source,
|
||||
stream,
|
||||
@@ -104,7 +102,6 @@ class LocalAudioTrack extends LocalTrack
|
||||
final stream = await LocalTrack.createStream(options);
|
||||
|
||||
return LocalAudioTrack(
|
||||
'',
|
||||
TrackSource.microphone,
|
||||
stream,
|
||||
stream.getAudioTracks().first,
|
||||
|
||||
@@ -57,13 +57,11 @@ abstract class LocalTrack extends Track {
|
||||
String? codec;
|
||||
|
||||
LocalTrack(
|
||||
String name,
|
||||
lk_models.TrackType kind,
|
||||
TrackSource source,
|
||||
rtc.MediaStream mediaStream,
|
||||
rtc.MediaStreamTrack mediaStreamTrack,
|
||||
) : super(
|
||||
name,
|
||||
kind,
|
||||
source,
|
||||
mediaStream,
|
||||
|
||||
@@ -7,7 +7,6 @@ import '../../proto/livekit_models.pb.dart' as lk_models;
|
||||
import '../../types/other.dart';
|
||||
import '../options.dart';
|
||||
import '../stats.dart';
|
||||
import '../track.dart';
|
||||
import 'audio.dart';
|
||||
import 'local.dart';
|
||||
|
||||
@@ -113,13 +112,11 @@ class LocalVideoTrack extends LocalTrack with VideoTrack {
|
||||
|
||||
// Private constructor
|
||||
LocalVideoTrack._(
|
||||
String name,
|
||||
TrackSource source,
|
||||
rtc.MediaStream stream,
|
||||
rtc.MediaStreamTrack track,
|
||||
this.currentOptions,
|
||||
) : super(
|
||||
name,
|
||||
lk_models.TrackType.VIDEO,
|
||||
source,
|
||||
stream,
|
||||
@@ -134,7 +131,6 @@ class LocalVideoTrack extends LocalTrack with VideoTrack {
|
||||
|
||||
final stream = await LocalTrack.createStream(options);
|
||||
return LocalVideoTrack._(
|
||||
Track.cameraName,
|
||||
TrackSource.camera,
|
||||
stream,
|
||||
stream.getVideoTracks().first,
|
||||
@@ -153,7 +149,6 @@ class LocalVideoTrack extends LocalTrack with VideoTrack {
|
||||
|
||||
final stream = await LocalTrack.createStream(options);
|
||||
return LocalVideoTrack._(
|
||||
Track.screenShareName,
|
||||
TrackSource.screenShareVideo,
|
||||
stream,
|
||||
stream.getVideoTracks().first,
|
||||
@@ -175,7 +170,6 @@ class LocalVideoTrack extends LocalTrack with VideoTrack {
|
||||
|
||||
List<LocalTrack> tracks = [
|
||||
LocalVideoTrack._(
|
||||
Track.screenShareName,
|
||||
TrackSource.screenShareVideo,
|
||||
stream,
|
||||
stream.getVideoTracks().first,
|
||||
@@ -184,12 +178,8 @@ class LocalVideoTrack extends LocalTrack with VideoTrack {
|
||||
];
|
||||
|
||||
if (stream.getAudioTracks().isNotEmpty) {
|
||||
tracks.add(LocalAudioTrack(
|
||||
Track.screenShareName,
|
||||
TrackSource.screenShareAudio,
|
||||
stream,
|
||||
stream.getAudioTracks().first,
|
||||
const AudioCaptureOptions()));
|
||||
tracks.add(LocalAudioTrack(TrackSource.screenShareAudio, stream,
|
||||
stream.getAudioTracks().first, const AudioCaptureOptions()));
|
||||
}
|
||||
return tracks;
|
||||
}
|
||||
|
||||
@@ -16,11 +16,10 @@ import '../web/_audio_api.dart' if (dart.library.html) '../web/_audio_html.dart'
|
||||
class RemoteAudioTrack extends RemoteTrack
|
||||
with AudioTrack, RemoteAudioManagementMixin {
|
||||
String? _deviceId;
|
||||
RemoteAudioTrack(String name, TrackSource source, rtc.MediaStream stream,
|
||||
rtc.MediaStreamTrack track,
|
||||
RemoteAudioTrack(
|
||||
TrackSource source, rtc.MediaStream stream, rtc.MediaStreamTrack track,
|
||||
{rtc.RTCRtpReceiver? receiver})
|
||||
: super(
|
||||
name,
|
||||
lk_models.TrackType.AUDIO,
|
||||
source,
|
||||
stream,
|
||||
|
||||
@@ -9,11 +9,10 @@ import '../stats.dart';
|
||||
import '../track.dart';
|
||||
|
||||
abstract class RemoteTrack extends Track {
|
||||
RemoteTrack(String name, lk_models.TrackType kind, TrackSource source,
|
||||
RemoteTrack(lk_models.TrackType kind, TrackSource source,
|
||||
rtc.MediaStream stream, rtc.MediaStreamTrack track,
|
||||
{rtc.RTCRtpReceiver? receiver})
|
||||
: super(
|
||||
name,
|
||||
kind,
|
||||
source,
|
||||
stream,
|
||||
|
||||
@@ -10,11 +10,10 @@ import '../stats.dart';
|
||||
import 'remote.dart';
|
||||
|
||||
class RemoteVideoTrack extends RemoteTrack with VideoTrack {
|
||||
RemoteVideoTrack(String name, TrackSource source, rtc.MediaStream stream,
|
||||
rtc.MediaStreamTrack track,
|
||||
RemoteVideoTrack(
|
||||
TrackSource source, rtc.MediaStream stream, rtc.MediaStreamTrack track,
|
||||
{rtc.RTCRtpReceiver? receiver})
|
||||
: super(
|
||||
name,
|
||||
lk_models.TrackType.VIDEO,
|
||||
source,
|
||||
stream,
|
||||
|
||||
@@ -17,10 +17,8 @@ import '../types/other.dart';
|
||||
abstract class Track extends DisposableChangeNotifier
|
||||
with EventsEmittable<TrackEvent> {
|
||||
static const uuid = Uuid();
|
||||
static const cameraName = 'camera';
|
||||
static const screenShareName = 'screenshare';
|
||||
|
||||
final String name;
|
||||
@Deprecated('Use TrackPublication.name instead')
|
||||
final String name = 'Deprecated, please use TrackPublication.name instead';
|
||||
final lk_models.TrackType kind;
|
||||
final TrackSource source;
|
||||
|
||||
@@ -47,8 +45,7 @@ abstract class Track extends DisposableChangeNotifier
|
||||
|
||||
rtc.RTCRtpReceiver? receiver;
|
||||
|
||||
Track(this.name, this.kind, this.source, this._mediaStream,
|
||||
this._mediaStreamTrack,
|
||||
Track(this.kind, this.source, this._mediaStream, this._mediaStreamTrack,
|
||||
{this.receiver}) {
|
||||
// Any event emitted will trigger ChangeNotifier
|
||||
events.listen((event) {
|
||||
|
||||
Reference in New Issue
Block a user