OnlineClassManager.m 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. //
  2. // OnlineClassManager.m
  3. // KulexiuForTeacher
  4. //
  5. // Created by 王智 on 2022/4/1.
  6. //
  7. #import "OnlineClassManager.h"
  8. #import "TXClassroomViewController.h"
  9. #import "LoginHelper.h"
  10. #import "ClassroomService.h"
  11. #import "LocalRenderManager.h"
  12. #import "KSNormalAlertView.h"
  13. @interface OnlineClassManager ()<ClassroomHelperDelegate>
  14. @property (nonatomic, strong) NSString *roomId;
  15. @property (nonatomic, strong) NSString *subjectName;
  16. @property (nonatomic, strong) NSString *subjectId;
  17. // 防止循环引用
  18. @property (nonatomic, weak) KSBaseViewController *baseCtrl;
  19. @property (nonatomic, strong) NSString *classEndTime;
  20. @end
  21. @implementation OnlineClassManager
  22. - (instancetype)init {
  23. if (self = [super init]) {
  24. [LoginHelper sharedInstance].delegate = self;
  25. }
  26. return self;
  27. }
  28. - (void)joinRoomWithId:(NSString *)roomId subjectName:(NSString *)subjectName classEndTime:(NSString *)classEndTime inViewController:(KSBaseViewController *)ctrl {
  29. self.roomId = roomId;
  30. self.subjectName = subjectName;
  31. self.baseCtrl = ctrl;
  32. self.classEndTime = classEndTime;
  33. [self joinRoom];
  34. }
  35. - (void)joinRoom {
  36. // 进入房间重置默认值
  37. [LocalRenderManager shareInstance].hadRenderMainView = NO;
  38. [LOADING_MANAGER showCustomLoading:@"加载中..."];
  39. [self login:NO];
  40. }
  41. #pragma mark - ClassroomHelperDelegate
  42. - (void)classroomDidJoin:(Classroom *)classroom {
  43. if ([self.baseCtrl.navigationController.topViewController isKindOfClass:[self.baseCtrl class]]) {
  44. [LOADING_MANAGER removeCustomLoading];
  45. // 加入RTC成功反馈给后端
  46. [self notiferIsSuccess:YES];
  47. [self pushToTRTCRoom];
  48. }
  49. }
  50. - (void)classroomDidJoinFailCode:(NSNumber *)code errorMessage:(nonnull NSString *)message {
  51. [LOADING_MANAGER removeCustomLoading];
  52. NSString *tipsMessage = [NSString isEmptyString:message] ? [NSString stringWithFormat:@"加入房间失败,请重试.错误码:%@",code] : message;
  53. [self notiferIsSuccess:NO];
  54. [KSNormalAlertView ks_showAlertWithTitle:tipsMessage confirmTitle:@"确定" confirm:^{
  55. }];
  56. }
  57. // 加入RTC房间失败回调
  58. - (void)classroomDidJoinFailRTC:(NSNumber *)code {
  59. [LOADING_MANAGER removeCustomLoading];
  60. [self notiferIsSuccess:NO];
  61. //
  62. // NSString *tipsMessage = [NSString stringWithFormat:@"加入房间失败RTC:%@",code];
  63. // [KSNormalAlertView ks_showAlertWithTitle:tipsMessage confirmTitle:@"确定" confirm:^{
  64. //
  65. // }];
  66. // [self notiferIsSuccess:NO];
  67. }
  68. - (void)notiferIsSuccess:(BOOL)isSuccess {
  69. [[ClassroomService sharedService] joinRoomStatusNotify:isSuccess];
  70. }
  71. - (void)classroomDidOverMaxUserCount {
  72. [self notiferIsSuccess:NO];
  73. [LOADING_MANAGER removeCustomLoading];
  74. [KSNormalAlertView ks_showAlertWithTitle:@"教室人数已满!" confirmTitle:@"确认" confirm:^{
  75. }];
  76. }
  77. - (void)pushToTRTCRoom {
  78. // 已经到教室页面,不需要再次push
  79. TXClassroomViewController *vc = [[TXClassroomViewController alloc] init];
  80. vc.courseId = self.roomId;
  81. vc.subjectId = self.subjectId;
  82. vc.classEndTime = self.classEndTime;
  83. [self.baseCtrl.navigationController pushViewController:vc animated:YES];
  84. }
  85. - (void)login:(BOOL)isAudience {
  86. NSString *roomId = [self.roomId stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
  87. NSString *userName = [UserDefault(NicknameKey) stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
  88. [LoginHelper sharedInstance].subjectId = self.subjectId;
  89. [[LoginHelper sharedInstance] login:roomId user:userName isAudience:isAudience];
  90. }
  91. @end