Better audio management (#10)
* add audio_session package * `AudioManager` initial design * try to integrate audio manager * configure audio session * `DisposeAware` disposing if already published causes exception. * organize * guard flutter_webrtc calls * websocket async fix * use `ConnectionState` instead of `_isClosed` and `isReconnecting` * change create audio track defaults * update protos * protocol 3 speaker updates * fix exception * emit `RoomDisconnectedEvent` only once * fix exception * keep track of local / remote audio tracks * explicit types * manage track state * re-structure audio management * change defaults * unpublish all * use experimental build * change defaults * configuring is optional * call native `RTCAudioSession.setConfiguration` * defaults adjustment * iOS only for now * use lib 92.4515.07 * clean up * revert audio options for now * remove pod source * rename apple related audio * `createListener` method * organize native audio * `SpeakingChangedEvent` only on `Participant` * refactoring * fix ios compile * fix configure audio only for iOS logic * minor fix & clean up * change dispose logic * format protos * fix unpublishTrack * `createListener` into a mixin * simplify * use flutter_webrtc master * unpublish for example * update ios icon * android icon * web icon * favicon
This commit is contained in:
@@ -1,13 +1,17 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_webrtc/flutter_webrtc.dart' as rtc;
|
||||
import 'package:livekit_client/src/classes/change_notifier.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
import '../extensions.dart';
|
||||
import '../logger.dart';
|
||||
import '../proto/livekit_models.pb.dart' as lk_models;
|
||||
import '../support/disposable.dart';
|
||||
|
||||
/// Wrapper around a MediaStreamTrack with additional metadata.
|
||||
/// Base for [AudioTrack] and [VideoTrack],
|
||||
/// can not be instantiated directly.
|
||||
abstract class Track extends LKChangeNotifier {
|
||||
abstract class Track extends DisposableChangeNotifier {
|
||||
static const cameraName = 'camera';
|
||||
static const screenShareName = 'screen';
|
||||
|
||||
@@ -19,6 +23,10 @@ abstract class Track extends LKChangeNotifier {
|
||||
rtc.RTCRtpTransceiver? transceiver;
|
||||
String? _cid;
|
||||
|
||||
// started / stopped
|
||||
bool _active = false;
|
||||
bool get isActive => _active;
|
||||
|
||||
Track(
|
||||
this.kind,
|
||||
this.name,
|
||||
@@ -50,7 +58,33 @@ abstract class Track extends LKChangeNotifier {
|
||||
return cid;
|
||||
}
|
||||
|
||||
Future<void> stop() async {
|
||||
await mediaStreamTrack.stop();
|
||||
// returns true if started, false if already started
|
||||
@mustCallSuper
|
||||
Future<bool> start() async {
|
||||
if (_active) {
|
||||
// already started
|
||||
return false;
|
||||
}
|
||||
|
||||
_active = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
// returns true if stopped, false if already stopped
|
||||
@mustCallSuper
|
||||
Future<bool> stop() async {
|
||||
if (!_active) {
|
||||
// already stopped
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
await mediaStreamTrack.stop();
|
||||
} catch (_) {
|
||||
logger.warning('[$objectId] rtc.mediaStreamTrack.stop() did throw ${_}');
|
||||
}
|
||||
|
||||
_active = false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user