优化了老师端的等待状态判断逻辑

This commit is contained in:
zhutao
2025-11-23 22:09:39 +08:00
parent 5784a0a5d4
commit 4ecb0c35d6
8 changed files with 276 additions and 67 deletions

View File

@@ -1,5 +1,6 @@
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';
@@ -14,17 +15,23 @@ class ContentView extends StatefulWidget {
}
class _ContentViewState extends State<ContentView> {
//声网数据
RtcEngine? _engine;
@override
void initState() {
super.initState();
// _initRtc();
_initRtc();
}
@override
void dispose() {
super.dispose();
_dispose();
}
void _initRtc() async {
UserStore userStore = context.read<UserStore>();
final vm = context.read<TchRoomVM>();
_engine = createAgoraRtcEngine();
//初始化 RtcEngine设置频道场景为 channelProfileLiveBroadcasting直播场景
@@ -44,8 +51,7 @@ 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) {},
),
);
//启动视频模块
@@ -54,7 +60,7 @@ class _ContentViewState extends State<ContentView> {
await _engine!.joinChannel(
token: vm.rtcToken!.token,
channelId: vm.rtcToken!.channel,
uid: vm.rtcToken!.uid,
uid: userStore.userInfo!.id,
options: ChannelMediaOptions(
// 自动订阅所有视频流
autoSubscribeVideo: true,
@@ -70,6 +76,14 @@ class _ContentViewState extends State<ContentView> {
);
}
//销毁
Future<void> _dispose() async {
if (_engine != null) {
await _engine!.leaveChannel();
await _engine!.release();
}
}
@override
Widget build(BuildContext context) {
return Consumer<TchRoomVM>(