return publication for TrackSource apis
This commit is contained in:
@@ -253,41 +253,48 @@ class LocalParticipant extends Participant {
|
|||||||
}
|
}
|
||||||
|
|
||||||
extension LocalParticipantTrackSourceExt on LocalParticipant {
|
extension LocalParticipantTrackSourceExt on LocalParticipant {
|
||||||
Future<void> setCameraEnabled(bool enabled) async {
|
/// Shortcut for publishing a [TrackSource.camera]
|
||||||
|
Future<LocalTrackPublication?> setCameraEnabled(bool enabled) async {
|
||||||
return setSourceEnabled(TrackSource.camera, enabled);
|
return setSourceEnabled(TrackSource.camera, enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> setMicrophoneEnabled(bool enabled) async {
|
/// Shortcut for publishing a [TrackSource.microphone]
|
||||||
|
Future<LocalTrackPublication?> setMicrophoneEnabled(bool enabled) async {
|
||||||
return setSourceEnabled(TrackSource.microphone, enabled);
|
return setSourceEnabled(TrackSource.microphone, enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> setScreenShareEnabled(bool enabled) async {
|
/// Shortcut for publishing a [TrackSource.screenShareVideo]
|
||||||
|
Future<LocalTrackPublication?> setScreenShareEnabled(bool enabled) async {
|
||||||
return setSourceEnabled(TrackSource.screenShareVideo, enabled);
|
return setSourceEnabled(TrackSource.screenShareVideo, enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> setSourceEnabled(TrackSource source, bool enabled) async {
|
/// A convenience method to publish a track for a specific [TrackSource].
|
||||||
|
Future<LocalTrackPublication?> setSourceEnabled(
|
||||||
|
TrackSource source, bool enabled) async {
|
||||||
logger.fine('setSourceEnabled(source: $source, enabled: $enabled)');
|
logger.fine('setSourceEnabled(source: $source, enabled: $enabled)');
|
||||||
final pub = getTrackPublicationBySource(source) as LocalTrackPublication?;
|
final publication =
|
||||||
if (pub != null) {
|
getTrackPublicationBySource(source) as LocalTrackPublication?;
|
||||||
|
if (publication != null) {
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
await pub.unmute();
|
await publication.unmute();
|
||||||
} else {
|
} else {
|
||||||
if (source == TrackSource.screenShareVideo) {
|
if (source == TrackSource.screenShareVideo) {
|
||||||
await unpublishTrack(pub.sid);
|
await unpublishTrack(publication.sid);
|
||||||
} else {
|
} else {
|
||||||
await pub.mute();
|
await publication.mute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return publication;
|
||||||
} else if (enabled) {
|
} else if (enabled) {
|
||||||
if (source == TrackSource.camera) {
|
if (source == TrackSource.camera) {
|
||||||
final track = await LocalVideoTrack.createCameraTrack();
|
final track = await LocalVideoTrack.createCameraTrack();
|
||||||
await publishVideoTrack(track);
|
return await publishVideoTrack(track);
|
||||||
} else if (source == TrackSource.microphone) {
|
} else if (source == TrackSource.microphone) {
|
||||||
final track = await LocalAudioTrack.create();
|
final track = await LocalAudioTrack.create();
|
||||||
await publishAudioTrack(track);
|
return await publishAudioTrack(track);
|
||||||
} else if (source == TrackSource.screenShareVideo) {
|
} else if (source == TrackSource.screenShareVideo) {
|
||||||
final track = await LocalVideoTrack.createScreenShareTrack();
|
final track = await LocalVideoTrack.createScreenShareTrack();
|
||||||
await publishVideoTrack(track);
|
return await publishVideoTrack(track);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user