VideoManager+http.m 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //
  2. // VideoManager+http.m
  3. // SikeyComm
  4. //
  5. // Created by 刘振兴 on 2025/2/18.
  6. // Copyright © 2025 BaH Cy. All rights reserved.
  7. //
  8. #import "VideoManager+http.h"
  9. @implementation VideoManager (http)
  10. - (void)requestToken:(NSString*)uid ticket:(NSString*)ticket callback:(void(^)(BOOL isOK, NSString* token))callback {
  11. HDNormalLog(([NSString stringWithFormat:@"VideoManager: requestToken ticket:%@", ticket]));
  12. NSDictionary *param = @{
  13. @"channelName":[self getChannelName:uid ticket:ticket],
  14. };
  15. [ERequest httpRequest:param httpURL:URL_VIDEO_TOKEN httpMethod:@"GET" onSuccess:^(NSDictionary *result) {
  16. if ([ERequest isSuccessWithResult:result]) {
  17. callback(YES, result[@"data"][@"token"]);
  18. } else {
  19. [EasyTextView showErrorText:result[@"message"]];
  20. callback(NO, @"");
  21. }
  22. } onFailure:^(NSError *error) {
  23. [EasyTextView showErrorText:NSLocalizedString(@"Network.Error", nil)];
  24. callback(NO, @"");
  25. }];
  26. }
  27. - (void)requestVideo:(NSString*)uid ticket:(NSString*)ticket dial:(NSInteger)dial callback:(void(^)(BOOL isOK, NSString* token))callback {
  28. HDNormalLog(([NSString stringWithFormat:@"VideoManager: requestVideo ticket:%@ dial:%ld", ticket, dial]));
  29. if (dial > 0) {
  30. DeviceModel* model = [[DataManager shared] getDeviceWithTicket:ticket];
  31. if (model.videoType == VIDEO_TYPE_AGORA) {
  32. [self requestToken:uid ticket:ticket callback:^(BOOL isOK, NSString *token) {
  33. [self requestVideoEx:uid ticket:ticket token:token dial:dial callback:^(BOOL isOK) {
  34. callback(isOK, token);
  35. }];
  36. }];
  37. }
  38. } else {
  39. [self requestVideoEx:uid ticket:ticket token:@"" dial:dial callback:^(BOOL isOK) {
  40. callback(isOK, @"");
  41. }];
  42. }
  43. }
  44. - (void)requestVideoEx:(NSString*)uid ticket:(NSString*)ticket token:(NSString*)token dial:(NSInteger)dial callback:(void(^)(BOOL isOK))callback {
  45. HDNormalLog(([NSString stringWithFormat:@"VideoManager: requestVideoEx ticket:%@ dial:%ld token:%@", ticket, dial, token]));
  46. NSDictionary *param = @{
  47. @"sid":uid,
  48. @"roomId":ticket,
  49. @"token":token,
  50. @"dial":@(dial), //是否是拨号 -1 挂断 1 拨号
  51. };
  52. NSString* url = dial == 1? URL_VIDEO_DIAL : URL_VIDEO_HANGUP;
  53. [ERequest httpRequest:param httpURL:url httpMethod:@"GET" onSuccess:^(NSDictionary *result) {
  54. if ([ERequest isSuccessWithResult:result]) {
  55. callback(YES);
  56. } else {
  57. [EasyTextView showErrorText:result[@"message"]];
  58. callback(NO);
  59. }
  60. } onFailure:^(NSError *error) {
  61. [EasyTextView showErrorText:NSLocalizedString(@"Network.Error", nil)];
  62. callback(NO);
  63. }];
  64. }
  65. @end