123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- //
- // OnlineClassManager.m
- // KulexiuForTeacher
- //
- // Created by 王智 on 2022/4/1.
- //
- #import "OnlineClassManager.h"
- #import "TXClassroomViewController.h"
- #import "LoginHelper.h"
- #import "ClassroomService.h"
- #import "LocalRenderManager.h"
- #import "KSNormalAlertView.h"
- @interface OnlineClassManager ()<ClassroomHelperDelegate>
- @property (nonatomic, strong) NSString *roomId;
- @property (nonatomic, strong) NSString *subjectName;
- @property (nonatomic, strong) NSString *subjectId;
- // 防止循环引用
- @property (nonatomic, weak) KSBaseViewController *baseCtrl;
- @property (nonatomic, strong) NSString *classEndTime;
- @end
- @implementation OnlineClassManager
- - (instancetype)init {
- if (self = [super init]) {
- [LoginHelper sharedInstance].delegate = self;
- }
- return self;
- }
- - (void)joinRoomWithId:(NSString *)roomId subjectName:(NSString *)subjectName classEndTime:(NSString *)classEndTime inViewController:(KSBaseViewController *)ctrl {
- self.roomId = roomId;
- self.subjectName = subjectName;
- self.baseCtrl = ctrl;
- self.classEndTime = classEndTime;
- [self joinRoom];
- }
- - (void)joinRoom {
- // 进入房间重置默认值
- [LocalRenderManager shareInstance].hadRenderMainView = NO;
- [LOADING_MANAGER showCustomLoading:@"加载中..."];
- [self login:NO];
- }
- #pragma mark - ClassroomHelperDelegate
- - (void)classroomDidJoin:(Classroom *)classroom {
-
- if ([self.baseCtrl.navigationController.topViewController isKindOfClass:[self.baseCtrl class]]) {
- [LOADING_MANAGER removeCustomLoading];
-
- // 加入RTC成功反馈给后端
- [self notiferIsSuccess:YES];
-
- [self pushToTRTCRoom];
- }
- }
- - (void)classroomDidJoinFailCode:(NSNumber *)code errorMessage:(nonnull NSString *)message {
- [LOADING_MANAGER removeCustomLoading];
- NSString *tipsMessage = [NSString isEmptyString:message] ? [NSString stringWithFormat:@"加入房间失败,请重试.错误码:%@",code] : message;
- [self notiferIsSuccess:NO];
- [KSNormalAlertView ks_showAlertWithTitle:tipsMessage confirmTitle:@"确定" confirm:^{
-
- }];
- }
- // 加入RTC房间失败回调
- - (void)classroomDidJoinFailRTC:(NSNumber *)code {
- [LOADING_MANAGER removeCustomLoading];
- [self notiferIsSuccess:NO];
- //
- // NSString *tipsMessage = [NSString stringWithFormat:@"加入房间失败RTC:%@",code];
- // [KSNormalAlertView ks_showAlertWithTitle:tipsMessage confirmTitle:@"确定" confirm:^{
- //
- // }];
- // [self notiferIsSuccess:NO];
- }
- - (void)notiferIsSuccess:(BOOL)isSuccess {
- [[ClassroomService sharedService] joinRoomStatusNotify:isSuccess];
- }
- - (void)classroomDidOverMaxUserCount {
- [self notiferIsSuccess:NO];
- [LOADING_MANAGER removeCustomLoading];
- [KSNormalAlertView ks_showAlertWithTitle:@"教室人数已满!" confirmTitle:@"确认" confirm:^{
- }];
- }
- - (void)pushToTRTCRoom {
- // 已经到教室页面,不需要再次push
- TXClassroomViewController *vc = [[TXClassroomViewController alloc] init];
- vc.courseId = self.roomId;
- vc.subjectId = self.subjectId;
- vc.classEndTime = self.classEndTime;
- [self.baseCtrl.navigationController pushViewController:vc animated:YES];
- }
- - (void)login:(BOOL)isAudience {
- NSString *roomId = [self.roomId stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
- NSString *userName = [UserDefault(NicknameKey) stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
- [LoginHelper sharedInstance].subjectId = self.subjectId;
- [[LoginHelper sharedInstance] login:roomId user:userName isAudience:isAudience];
- }
- @end
|