2
0

WFCUConferenceParticipantCollectionViewCell.m 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. //
  2. // WFCUConferenceParticipantCollectionViewCell.m
  3. // WFChatUIKit
  4. //
  5. // Created by dali on 2020/1/20.
  6. // Copyright © 2020 WildFireChat. All rights reserved.
  7. //
  8. #if WFCU_SUPPORT_VOIP
  9. #import "WFCUConferenceParticipantCollectionViewCell.h"
  10. #import <SDWebImage/SDWebImage.h>
  11. #import "WFCUWaitingAnimationView.h"
  12. #import "WFCUImage.h"
  13. #import "WFCUConferenceLabelView.h"
  14. @interface WFCUConferenceParticipantCollectionViewCell ()
  15. @property (nonatomic, strong)UIImageView *portraitView;
  16. @property (nonatomic, strong)WFCUWaitingAnimationView *stateLabel;
  17. @property(nonatomic, strong)NSString *userId;
  18. @property (nonatomic, strong)WFCUConferenceLabelView *conferenceLabelView;
  19. @property(nonatomic, strong)WFAVParticipantProfile *profile;
  20. @end
  21. @implementation WFCUConferenceParticipantCollectionViewCell
  22. - (instancetype)initWithFrame:(CGRect)frame {
  23. self = [super initWithFrame:frame];
  24. if(self) {
  25. self.backgroundColor = [UIColor colorWithRed:0.4 green:0.4 blue:0.4 alpha:0.4];
  26. self.layer.masksToBounds = YES;
  27. self.layer.cornerRadius = 3.f;
  28. self.layer.borderWidth = 1.f;
  29. self.layer.borderColor = [UIColor clearColor].CGColor;
  30. }
  31. return self;
  32. }
  33. - (void)setUserInfo:(WFCCUserInfo *)userInfo callProfile:(WFAVParticipantProfile *)profile {
  34. self.profile = profile;
  35. self.userId = userInfo.userId;
  36. [self.portraitView sd_setImageWithURL:[NSURL URLWithString:[userInfo.portrait stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] placeholderImage:[WFCUImage imageNamed:@"PersonalChat"]];
  37. self.portraitView.center = CGPointMake(self.bounds.size.width/2, self.bounds.size.height/2);
  38. if (profile.state == kWFAVEngineStateIncomming
  39. || profile.state == kWFAVEngineStateOutgoing
  40. || profile.state == kWFAVEngineStateConnecting) {
  41. [self.stateLabel start];
  42. self.stateLabel.hidden = NO;
  43. } else {
  44. [self.stateLabel stop];
  45. self.stateLabel.hidden = YES;
  46. }
  47. self.layer.borderColor = [UIColor clearColor].CGColor;
  48. self.portraitView.layer.borderColor = [UIColor clearColor].CGColor;
  49. self.conferenceLabelView.name = userInfo.displayName;
  50. BOOL isVideoMuted = YES;
  51. BOOL isAudioMuted = YES;
  52. if ([WFAVEngineKit sharedEngineKit].currentSession.isConference) {
  53. if(!profile.audience) {
  54. isVideoMuted = profile.videoMuted;
  55. isAudioMuted = profile.audioMuted;
  56. }
  57. } else {
  58. isVideoMuted = NO;
  59. isAudioMuted = NO;
  60. }
  61. self.conferenceLabelView.isMuteVideo = isVideoMuted;
  62. self.conferenceLabelView.isMuteAudio = isAudioMuted;
  63. if(isAudioMuted) {
  64. self.layer.borderColor = [UIColor clearColor].CGColor;
  65. }
  66. [[NSNotificationCenter defaultCenter] removeObserver:self];
  67. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onVolumeUpdated:) name:@"wfavVolumeUpdated" object:nil];
  68. CGRect frame = self.conferenceLabelView.frame;
  69. if(isVideoMuted) {
  70. self.conferenceLabelView.frame = CGRectMake(self.bounds.size.width/2 - frame.size.width/2, self.bounds.size.height/2 + 30 + 4, frame.size.width, frame.size.height);
  71. } else {
  72. self.conferenceLabelView.frame = CGRectMake(4, self.bounds.size.height - frame.size.height - 4, frame.size.width, frame.size.height);
  73. }
  74. }
  75. - (void)addSubview:(UIView *)view {
  76. [super addSubview:view];
  77. [self bringSubviewToFront:self.conferenceLabelView];
  78. }
  79. - (void)onVolumeUpdated:(NSNotification *)notification {
  80. if([notification.object isEqual:self.userId]) {
  81. NSInteger volume = [notification.userInfo[@"volume"] integerValue];
  82. if(self.conferenceLabelView.isMuteVideo) {
  83. if (volume > 1000) {
  84. self.portraitView.layer.borderColor = [UIColor greenColor].CGColor;
  85. } else {
  86. self.portraitView.layer.borderColor = [UIColor clearColor].CGColor;
  87. }
  88. self.layer.borderColor = [UIColor clearColor].CGColor;
  89. } else {
  90. if (volume > 1000) {
  91. self.layer.borderColor = [UIColor greenColor].CGColor;
  92. } else {
  93. self.layer.borderColor = [UIColor clearColor].CGColor;
  94. }
  95. self.portraitView.layer.borderColor = [UIColor clearColor].CGColor;
  96. }
  97. self.conferenceLabelView.volume = volume;
  98. }
  99. }
  100. - (WFCUConferenceLabelView *)conferenceLabelView {
  101. if(!_conferenceLabelView) {
  102. CGSize size = [WFCUConferenceLabelView sizeOffView];
  103. _conferenceLabelView = [[WFCUConferenceLabelView alloc] initWithFrame:CGRectMake(4, self.bounds.size.height - size.height - 4, size.width, size.height)];
  104. [self.contentView addSubview:_conferenceLabelView];
  105. }
  106. return _conferenceLabelView;
  107. }
  108. - (UIImageView *)portraitView {
  109. if (!_portraitView) {
  110. _portraitView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 60, 60)];
  111. _portraitView.center = self.contentView.center;
  112. _portraitView.layer.masksToBounds = YES;
  113. _portraitView.layer.cornerRadius = 30;
  114. _portraitView.layer.borderWidth = 1;
  115. _portraitView.layer.borderColor = [UIColor clearColor].CGColor;
  116. [self.contentView addSubview:_portraitView];
  117. }
  118. return _portraitView;
  119. }
  120. - (WFCUWaitingAnimationView *)stateLabel {
  121. if (!_stateLabel) {
  122. _stateLabel = [[WFCUWaitingAnimationView alloc] initWithFrame:CGRectMake(0, 0, 60, 60)];
  123. _stateLabel.animationImages = @[[WFCUImage imageNamed:@"connect_ani1"],[WFCUImage imageNamed:@"connect_ani2"],[WFCUImage imageNamed:@"connect_ani3"]];
  124. _stateLabel.animationDuration = 1;
  125. _stateLabel.animationRepeatCount = 200;
  126. _stateLabel.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.7];
  127. _stateLabel.hidden = YES;
  128. _stateLabel.layer.masksToBounds = YES;
  129. _stateLabel.layer.cornerRadius = 30;
  130. [self.portraitView addSubview:_stateLabel];
  131. }
  132. return _stateLabel;
  133. }
  134. - (void)dealloc {
  135. [[NSNotificationCenter defaultCenter] removeObserver:self];
  136. }
  137. @end
  138. #endif