better platform check
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
import 'platform/io.dart' if (dart.library.html) 'platform/web.dart';
|
||||
|
||||
// Returns the current platform which works for both web and devices.
|
||||
PlatformType lkPlatform() => lkPlatformImplementation();
|
||||
bool lkPlatformIs(PlatformType type) => lkPlatform() == type;
|
||||
|
||||
enum PlatformType {
|
||||
web,
|
||||
windows,
|
||||
linux,
|
||||
macOS,
|
||||
android,
|
||||
fuchsia,
|
||||
iOS,
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import '../platform.dart';
|
||||
import 'dart:io';
|
||||
|
||||
PlatformType lkPlatformImplementation() {
|
||||
if (Platform.isWindows) return PlatformType.windows;
|
||||
if (Platform.isFuchsia) return PlatformType.fuchsia;
|
||||
if (Platform.isMacOS) return PlatformType.macOS;
|
||||
if (Platform.isLinux) return PlatformType.linux;
|
||||
if (Platform.isIOS) return PlatformType.iOS;
|
||||
return PlatformType.android;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
import '../platform.dart';
|
||||
|
||||
PlatformType lkPlatformImplementation() => PlatformType.web;
|
||||
@@ -1,4 +1,4 @@
|
||||
import 'platforms/io.dart' if (dart.library.html) 'platforms/web.dart';
|
||||
import 'websocket/io.dart' if (dart.library.html) 'websocket/web.dart';
|
||||
|
||||
class WebSocketException implements Exception {
|
||||
final int code;
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
// import 'package:audio_session/audio_session.dart' as _as;
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import '../support/platform.dart';
|
||||
|
||||
import 'package:synchronized/synchronized.dart' as sync;
|
||||
|
||||
@@ -78,7 +74,7 @@ mixin AudioManagementMixin on AudioTrack {
|
||||
logger.fine('[$runtimeType] didUpdateSate: $audioTrackState');
|
||||
|
||||
NativeAudioConfiguration? config;
|
||||
if (!kIsWeb && Platform.isIOS) {
|
||||
if (!lkPlatformIs(PlatformType.iOS)) {
|
||||
// Only iOS for now...
|
||||
config = await nativeAudioConfigurationForAudioTrackState
|
||||
.call(audioTrackState);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import 'dart:io' show Platform;
|
||||
|
||||
import 'package:flutter_webrtc/flutter_webrtc.dart' as rtc;
|
||||
import '../support/platform.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
import '../exceptions.dart';
|
||||
@@ -48,7 +47,7 @@ abstract class LocalTrack extends Track {
|
||||
logger.fine('LocalTrack.mute() muted: $muted');
|
||||
if (muted) return false; // already muted
|
||||
await disable();
|
||||
if (!Platform.isWindows) {
|
||||
if (!lkPlatformIs(PlatformType.windows)) {
|
||||
await stop();
|
||||
}
|
||||
updateMuted(true, shouldSendSignal: true);
|
||||
@@ -61,7 +60,7 @@ abstract class LocalTrack extends Track {
|
||||
Future<bool> unmute() async {
|
||||
logger.fine('LocalTrack.unmute() muted: $muted');
|
||||
if (!muted) return false; // already un-muted
|
||||
if (!Platform.isWindows) {
|
||||
if (!lkPlatformIs(PlatformType.windows)) {
|
||||
await restartTrack();
|
||||
}
|
||||
await enable();
|
||||
@@ -74,8 +73,16 @@ abstract class LocalTrack extends Track {
|
||||
final didStop = await super.stop();
|
||||
if (didStop) {
|
||||
logger.fine('Stopping mediaStreamTrack...');
|
||||
await mediaStreamTrack.stop();
|
||||
await mediaStream.dispose();
|
||||
try {
|
||||
await mediaStreamTrack.stop();
|
||||
} catch (error) {
|
||||
logger.severe('MediaStreamTrack.stop() did throw $error');
|
||||
}
|
||||
try {
|
||||
await mediaStream.dispose();
|
||||
} catch (error) {
|
||||
logger.severe('MediaStreamTrack.dispose() did throw $error');
|
||||
}
|
||||
}
|
||||
return didStop;
|
||||
}
|
||||
@@ -131,7 +138,11 @@ abstract class LocalTrack extends Track {
|
||||
final newTrack = newStream.getTracks().first;
|
||||
|
||||
// replace track on sender
|
||||
await sender?.replaceTrack(newTrack);
|
||||
try {
|
||||
await sender?.replaceTrack(newTrack);
|
||||
} catch (error) {
|
||||
logger.severe('RTCRtpSender.replaceTrack() did throw $error');
|
||||
}
|
||||
|
||||
// set new stream & track to this object
|
||||
updateMediaStreamAndTrack(newStream, newTrack);
|
||||
|
||||
Reference in New Issue
Block a user