自习室优化ok
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import 'package:agora_rtc_engine/agora_rtc_engine.dart';
|
||||
import 'package:app/config/config.dart';
|
||||
import 'package:app/providers/user_store.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:wakelock_plus/wakelock_plus.dart';
|
||||
|
||||
import '../viewmodel/tch_room_vm.dart';
|
||||
import 'student_item.dart';
|
||||
@@ -27,11 +27,11 @@ class _ContentViewState extends State<ContentView> {
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
WakelockPlus.disable();
|
||||
_dispose();
|
||||
}
|
||||
|
||||
void _initRtc() async {
|
||||
UserStore userStore = context.read<UserStore>();
|
||||
final vm = context.read<TchRoomVM>();
|
||||
_engine = createAgoraRtcEngine();
|
||||
//初始化 RtcEngine,设置频道场景为 channelProfileLiveBroadcasting(直播场景)
|
||||
@@ -41,39 +41,33 @@ class _ContentViewState extends State<ContentView> {
|
||||
channelProfile: ChannelProfileType.channelProfileCommunication,
|
||||
),
|
||||
);
|
||||
//添加回调
|
||||
_engine!.registerEventHandler(
|
||||
RtcEngineEventHandler(
|
||||
// 成功加入频道回调
|
||||
onJoinChannelSuccess: (RtcConnection connection, int elapsed) {
|
||||
setState(() {});
|
||||
},
|
||||
// 远端用户或主播加入当前频道回调
|
||||
onUserJoined: (RtcConnection connection, int remoteUid, int elapsed) {},
|
||||
// 远端用户或主播离开当前频道回调
|
||||
onUserOffline: (RtcConnection connection, int remoteUid, UserOfflineReasonType reason) {},
|
||||
),
|
||||
);
|
||||
//启动视频模块
|
||||
// 启用视频模块
|
||||
await _engine!.enableVideo();
|
||||
//加入频道
|
||||
await _engine!.joinChannel(
|
||||
token: vm.rtcToken!.token,
|
||||
channelId: vm.rtcToken!.channel,
|
||||
uid: userStore.userInfo!.id,
|
||||
options: ChannelMediaOptions(
|
||||
// 自动订阅所有视频流
|
||||
autoSubscribeVideo: true,
|
||||
// 自动订阅所有音频流
|
||||
autoSubscribeAudio: true,
|
||||
// 发布摄像头采集的视频
|
||||
publishCameraTrack: true,
|
||||
// 发布麦克风采集的音频
|
||||
publishMicrophoneTrack: true,
|
||||
// 设置用户角色为 clientRoleBroadcaster(主播)或 clientRoleAudience(观众)
|
||||
clientRoleType: ClientRoleType.clientRoleBroadcaster,
|
||||
),
|
||||
);
|
||||
// 开启本地预览
|
||||
await _engine!.startPreview();
|
||||
|
||||
final status = await _engine!.getConnectionState();
|
||||
WakelockPlus.enable();
|
||||
if (status == ConnectionStateType.connectionStateDisconnected) {
|
||||
//加入频道
|
||||
await _engine!.joinChannel(
|
||||
token: vm.rtcToken!.token,
|
||||
channelId: vm.rtcToken!.channel,
|
||||
uid: vm.rtcToken!.uid,
|
||||
options: ChannelMediaOptions(
|
||||
// 自动订阅所有视频流
|
||||
autoSubscribeVideo: true,
|
||||
// 自动订阅所有音频流
|
||||
autoSubscribeAudio: true,
|
||||
// 发布摄像头采集的视频
|
||||
publishCameraTrack: true,
|
||||
// 发布麦克风采集的音频
|
||||
publishMicrophoneTrack: true,
|
||||
// 设置用户角色为 clientRoleBroadcaster(主播)或 clientRoleAudience(观众)
|
||||
clientRoleType: ClientRoleType.clientRoleBroadcaster,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//销毁
|
||||
@@ -89,8 +83,11 @@ class _ContentViewState extends State<ContentView> {
|
||||
return Consumer<TchRoomVM>(
|
||||
builder: (context, vm, _) {
|
||||
if (vm.students.isEmpty) {
|
||||
return Center(
|
||||
child: Text('准备中'),
|
||||
return Align(
|
||||
child: Text(
|
||||
'学生还没入场',
|
||||
style: TextStyle(color: Colors.white),
|
||||
),
|
||||
);
|
||||
}
|
||||
//选中的学生
|
||||
@@ -105,9 +102,30 @@ class _ContentViewState extends State<ContentView> {
|
||||
spacing: 15,
|
||||
children: [
|
||||
Expanded(
|
||||
child: StudentItem(
|
||||
user: activeStudent,
|
||||
engine: _engine,
|
||||
child: Stack(
|
||||
children: [
|
||||
StudentItem(
|
||||
user: activeStudent,
|
||||
engine: _engine,
|
||||
),
|
||||
Positioned(
|
||||
top: 0,
|
||||
left: 0,
|
||||
child: Container(
|
||||
width: 150,
|
||||
color: Colors.black,
|
||||
child: AspectRatio(
|
||||
aspectRatio: 1 / 1.2,
|
||||
child: AgoraVideoView(
|
||||
controller: VideoViewController(
|
||||
rtcEngine: _engine!,
|
||||
canvas: const VideoCanvas(uid: 0),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
|
||||
Reference in New Issue
Block a user