|
@@ -9,6 +9,7 @@
|
|
|
#import "VideoManager.h"
|
|
|
#import "VideoManager+juphoon.h"
|
|
|
#import "VideoManager+agora.h"
|
|
|
+#import "VideoManager+http.h"
|
|
|
#import "VideoManager+timer.h"
|
|
|
|
|
|
@implementation VideoManager
|
|
@@ -32,64 +33,6 @@
|
|
|
[self clearAgora];
|
|
|
}
|
|
|
|
|
|
-- (void)requestVideo:(NSString*)uid ticket:(NSString*)ticket dial:(NSInteger)dial callback:(void(^)(BOOL isOK, NSString* token))callback {
|
|
|
- HDNormalLog(([NSString stringWithFormat:@"VideoManager: requestVideo ticket:%@ dial:%ld", ticket, dial]));
|
|
|
- if (dial > 0) {
|
|
|
- DeviceModel* model = [[DataManager shared] getDeviceWithTicket:ticket];
|
|
|
- if (model.videoType == VIDEO_TYPE_AGORA) {
|
|
|
- [self requestAgoraToken:uid ticket:ticket callback:^(BOOL isOK, NSString *token) {
|
|
|
- [self requestVideoEx:uid ticket:ticket token:token dial:dial callback:^(BOOL isOK) {
|
|
|
- callback(isOK, token);
|
|
|
- }];
|
|
|
- }];
|
|
|
- }
|
|
|
- } else {
|
|
|
- [self requestVideoEx:uid ticket:ticket token:@"" dial:dial callback:^(BOOL isOK) {
|
|
|
- callback(isOK, @"");
|
|
|
- }];
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-- (void)requestAgoraToken:(NSString*)uid ticket:(NSString*)ticket callback:(void(^)(BOOL isOK, NSString* token))callback {
|
|
|
- HDNormalLog(([NSString stringWithFormat:@"VideoManager: requestAgoraToken ticket:%@", ticket]));
|
|
|
- NSDictionary *param = @{
|
|
|
- @"channelName":[self getChannelName:uid ticket:ticket],
|
|
|
- };
|
|
|
- [ERequest httpRequest:param httpURL:URL_VIDEO_TOKEN httpMethod:@"GET" onSuccess:^(NSDictionary *result) {
|
|
|
- if ([ERequest isSuccessWithResult:result]) {
|
|
|
- callback(YES, result[@"data"][@"token"]);
|
|
|
- } else {
|
|
|
- [EasyTextView showErrorText:result[@"message"]];
|
|
|
- callback(NO, @"");
|
|
|
- }
|
|
|
- } onFailure:^(NSError *error) {
|
|
|
- [EasyTextView showErrorText:NSLocalizedString(@"Network.Error", nil)];
|
|
|
- callback(NO, @"");
|
|
|
- }];
|
|
|
-}
|
|
|
-
|
|
|
-- (void)requestVideoEx:(NSString*)uid ticket:(NSString*)ticket token:(NSString*)token dial:(NSInteger)dial callback:(void(^)(BOOL isOK))callback {
|
|
|
- HDNormalLog(([NSString stringWithFormat:@"VideoManager: requestVideoEx ticket:%@ dial:%ld token:%@", ticket, dial, token]));
|
|
|
- NSDictionary *param = @{
|
|
|
- @"sid":uid,
|
|
|
- @"roomId":ticket,
|
|
|
- @"token":token,
|
|
|
- @"dial":@(dial), //是否是拨号 -1 挂断 1 拨号
|
|
|
- };
|
|
|
- NSString* url = dial == 1? URL_VIDEO_DIAL : URL_VIDEO_HANGUP;
|
|
|
- [ERequest httpRequest:param httpURL:url httpMethod:@"GET" onSuccess:^(NSDictionary *result) {
|
|
|
- if ([ERequest isSuccessWithResult:result]) {
|
|
|
- callback(YES);
|
|
|
- } else {
|
|
|
- [EasyTextView showErrorText:result[@"message"]];
|
|
|
- callback(NO);
|
|
|
- }
|
|
|
- } onFailure:^(NSError *error) {
|
|
|
- [EasyTextView showErrorText:NSLocalizedString(@"Network.Error", nil)];
|
|
|
- callback(NO);
|
|
|
- }];
|
|
|
-}
|
|
|
-
|
|
|
#pragma mark -
|
|
|
- (void)actionFromSocket:(SocketModel*)model dial:(NSInteger)dial {
|
|
|
if (dial <= 0) {
|
|
@@ -147,6 +90,16 @@
|
|
|
DeviceModel* model = [[DataManager shared]getDeviceWithTicket:self.mTicket];
|
|
|
if (model.videoType == VIDEO_TYPE_JUPHOON) {
|
|
|
[self loginJuphoon];
|
|
|
+ } else if (model.videoType == VIDEO_TYPE_AGORA) {
|
|
|
+ [self showInCallVC];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (void)videoAnswer {
|
|
|
+ DeviceModel* model = [[DataManager shared]getDeviceWithTicket:self.mTicket];
|
|
|
+ if (model.videoType == VIDEO_TYPE_JUPHOON) {
|
|
|
+ JCCallItem *activeCall = [self getActiveCall];
|
|
|
+ [self.mJuphoonCall answer:activeCall video:true];
|
|
|
} else if (model.videoType == VIDEO_TYPE_AGORA) {
|
|
|
[self joinChannel:self.mToken channelId:self.mChannelName uid:0];
|
|
|
}
|
|
@@ -176,6 +129,15 @@
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+- (void)switchCamera {
|
|
|
+ DeviceModel* model = [[DataManager shared] getDeviceWithTicket:self.mTicket];
|
|
|
+ if (model.videoType == VIDEO_TYPE_JUPHOON) {
|
|
|
+ [self switchCameraJuphoon];
|
|
|
+ } else if (model.videoType == VIDEO_TYPE_AGORA) {
|
|
|
+ [self switchCameraAgora];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
- (void)showInCallVC {
|
|
|
if (self.mInCallVC)
|
|
|
return;
|
|
@@ -225,4 +187,8 @@
|
|
|
return model ? model.avatar : @"";
|
|
|
}
|
|
|
|
|
|
+- (NSString*)getChannelName:(NSString*)sid ticket:(NSString*)ticket {
|
|
|
+ return [NSString stringWithFormat:@"%@_%@", sid, ticket];
|
|
|
+}
|
|
|
+
|
|
|
@end
|