Forráskód Böngészése

视频 manager兼容

liuzhenxing1118 7 hónapja
szülő
commit
04e5222237

+ 2 - 2
artimenring-iOS/Artimenring/Classes/Data/VideoManager+agora.h

@@ -16,10 +16,10 @@ NS_ASSUME_NONNULL_BEGIN
 - (void)termAgora;
 - (void)clearAgora;
 
-- (NSString*)getChannelName:(NSString*)sid ticket:(NSString*)ticket;
-
 - (void)joinChannel:(NSString*)token channelId:(NSString*)channelId uid:(NSUInteger)uid;
 
+- (void)switchCameraAgora;
+
 @end
 
 NS_ASSUME_NONNULL_END

+ 4 - 4
artimenring-iOS/Artimenring/Classes/Data/VideoManager+agora.m

@@ -23,10 +23,6 @@
     return YES;
 }
 
-- (NSString*)getChannelName:(NSString*)sid ticket:(NSString*)ticket {
-    return [NSString stringWithFormat:@"%@_%@", sid, ticket];
-}
-
 - (void)joinChannel:(NSString*)token channelId:(NSString*)channelId uid:(NSUInteger)uid {
     AgoraRtcChannelMediaOptions *options = [[AgoraRtcChannelMediaOptions alloc] init];
     // 自动订阅所有音频流
@@ -68,4 +64,8 @@
     [AgoraRtcEngineKit destroy];
 }
 
+- (void)switchCameraAgora {
+    [self.agoraKit switchCamera];
+}
+
 @end

+ 23 - 0
artimenring-iOS/Artimenring/Classes/Data/VideoManager+http.h

@@ -0,0 +1,23 @@
+//
+//  VideoManager+http.h
+//  SikeyComm
+//
+//  Created by 刘振兴 on 2025/2/18.
+//  Copyright © 2025 BaH Cy. All rights reserved.
+//
+
+#import "VideoManager.h"
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface VideoManager (http)
+
+- (void)requestVideo:(NSString*)uid ticket:(NSString*)ticket dial:(NSInteger)dial callback:(void(^)(BOOL isOK, NSString* token))callback;
+
+- (void)requestToken:(NSString*)uid ticket:(NSString*)ticket callback:(void(^)(BOOL isOK, NSString* token))callback;
+
+- (void)requestVideoEx:(NSString*)uid ticket:(NSString*)ticket token:(NSString*)token dial:(NSInteger)dial callback:(void(^)(BOOL isOK))callback;
+
+@end
+
+NS_ASSUME_NONNULL_END

+ 71 - 0
artimenring-iOS/Artimenring/Classes/Data/VideoManager+http.m

@@ -0,0 +1,71 @@
+//
+//  VideoManager+http.m
+//  SikeyComm
+//
+//  Created by 刘振兴 on 2025/2/18.
+//  Copyright © 2025 BaH Cy. All rights reserved.
+//
+
+#import "VideoManager+http.h"
+
+@implementation VideoManager (http)
+
+- (void)requestToken:(NSString*)uid ticket:(NSString*)ticket callback:(void(^)(BOOL isOK, NSString* token))callback {
+    HDNormalLog(([NSString stringWithFormat:@"VideoManager: requestToken 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)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 requestToken: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)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);
+    }];
+}
+
+@end

+ 4 - 0
artimenring-iOS/Artimenring/Classes/Data/VideoManager+juphoon.h

@@ -22,6 +22,10 @@ NS_ASSUME_NONNULL_BEGIN
 - (BOOL)call:(NSString*)uid ticket:(NSString*)ticket;
 - (void)termJuphoon;
 
+- (void)switchCameraJuphoon;
+- (void)muteJuphoon;
+- (void)speakerJuphoon;
+
 @end
 
 NS_ASSUME_NONNULL_END

+ 14 - 0
artimenring-iOS/Artimenring/Classes/Data/VideoManager+juphoon.m

@@ -73,6 +73,20 @@
     }
 }
 
+- (void)switchCameraJuphoon {
+    [self.mJuphoonMediaDevice switchCamera];
+}
+
+- (void)muteJuphoon {
+    JCCallItem *activeCall = [self getActiveCall];
+    [self.mJuphoonCall mute:activeCall];
+}
+
+- (void)speakerJuphoon {
+    BOOL isOn = self.mJuphoonMediaDevice.isSpeakerOn;
+    [self.mJuphoonMediaDevice enableSpeaker:!isOn];
+}
+
 #pragma mark - JCMediaDeviceCallback
 /**
  * 登录结果回调

+ 3 - 0
artimenring-iOS/Artimenring/Classes/Data/VideoManager.h

@@ -45,6 +45,8 @@ NS_ASSUME_NONNULL_BEGIN
 
 - (void)videoCallStart:(NSString*)uid ticket:(NSString*)ticket;
 - (void)videoEnd:(BOOL)isIncomming isSendMessage:(BOOL)isSendMessage;
+- (void)videoAnswer;
+- (void)switchCamera;
 
 - (void)actionFromSocket:(SocketModel*)model dial:(NSInteger)dial;
 - (void)termWithTimeout;
@@ -55,6 +57,7 @@ NS_ASSUME_NONNULL_BEGIN
 - (JCCallItem*)getActiveCall;
 - (NSString*)getTalkName;
 - (NSString*)getTalkHeadImageURL;
+- (NSString*)getChannelName:(NSString*)sid ticket:(NSString*)ticket;
 
 @end
 

+ 24 - 58
artimenring-iOS/Artimenring/Classes/Data/VideoManager.m

@@ -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

+ 6 - 15
artimenring-iOS/Artimenring/Classes/ViewController/Call/SKInCallViewController.m

@@ -80,35 +80,29 @@
     [[VideoManager shared] videoEnd:YES isSendMessage:YES];
 }
 
+- (IBAction)voiceAnswer:(id)sender {
+}
+
 - (IBAction)videoAnswer:(id)sender {
-    JCCallItem *activeCall = [[VideoManager shared] getActiveCall];
-    [[VideoManager shared].mJuphoonCall answer:activeCall video:true];
+    [[VideoManager shared] videoAnswer];
 }
 
 #pragma mark - In Calling Actions
 - (IBAction)setCameraState:(id)sender {
-    JCCallItem *activeCall = [[VideoManager shared] getActiveCall];
-    [[VideoManager shared].mJuphoonCall enableUploadVideoStream:activeCall];
+    
 }
 
 - (IBAction)addNewCall:(id)sender {
 }
 
 - (IBAction)switchCamera:(id)sender {
-    [[VideoManager shared].mJuphoonMediaDevice switchCamera];
+    [[VideoManager shared] switchCamera];
 }
 
 - (IBAction)hold:(id)sender {
-    JCCallItem *activeCall = [[VideoManager shared] getActiveCall];
-    [[VideoManager shared].mJuphoonCall hold:activeCall];
 }
 
 - (IBAction)mute:(id)sender {
-    JCCallItem *activeCall = [[VideoManager shared] getActiveCall];
-    [[VideoManager shared].mJuphoonCall mute:activeCall];
-}
-
-- (IBAction)voiceAnswer:(id)sender {
 }
 
 - (IBAction)audioRecord:(id)sender {
@@ -121,9 +115,6 @@
 }
 
 - (IBAction)speaker:(id)sender {
-    BOOL isOn = [VideoManager shared].mJuphoonMediaDevice.isSpeakerOn;
-    [[VideoManager shared].mJuphoonMediaDevice enableSpeaker:!isOn];
-    self.speakerBtn.selected = isOn;
 }
 
 - (IBAction)callStatistics:(id)sender {

+ 6 - 0
artimenring-iOS/SikeyComm.xcodeproj/project.pbxproj

@@ -180,6 +180,7 @@
 		E4010C2D2BEA3C4C00C0A23F /* video_end.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = E4010C2B2BEA3C4C00C0A23F /* video_end.mp3 */; };
 		E4010C2E2BEA3C4C00C0A23F /* video_start.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = E4010C2C2BEA3C4C00C0A23F /* video_start.mp3 */; };
 		E41849612B8C8CCB000C18DB /* SKAlarmClockTitleViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E41849602B8C8CCB000C18DB /* SKAlarmClockTitleViewController.m */; };
+		E418538B2D64745B00F9C739 /* VideoManager+http.m in Sources */ = {isa = PBXBuildFile; fileRef = E418538A2D64745B00F9C739 /* VideoManager+http.m */; };
 		E41ECB5C2CF95C6C00C4C36C /* SKMainViewController+location.m in Sources */ = {isa = PBXBuildFile; fileRef = E41ECB4C2CF95C6B00C4C36C /* SKMainViewController+location.m */; };
 		E41ECB5D2CF95C6C00C4C36C /* SKMainViewController+realpos.m in Sources */ = {isa = PBXBuildFile; fileRef = E41ECB4D2CF95C6B00C4C36C /* SKMainViewController+realpos.m */; };
 		E41ECB5E2CF95C6C00C4C36C /* SKMainViewController+banner.m in Sources */ = {isa = PBXBuildFile; fileRef = E41ECB4E2CF95C6B00C4C36C /* SKMainViewController+banner.m */; };
@@ -707,6 +708,8 @@
 		E4010C2C2BEA3C4C00C0A23F /* video_start.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = video_start.mp3; sourceTree = "<group>"; };
 		E418495F2B8C8CCA000C18DB /* SKAlarmClockTitleViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SKAlarmClockTitleViewController.h; sourceTree = "<group>"; };
 		E41849602B8C8CCB000C18DB /* SKAlarmClockTitleViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SKAlarmClockTitleViewController.m; sourceTree = "<group>"; };
+		E41853892D64745B00F9C739 /* VideoManager+http.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "VideoManager+http.h"; sourceTree = "<group>"; };
+		E418538A2D64745B00F9C739 /* VideoManager+http.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "VideoManager+http.m"; sourceTree = "<group>"; };
 		E41ECB4C2CF95C6B00C4C36C /* SKMainViewController+location.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "SKMainViewController+location.m"; sourceTree = "<group>"; };
 		E41ECB4D2CF95C6B00C4C36C /* SKMainViewController+realpos.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "SKMainViewController+realpos.m"; sourceTree = "<group>"; };
 		E41ECB4E2CF95C6B00C4C36C /* SKMainViewController+banner.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "SKMainViewController+banner.m"; sourceTree = "<group>"; };
@@ -2398,6 +2401,8 @@
 				E420015D2BAC1FDD000D26B2 /* VideoManager.m */,
 				E4499A962D5DDFEA00653B56 /* VideoManager+agora.h */,
 				E4499A942D5DDFEA00653B56 /* VideoManager+agora.m */,
+				E41853892D64745B00F9C739 /* VideoManager+http.h */,
+				E418538A2D64745B00F9C739 /* VideoManager+http.m */,
 				E4499A952D5DDFEA00653B56 /* VideoManager+juphoon.h */,
 				E4499A932D5DDFEA00653B56 /* VideoManager+juphoon.m */,
 				E4499A7E2D5B4DF000653B56 /* VideoManager+ringtone.h */,
@@ -3123,6 +3128,7 @@
 				E459F0932B6B3D16002571E3 /* SKSchoolTimeListCell.m in Sources */,
 				27FFF948202845AA006C9F75 /* PushAllMessageViewCell.m in Sources */,
 				E4E75FD62BA06FFE00236F73 /* MagicReportView.m in Sources */,
+				E418538B2D64745B00F9C739 /* VideoManager+http.m in Sources */,
 				E4B1121F2B9B213200F48C90 /* SKRelationViewController.m in Sources */,
 				E4499A832D5B4DF000653B56 /* VideoManager+timer.m in Sources */,
 				E459F0902B6B3D16002571E3 /* SKElectricityModeViewController.m in Sources */,