|
@@ -1,9 +1,11 @@
|
|
|
import 'dart:async';
|
|
|
+import 'dart:collection';
|
|
|
|
|
|
import 'package:fis_common/logger/logger.dart';
|
|
|
import 'package:fis_lib_media_rt/implementations/trtc/channel.dart';
|
|
|
import 'package:fis_lib_media_rt/implementations/trtc/resolutions.dart';
|
|
|
import 'package:fis_lib_media_rt/implementations/trtc/room.dart';
|
|
|
+import 'package:fis_lib_media_rt/interface/channel.dart';
|
|
|
import 'package:fis_lib_media_rt/interface/enums.dart';
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
import 'package:tencent_trtc_cloud/trtc_cloud_def.dart';
|
|
@@ -12,7 +14,6 @@ import 'package:tencent_trtc_cloud/trtc_cloud_listener.dart';
|
|
|
import '../../base/publisher.dart';
|
|
|
import '../../interface/publisher.dart';
|
|
|
import 'client_getter_mixin.dart';
|
|
|
-import 'player.dart';
|
|
|
|
|
|
class TrtcPublisher extends BasePublisher with TrtcClientGetterMixin {
|
|
|
// ignore: non_constant_identifier_names
|
|
@@ -27,40 +28,41 @@ class TrtcPublisher extends BasePublisher with TrtcClientGetterMixin {
|
|
|
final quality = TRTCCloudDef.TRTC_AUDIO_QUALITY_DEFAULT;
|
|
|
final isFrontCamera = true;
|
|
|
final localViewId = 0;
|
|
|
- TrtcPublishChannel? _publishChannel;
|
|
|
+ TrtcPublishChannel? get _channel =>
|
|
|
+ room.localMember.channels.first as TrtcPublishChannel;
|
|
|
|
|
|
PublisherProfile? _profile;
|
|
|
|
|
|
TrtcPublisher({required super.room}) {
|
|
|
_trtcRoom = room as TrtcRoom;
|
|
|
+ _buildPreviewChannel();
|
|
|
}
|
|
|
|
|
|
late TrtcRoom _trtcRoom;
|
|
|
|
|
|
+ @override
|
|
|
+ UnmodifiableListView<IPublishChannel> get channels => UnmodifiableListView(
|
|
|
+ room.localMember.channels.map((e) => e as IPublishChannel));
|
|
|
+
|
|
|
@override
|
|
|
Future<void> startLocal() async {
|
|
|
try {
|
|
|
- _buildPreviewChannel();
|
|
|
- if (isOpenMic) {
|
|
|
- if (kIsWeb) {
|
|
|
- // _trtcRoom.events.once(
|
|
|
- // TRTCCloudListener.onStreamPublish,
|
|
|
- // (param) async {
|
|
|
- // if (param == 0) {
|
|
|
- // await client
|
|
|
- // .startLocalAudio(TRTCCloudDef.TRTC_AUDIO_QUALITY_DEFAULT);
|
|
|
- // print('🎉Mic Capture Started');
|
|
|
- // }
|
|
|
- // },
|
|
|
- // );
|
|
|
- } else {
|
|
|
- await client.startLocalAudio(quality);
|
|
|
- }
|
|
|
+ // _buildPreviewChannel();
|
|
|
+ if (kIsWeb) {
|
|
|
+ _trtcRoom.events.once(
|
|
|
+ TRTCCloudListener.onStreamPublish,
|
|
|
+ (param) async {
|
|
|
+ if (param == 0) {
|
|
|
+ await client
|
|
|
+ .startLocalAudio(TRTCCloudDef.TRTC_AUDIO_QUALITY_DEFAULT);
|
|
|
+ print('🎉Mic Capture Started');
|
|
|
+ }
|
|
|
+ },
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ await client.startLocalAudio(quality);
|
|
|
}
|
|
|
- if (isOpenCamera) {
|
|
|
- // TODO: set mute state of video & audio
|
|
|
- }
|
|
|
- room.localMember.addChannel(_publishChannel!);
|
|
|
+ _channel!.isPreviewing = true;
|
|
|
} catch (e) {
|
|
|
logger.e("[TrtcPublisher] start local preview error", e);
|
|
|
}
|
|
@@ -69,9 +71,10 @@ class TrtcPublisher extends BasePublisher with TrtcClientGetterMixin {
|
|
|
@override
|
|
|
Future<void> stopLocal() async {
|
|
|
try {
|
|
|
- _removePreviewChannel();
|
|
|
- await client.stopLocalAudio(); //await client.muteLocalAudio(isMute);
|
|
|
+ await client.stopLocalAudio();
|
|
|
await client.stopLocalPreview();
|
|
|
+ _channel!.isPreviewing = false;
|
|
|
+ // _removePreviewChannel();
|
|
|
} catch (e) {
|
|
|
logger.e("[TrtcPublisher] stop local preview error", e);
|
|
|
}
|
|
@@ -89,25 +92,28 @@ class TrtcPublisher extends BasePublisher with TrtcClientGetterMixin {
|
|
|
C_BITRATE_RANGE[currProfile.resolution]?.defaultBitrate ??
|
|
|
900;
|
|
|
|
|
|
- _buildPreviewChannel();
|
|
|
- _publishChannel!.videoEncParam = TRTCVideoEncParam(
|
|
|
+ // _buildPreviewChannel();
|
|
|
+ _channel!.videoEncParam = TRTCVideoEncParam(
|
|
|
videoFps: currProfile.frameRate,
|
|
|
videoResolution: resolution,
|
|
|
videoBitrate: bitrate,
|
|
|
videoResolutionMode: currProfile.resolutionMode.index,
|
|
|
);
|
|
|
|
|
|
- client.setVideoEncoderParam(_publishChannel!.videoEncParam!);
|
|
|
+ client.setVideoEncoderParam(_channel!.videoEncParam!);
|
|
|
print('✨Changed Resolution to 480P');
|
|
|
}
|
|
|
|
|
|
void _buildPreviewChannel() {
|
|
|
- _publishChannel ??= TrtcPublishChannel(member: room.localMember);
|
|
|
+ if (channels.isEmpty) {
|
|
|
+ final channel = TrtcPublishChannel(member: room.localMember);
|
|
|
+ room.localMember.addChannel(channel);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
void _removePreviewChannel() {
|
|
|
- if (_publishChannel != null) {
|
|
|
- room.localMember.removeChannel(_publishChannel!);
|
|
|
+ if (channels.isNotEmpty) {
|
|
|
+ room.localMember.clearChannels(); //TODO: 目前只有主画面的
|
|
|
}
|
|
|
}
|
|
|
|