1
This commit is contained in:
@@ -3,7 +3,7 @@ import 'package:app/config/config.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../viewmodel/students_view_model.dart';
|
||||
import '../viewmodel/tch_room_vm.dart';
|
||||
import 'student_item.dart';
|
||||
|
||||
class ContentView extends StatefulWidget {
|
||||
@@ -14,19 +14,24 @@ class ContentView extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _ContentViewState extends State<ContentView> {
|
||||
// bool isLoading = true;
|
||||
|
||||
//声网数据
|
||||
RtcEngine? _engine;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// _initRtc();
|
||||
}
|
||||
|
||||
void _initRtc() async {
|
||||
final vm = context.read<StudentsViewModel>();
|
||||
final vm = context.read<TchRoomVM>();
|
||||
_engine = createAgoraRtcEngine();
|
||||
//初始化 RtcEngine,设置频道场景为 channelProfileLiveBroadcasting(直播场景)
|
||||
await _engine!.initialize(
|
||||
RtcEngineContext(
|
||||
appId: Config.swAppId,
|
||||
channelProfile: ChannelProfileType.channelProfileLiveBroadcasting,
|
||||
channelProfile: ChannelProfileType.channelProfileCommunication,
|
||||
),
|
||||
);
|
||||
//添加回调
|
||||
@@ -39,7 +44,8 @@ class _ContentViewState extends State<ContentView> {
|
||||
// 远端用户或主播加入当前频道回调
|
||||
onUserJoined: (RtcConnection connection, int remoteUid, int elapsed) {},
|
||||
// 远端用户或主播离开当前频道回调
|
||||
onUserOffline: (RtcConnection connection, int remoteUid, UserOfflineReasonType reason) {},
|
||||
onUserOffline:
|
||||
(RtcConnection connection, int remoteUid, UserOfflineReasonType reason) {},
|
||||
),
|
||||
);
|
||||
//启动视频模块
|
||||
@@ -48,7 +54,7 @@ class _ContentViewState extends State<ContentView> {
|
||||
await _engine!.joinChannel(
|
||||
token: vm.rtcToken!.token,
|
||||
channelId: vm.rtcToken!.channel,
|
||||
uid: int.parse(vm.rtcToken!.uid),
|
||||
uid: vm.rtcToken!.uid,
|
||||
options: ChannelMediaOptions(
|
||||
// 自动订阅所有视频流
|
||||
autoSubscribeVideo: true,
|
||||
@@ -64,22 +70,13 @@ class _ContentViewState extends State<ContentView> {
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
final vm = context.read<StudentsViewModel>();
|
||||
if (_engine == null && vm.students.isNotEmpty) {
|
||||
_initRtc();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Consumer<StudentsViewModel>(
|
||||
return Consumer<TchRoomVM>(
|
||||
builder: (context, vm, _) {
|
||||
if (vm.students.isEmpty) {
|
||||
return Center(
|
||||
child: Text('无学生在场,请通知学生入场'),
|
||||
child: Text('准备中'),
|
||||
);
|
||||
}
|
||||
//选中的学生
|
||||
@@ -96,6 +93,7 @@ class _ContentViewState extends State<ContentView> {
|
||||
Expanded(
|
||||
child: StudentItem(
|
||||
user: activeStudent,
|
||||
engine: _engine,
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
@@ -107,6 +105,7 @@ class _ContentViewState extends State<ContentView> {
|
||||
height: 250,
|
||||
child: StudentItem(
|
||||
user: item,
|
||||
engine: _engine,
|
||||
),
|
||||
);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user