ClassroomMainContainer.m 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. //
  2. // ClassroomMainContainer.m
  3. // StudentDaya
  4. //
  5. // Created by Kyle on 2020/6/12.
  6. // Copyright © 2020 DayaMusic. All rights reserved.
  7. //
  8. #import "ClassroomMainContainer.h"
  9. #import "RTCService.h"
  10. #import "LocalRenderManager.h"
  11. @interface ClassroomMainContainer ()
  12. @property (nonatomic, strong) UIView *tapGestureView;
  13. @property (nonatomic) CGRect currentVideoFrame;
  14. @property (nonatomic) CGRect originVideoFrame;
  15. @end
  16. @implementation ClassroomMainContainer
  17. - (instancetype)initWithFrame:(CGRect)frame {
  18. self = [super initWithFrame:frame];
  19. if (self) {
  20. self.backgroundColor = [UIColor colorWithHexString:@"141414" alpha:1];
  21. [self addSubview:self.emptyView];
  22. [self addSubview:self.videoBackView];
  23. [self.videoBackView addSubview:self.videoView];
  24. self.originVideoFrame = self.videoBackView.frame;
  25. self.currentVideoFrame = self.originVideoFrame;
  26. }
  27. return self;
  28. }
  29. - (void)didChangeRole:(Role)role {
  30. [self.emptyView changeRole:role];
  31. }
  32. - (void)containerViewRenderView:(RoomMember *)member {
  33. self.videoBackView.hidden = NO;
  34. self.videoView.hidden = NO;
  35. if([[ClassroomService sharedService].currentRoom.currentMemberId isEqualToString:member.userId]) {
  36. RoomMember *curMemeber =[ClassroomService sharedService].currentRoom.currentMember;
  37. [[RTCService sharedInstance] renderLocalVideoOnView:self.videoView cameraEnable:curMemeber.cameraEnable];
  38. [LocalRenderManager shareInstance].hadRenderMainView = YES;
  39. }else {
  40. [LocalRenderManager shareInstance].hadRenderMainView = NO;
  41. [[RTCService sharedInstance] exchangeRemoteUserAVStreamToNomalSteam:member.userId callback:^{
  42. [[RTCService sharedInstance] renderRemoteVideoOnView:self.videoView forUser:member.userId];
  43. }];
  44. }
  45. self.member = member;
  46. }
  47. - (void)cancelRenderView {
  48. [LocalRenderManager shareInstance].hadRenderMainView = NO;
  49. // 如何关闭了摄像头,可能导致videoView 遮挡控制事件
  50. [self updateVideoViewFrame:NO];
  51. self.videoBackView.hidden = YES;
  52. }
  53. #pragma mark - private method
  54. - (void)updateVideoViewFrame:(BOOL)isFull {
  55. self.currentVideoFrame = self.frame;
  56. if(isFull) {
  57. [self.superview addSubview:self.videoBackView];
  58. [self.superview bringSubviewToFront:self.videoBackView];
  59. CGFloat width = 0.0f;
  60. CGFloat height = 0.0f;
  61. height = kScreen_Width / 4.0f * 3;
  62. if (height > kScreenHeight) {
  63. height = kScreenHeight;
  64. }
  65. width = height / 3.0f * 4;
  66. self.videoView.frame = CGRectMake((kScreenWidth - width) / 2.0f, 0, width, height);
  67. }else {
  68. [self.videoBackView removeFromSuperview];
  69. [self addSubview:self.videoBackView];
  70. self.currentVideoFrame = self.originVideoFrame;
  71. self.videoView.frame = CGRectMake(0, 0, CGRectGetWidth(self.currentVideoFrame), CGRectGetHeight(self.currentVideoFrame));
  72. }
  73. self.videoBackView.frame = self.currentVideoFrame;
  74. }
  75. #pragma mark - getter
  76. - (UIView *)videoBackView {
  77. if (!_videoBackView) {
  78. CGFloat width = 0.0f;
  79. CGFloat height = 0.0f;
  80. height = kScreenHeight - 20;
  81. width = height / 3.0f * 4;
  82. if (width > kScreenWidth - 180) {
  83. width = kScreenWidth - 180;
  84. height = width / 4.0f * 3;
  85. }
  86. _videoBackView = [[UIView alloc] initWithFrame:CGRectMake(10, 10, width, height)];
  87. _videoBackView.backgroundColor = [UIColor colorWithHexString:@"141414" alpha:1];
  88. }
  89. return _videoBackView;
  90. }
  91. - (UIView *)videoView {
  92. if(!_videoView) {
  93. CGFloat width = 0.0f;
  94. CGFloat height = 0.0f;
  95. height = kScreenHeight - 20;
  96. width = height / 3.0f * 4;
  97. if (width > kScreenWidth - 180) {
  98. width = kScreenWidth - 180;
  99. height = width / 4.0f * 3;
  100. }
  101. _videoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, width, height)];
  102. }
  103. return _videoView;
  104. }
  105. - (EmptyView *)emptyView {
  106. if (!_emptyView) {
  107. CGFloat width = 0.0f;
  108. CGFloat height = 0.0f;
  109. height = kScreenHeight - 20;
  110. width = height / 3.0f * 4;
  111. if (width > kScreenWidth - 180) {
  112. width = kScreenWidth - 180;
  113. height = width / 4.0f * 3;
  114. }
  115. _emptyView = [[EmptyView alloc] initWithFrame:CGRectMake(10, 10, width, height) role:[ClassroomService sharedService].currentRoom.currentMember.role];
  116. }
  117. return _emptyView;
  118. }
  119. /*
  120. // Only override drawRect: if you perform custom drawing.
  121. // An empty implementation adversely affects performance during animation.
  122. - (void)drawRect:(CGRect)rect {
  123. // Drawing code
  124. }
  125. */
  126. @end