YOUPAILCVideoRequestVC.m 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. //
  2. // YOUPAILCVideoRequestVC.m
  3. // LiveChat
  4. //
  5. // Created by 张灿 on 2018/9/17.
  6. // Copyright © 2018年 caicai. All rights reserved.
  7. //
  8. #import "YOUPAILCVideoRequestVC.h"
  9. #import "YOUPAILCRequestView.h"
  10. @interface YOUPAILCVideoRequestVC ()<LCResquestViewDelegate>
  11. @property(nonatomic,strong)YOUPAILCRequestView* youpaiprequestView;
  12. @end
  13. @implementation YOUPAILCVideoRequestVC
  14. - (void)viewDidLoad{
  15. [super viewDidLoad];
  16. [self youpaifsetupResquestView];
  17. }
  18. - (void)youpaifsetupResquestView{
  19. self.youpaiprequestView = [[YOUPAILCRequestView alloc]initWithModel:self.youpaipvideoModel];
  20. self.youpaiprequestView.youpaipdelegate = self;
  21. [self.view addSubview:self.youpaiprequestView];
  22. }
  23. - (void)youpaifcloseRequestBtnClick{
  24. [self videoEnd:7];
  25. }
  26. - (void)youpaifcancelBtnClick{ //点击了取消按钮
  27. [self.youpaipsocketManager sendCancel];
  28. }
  29. //-(void)timeOver
  30. //{
  31. // [self videoEnd:3];
  32. //}
  33. - (void)requestSuccess{ //主叫连接成功
  34. self.youpaiprequestView.youpaipcancelBtn.hidden = NO;
  35. self.youpaiprequestView.youpaiptimeLabel.hidden = NO;
  36. self.youpaiprequestView.youpaipcloseBtn.hidden = YES;
  37. [self.youpaiprequestView youpaiftimePadding];
  38. NSDictionary* dictData = @{@"id":@11,
  39. @"data":@{
  40. @"roomid":self.youpaipvideoModel.youpaiproom_id,
  41. @"callTime":[LCTools getCurrentTimestamp]
  42. }
  43. };
  44. NSString* str = [dictData mj_JSONString];
  45. NSLog(@"mj_JSONString = %@",str);
  46. NIMCustomSystemNotificationSetting *set = [[NIMCustomSystemNotificationSetting alloc]init];
  47. set.shouldBeCounted = NO;
  48. NIMCustomSystemNotification* customSysNotification = [[NIMCustomSystemNotification alloc]initWithContent:str];
  49. customSysNotification.apnsPayload = @{
  50. @"sound":@"open.wav",
  51. @"callType":@"video"
  52. };
  53. customSysNotification.apnsContent = @"收到视频请求";
  54. customSysNotification.sendToOnlineUsersOnly = NO;
  55. customSysNotification.setting = set;
  56. [[NIMSDK sharedSDK].systemNotificationManager sendCustomNotification:customSysNotification toSession:[NIMSession session:self.youpaipvideoModel.youpaipto_uid type:(NIMSessionTypeP2P)] completion:^(NSError * _Nullable error) {
  57. }];
  58. }
  59. - (void)responseChoosing:(NSString*)tip{ //被叫连接成功
  60. self.youpaiprequestView.youpaiptipLabel.text = tip;
  61. }
  62. //add by leo 剩余可通话时间
  63. - (void)canCallTime:(NSString*)tip
  64. {
  65. dispatch_async(dispatch_get_main_queue(), ^{
  66. NSString *callTimeStr = [NSString stringWithFormat:@"剩余时长:%@",[ZCUtils getHHMMSSFromSS:tip.integerValue]];
  67. // NSLog(@"tip.integerValue is %ld\n",tip.integerValue);
  68. if(tip.integerValue <= 1) {
  69. //剩余时间不足 主动挂断
  70. NSLog(@"费用不足发送了一次挂断信息\n");
  71. [self.youpaipsocketManager sendHangup];
  72. }
  73. [self.youpaipcancallTimeLab setText:callTimeStr];
  74. });
  75. }
  76. // 已减免时长
  77. - (void)discountWithTime:(NSInteger)time{
  78. dispatch_async(dispatch_get_main_queue(), ^{
  79. if (time <= 0) {
  80. self.youpaipformDiscountBgV.hidden = YES;
  81. }else{
  82. self.youpaipformDiscountBgV.hidden = NO;
  83. self.youpaipformDiscountL.text = [NSString stringWithFormat:@" 已减免%@分钟 ",@(time)];
  84. }
  85. });
  86. }
  87. - (void)videoStart:(NSDictionary*)dict{ //视频开始
  88. [super videoStart:dict];
  89. [UMengRecordTool umengEventCountWithId:TurnOnTheVideo];
  90. self.view.backgroundColor = [UIColor blackColor];
  91. [self youpaifsetupInterView];
  92. if (self.youpaiprequestView.youpaiptimer) {
  93. dispatch_source_cancel(self.youpaiprequestView.youpaiptimer);//删除GCD定时器
  94. self.youpaiprequestView.youpaiptimer = nil;
  95. }
  96. [self.youpaiprequestView removeFromSuperview];
  97. }
  98. //1主动取消 2。拒绝 3.超时 4.被叫者挂断 5.主叫者挂断 6.费用不足
  99. - (void)videoEnd:(NSInteger)type{
  100. [super videoEnd:type];
  101. if (type==1) {
  102. [ZCHUDHelper showTitle:@"已取消"];
  103. }else if (type==2){
  104. [ZCHUDHelper showTitle:@"已拒绝"];
  105. }else if (type==3){
  106. [ZCHUDHelper showTitle:@"超时无应答"];
  107. }else if (type==4){
  108. [ZCHUDHelper showTitle:@"对方已挂断"];
  109. }else if (type==5){
  110. [ZCHUDHelper showTitle:@"通话已结束"];
  111. }else if (type==6){
  112. [ZCHUDHelper showTitle:@"费用不足已断开"];
  113. }else if (type==10){
  114. [ZCHUDHelper showTitle:@"检测到本次视频违规,请遵守平台相关规则" showtime:5];
  115. }else if (type==11){
  116. [ZCHUDHelper showTitle:@"检测到本次视频违规,请遵守平台相关规则" showtime:5];
  117. }
  118. }
  119. - (void)youpaifsetupInterView{
  120. [super youpaifsetupInterView];
  121. }
  122. @end