PublishLiveViewModel.m 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. //
  2. // PublishLiveViewModel.m
  3. // BuguLive
  4. //
  5. // Created by xfg on 2017/6/8.
  6. // Copyright © 2017年 xfg. All rights reserved.
  7. //
  8. #import "PublishLiveViewModel.h"
  9. @implementation PublishLiveViewModel
  10. + (void)beginLive:(NSMutableDictionary *)dict vc:(UIViewController *)vc block:(AppCommonBlock)block
  11. {
  12. [[LiveCenterAPIManager sharedInstance] liveCenterAPIOfShowHostLiveOfDic:dict block:^(NSDictionary *responseJson, BOOL finished, NSError *error) {
  13. if (finished && !error && responseJson)
  14. {
  15. if (block)
  16. {
  17. AppBlockModel *blockModel = [AppBlockModel manager];
  18. blockModel.retDict = responseJson;
  19. blockModel.status = 1;
  20. block(blockModel);
  21. }
  22. if (!vc)
  23. {
  24. [PublishLiveViewModel beginLiveCenter:responseJson];
  25. }
  26. else
  27. {
  28. UIViewController *rootVC = vc.presentingViewController;
  29. while (rootVC.presentingViewController)
  30. {
  31. rootVC = rootVC.presentingViewController;
  32. }
  33. [rootVC dismissViewControllerAnimated:YES completion:^{
  34. [PublishLiveViewModel beginLiveCenter:responseJson];
  35. }];
  36. }
  37. }
  38. else
  39. {
  40. if (block)
  41. {
  42. block([AppBlockModel manager]);
  43. }
  44. [FanweMessage alertHUD:[responseJson toString:@"error"]];
  45. // [PublishLiveViewModel closeLastLive];
  46. }
  47. }];
  48. }
  49. #pragma mark - 暂时使用,对于异常退出的直播,需要先关闭再开启,不然无法开播
  50. //+ (void)closeLastLive {
  51. // //直播结束
  52. // NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
  53. // [mDict setObject:@"video" forKey:@"ctl"];
  54. // [mDict setObject:@"end_video" forKey:@"act"];
  55. // [mDict setObject:@"11506" forKey:@"room_id"];
  56. //
  57. // [[NetHttpsManager manager] POSTWithParameters:mDict SuccessBlock:^(NSDictionary *responseJson) {
  58. // NSLog(@"%@",responseJson);
  59. // } FailureBlock:^(NSError *error) {
  60. // NSLog(@"%@",error.description);
  61. // }];
  62. //}
  63. + (void)beginLiveCenter:(NSDictionary *)dict
  64. {
  65. // 开启直播(先API拿直播后台类型) 非悬浮 非小屏幕
  66. BOOL isSusWindow = false;
  67. BOOL isSmallScreen = false;
  68. // 根据实际需求 设置
  69. // isSusWindow = [[GlobalVariables sharedInstance].appModel.open_pai_module intValue] == 1 ? YES : NO;
  70. isSusWindow = YES;
  71. [[LiveCenterManager sharedInstance] showLiveOfAPIResponseJson:dict.mutableCopy isSusWindow:isSusWindow isSmallScreen:isSmallScreen block:^(BOOL finished) {
  72. }];
  73. }
  74. + (void)beginVoiceLive:(NSMutableDictionary *)dict vc:(UIViewController *)vc block:(AppCommonBlock)block
  75. {
  76. [[LiveCenterAPIManager sharedInstance] liveCenterAPIOfShowHostLiveOfDic:dict block:^(NSDictionary *responseJson, BOOL finished, NSError *error) {
  77. NSMutableDictionary *tmpDic = [NSMutableDictionary dictionaryWithDictionary:responseJson];
  78. [tmpDic setObject:@"1" forKey:@"is_voice"];
  79. responseJson = tmpDic.mutableCopy;
  80. if (finished && !error && responseJson)
  81. {
  82. if (block)
  83. {
  84. AppBlockModel *blockModel = [AppBlockModel manager];
  85. blockModel.retDict = responseJson;
  86. blockModel.status = 1;
  87. block(blockModel);
  88. }
  89. if (!vc)
  90. {
  91. [PublishLiveViewModel beginLiveCenter:responseJson];
  92. }
  93. else
  94. {
  95. UIViewController *rootVC = vc.presentingViewController;
  96. while (rootVC.presentingViewController)
  97. {
  98. rootVC = rootVC.presentingViewController;
  99. }
  100. [rootVC dismissViewControllerAnimated:YES completion:^{
  101. [PublishLiveViewModel beginLiveCenter:responseJson];
  102. }];
  103. }
  104. }
  105. else
  106. {
  107. if (block)
  108. {
  109. block([AppBlockModel manager]);
  110. }
  111. [FanweMessage alertHUD:[responseJson toString:@"error"]];
  112. }
  113. }];
  114. }
  115. @end