2
0

WFCUParticipantCollectionViewCell.m 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. //
  2. // WFCUParticipantCollectionViewCell.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 "WFCUParticipantCollectionViewCell.h"
  10. #import <SDWebImage/SDWebImage.h>
  11. #import "WFCUWaitingAnimationView.h"
  12. @interface WFCUParticipantCollectionViewCell ()
  13. @property (nonatomic, strong)UIImageView *portraitView;
  14. @property (nonatomic, strong)WFCUWaitingAnimationView *stateLabel;
  15. @property (nonatomic, strong)UIImageView *speakingView;
  16. @end
  17. @implementation WFCUParticipantCollectionViewCell
  18. - (void)setUserInfo:(WFCCUserInfo *)userInfo callProfile:(WFAVParticipantProfile *)profile {
  19. [self.portraitView sd_setImageWithURL:[NSURL URLWithString:[userInfo.portrait stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] placeholderImage:[UIImage imageNamed:@"PersonalChat"]];
  20. if (profile.state == kWFAVEngineStateIncomming
  21. || profile.state == kWFAVEngineStateOutgoing
  22. || profile.state == kWFAVEngineStateConnecting) {
  23. [self.stateLabel start];
  24. self.stateLabel.hidden = NO;
  25. } else {
  26. [self.stateLabel stop];
  27. if (profile.videoMuted) {
  28. self.stateLabel.hidden = NO;
  29. self.stateLabel.image = [UIImage imageNamed:@"disable_video"];
  30. } else {
  31. self.stateLabel.hidden = YES;
  32. }
  33. }
  34. _speakingView.hidden = YES;
  35. [[NSNotificationCenter defaultCenter] removeObserver:self];
  36. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onVolumeUpdated:) name:@"wfavVolumeUpdated" object:userInfo.userId];
  37. }
  38. - (void)onVolumeUpdated:(NSNotification *)notification {
  39. NSInteger volume = [notification.userInfo[@"volume"] integerValue];
  40. if (volume > 1000) {
  41. self.speakingView.hidden = NO;
  42. [self bringSubviewToFront:self.speakingView];
  43. } else {
  44. self.speakingView.hidden = YES;
  45. }
  46. }
  47. - (UIImageView *)portraitView {
  48. if (!_portraitView) {
  49. _portraitView = [[UIImageView alloc] initWithFrame:self.bounds];
  50. _portraitView.layer.masksToBounds = YES;
  51. _portraitView.layer.cornerRadius = 2.f;
  52. [self addSubview:_portraitView];
  53. }
  54. return _portraitView;
  55. }
  56. - (UIImageView *)speakingView {
  57. if (!_speakingView) {
  58. _speakingView = [[UIImageView alloc] initWithFrame:CGRectMake(0, self.bounds.size.height - 20, 20, 20)];
  59. _speakingView.layer.masksToBounds = YES;
  60. _speakingView.layer.cornerRadius = 2.f;
  61. _speakingView.image = [UIImage imageNamed:@"speaking"];
  62. [self addSubview:_speakingView];
  63. }
  64. return _speakingView;
  65. }
  66. - (WFCUWaitingAnimationView *)stateLabel {
  67. if (!_stateLabel) {
  68. _stateLabel = [[WFCUWaitingAnimationView alloc] initWithFrame:self.bounds];
  69. _stateLabel.animationImages = @[[UIImage imageNamed:@"connect_ani1"],[UIImage imageNamed:@"connect_ani2"],[UIImage imageNamed:@"connect_ani3"]];
  70. _stateLabel.animationDuration = 1;
  71. _stateLabel.animationRepeatCount = 200;
  72. _stateLabel.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.7];
  73. _stateLabel.hidden = YES;
  74. [self addSubview:_stateLabel];
  75. }
  76. return _stateLabel;
  77. }
  78. - (void)dealloc {
  79. [[NSNotificationCenter defaultCenter] removeObserver:self];
  80. }
  81. @end
  82. #endif