WFCUConferencePortraitCollectionViewCell.m 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. //
  2. // WFCUPortraitCollectionViewCell.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 "WFCUConferencePortraitCollectionViewCell.h"
  10. #import <SDWebImage/SDWebImage.h>
  11. #import "WFCUImage.h"
  12. #import "WFCUConferenceLabelView.h"
  13. @interface WFCUConferencePortraitCollectionViewCell ()
  14. @property (nonatomic, strong)UIImageView *portraitView;
  15. @property (nonatomic, strong)UILabel *nameLabel;
  16. @property (nonatomic, strong)UIImageView *stateLabel;
  17. @property (nonatomic, strong)WFCUConferenceLabelView *conferenceLabelView;
  18. @end
  19. @implementation WFCUConferencePortraitCollectionViewCell
  20. - (void)setUserInfo:(WFCCUserInfo *)userInfo {
  21. _userInfo = userInfo;
  22. self.layer.borderWidth = 1.f;
  23. self.layer.borderColor = [UIColor clearColor].CGColor;
  24. [self.portraitView sd_setImageWithURL:[NSURL URLWithString:[userInfo.portrait stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] placeholderImage:[WFCUImage imageNamed:@"PersonalChat"]];
  25. self.nameLabel.text = userInfo.displayName;
  26. self.conferenceLabelView.name = userInfo.displayName;
  27. [[NSNotificationCenter defaultCenter] removeObserver:self];
  28. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onVolumeUpdated:) name:@"wfavVolumeUpdated" object:nil];
  29. }
  30. - (void)onVolumeUpdated:(NSNotification *)notification {
  31. if([notification.object isEqual:self.userInfo.userId]) {
  32. NSInteger volume = [notification.userInfo[@"volume"] integerValue];
  33. if (volume > 1000) {
  34. self.layer.borderColor = [UIColor greenColor].CGColor;
  35. } else {
  36. self.layer.borderColor = [UIColor clearColor].CGColor;
  37. }
  38. self.conferenceLabelView.volume = volume;
  39. }
  40. }
  41. -(void)setProfile:(WFAVParticipantProfile *)profile {
  42. _profile = profile;
  43. if (profile.state == kWFAVEngineStateConnected || profile.state == kWFAVEngineStateIdle) {
  44. [self.stateLabel stopAnimating];
  45. self.stateLabel.hidden = YES;
  46. } else {
  47. [self.stateLabel startAnimating];
  48. self.stateLabel.hidden = NO;
  49. }
  50. BOOL isVideoMuted = YES;
  51. BOOL isAudioMuted = YES;
  52. if(!profile.audience) {
  53. isVideoMuted = profile.videoMuted;
  54. isAudioMuted = profile.audioMuted;
  55. }
  56. self.conferenceLabelView.isMuteVideo = isVideoMuted;
  57. self.conferenceLabelView.isMuteAudio = isAudioMuted;
  58. }
  59. - (void)addSubview:(UIView *)view {
  60. [super addSubview:view];
  61. [self bringSubviewToFront:self.conferenceLabelView];
  62. }
  63. - (UIImageView *)portraitView {
  64. if (!_portraitView) {
  65. _portraitView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.itemSize, self.itemSize)];
  66. _portraitView.layer.masksToBounds = YES;
  67. _portraitView.layer.cornerRadius = 2.f;
  68. [self addSubview:_portraitView];
  69. }
  70. return _portraitView;
  71. }
  72. - (UILabel *)nameLabel {
  73. if (!_nameLabel) {
  74. _nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, self.itemSize, self.itemSize, self.labelSize)];
  75. _nameLabel.font = [UIFont systemFontOfSize:self.labelSize - 4];
  76. _nameLabel.textColor = [UIColor whiteColor];
  77. _nameLabel.textAlignment = NSTextAlignmentCenter;
  78. [self addSubview:_nameLabel];
  79. }
  80. return _nameLabel;
  81. }
  82. - (UIImageView *)stateLabel {
  83. if (!_stateLabel) {
  84. _stateLabel = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.itemSize, self.itemSize)];
  85. _stateLabel.animationImages = @[[WFCUImage imageNamed:@"connect_ani1"],[WFCUImage imageNamed:@"connect_ani2"],[WFCUImage imageNamed:@"connect_ani3"]];
  86. _stateLabel.animationDuration = 1.f;
  87. _stateLabel.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.7];
  88. [self addSubview:_stateLabel];
  89. }
  90. return _stateLabel;
  91. }
  92. - (WFCUConferenceLabelView *)conferenceLabelView {
  93. if(!_conferenceLabelView) {
  94. CGSize size = [WFCUConferenceLabelView sizeOffView];
  95. _conferenceLabelView = [[WFCUConferenceLabelView alloc] initWithFrame:CGRectMake(4, self.bounds.size.height - size.height - 4, size.width, size.height)];
  96. [self addSubview:_conferenceLabelView];
  97. }
  98. return _conferenceLabelView;
  99. }
  100. - (void)dealloc {
  101. [[NSNotificationCenter defaultCenter] removeObserver:self];
  102. }
  103. @end
  104. #endif