123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- //
- // VideoManager.m
- // SikeyComm
- //
- // Created by 刘振兴 on 2024/3/21.
- // Copyright © 2024 BaH Cy. All rights reserved.
- //
- #import "VideoManager.h"
- #import "VideoManager+juphoon.h"
- #import "VideoManager+agora.h"
- #import "VideoManager+http.h"
- #import "VideoManager+timer.h"
- #import "VideoManager+view.h"
- @implementation VideoManager
- + (VideoManager *)shared {
- static VideoManager *manager;
- static dispatch_once_t token;
- dispatch_once(&token, ^{
- manager = [[VideoManager alloc] init];
- });
- return manager;
- }
- - (void)initManager {
- [self initJuphoon];
- [self initAgora];
- }
- - (void)clearManager {
- [self logoutJuphoon];
- [self clearAgora];
- [self clearValue];
- }
- - (void)clearValue {
- self.uid = @"";
- self.mTicket = @"";
- self.mToken = @"";
- self.roomId = @"";
- }
- - (void)videoCallIn {
- DeviceModel* model = [[DataManager shared]getDeviceWithTicket:self.mTicket];
- if (model.videoType == VIDEO_TYPE_JUPHOON) {
- [self loginJuphoon];
- } else if (model.videoType == VIDEO_TYPE_AGORA) {
- [self showInCallVC:model.videoType isCallIn:YES];
- }
- }
- - (void)videoCallOut:(NSString*)uid ticket:(NSString*)ticket {
- @weakify(self);
- BOOL isReachable = [[AFNetworkReachabilityManager sharedManager] isReachable];
- if (!isReachable) {
- [EasyTextView showErrorText:NSLocalizedString(@"Network.Error", nil)];
- return;
- }
- HDNormalLog(([NSString stringWithFormat:@"VideoManager: videoCallOut: uid:%@ ticket:%@", uid, ticket]));
- DeviceModel* model = [[DataManager shared] getDeviceWithTicket:ticket];
- if (!model)
- return;
- self.uid = uid;
- self.mTicket = ticket;
- self.roomId = model.videoType == VIDEO_TYPE_JUPHOON ? ticket : [self getRoomId:self.uid ticket:self.mTicket];
-
- if (model.videoType == VIDEO_TYPE_JUPHOON) {
- BOOL isok = [self call:uid ticket:ticket];
- if (!isok) {
- //如果失败,很有可能登录失败,重新登录//
- [self loginJuphoon];
- [EasyTextView showErrorText:[NSString stringWithFormat:NSLocalizedString(@"Video.Error.User.Login", nil)]];
- } else {
- [self requestVideo:uid ticket:ticket dial:1 callback:^(BOOL isOK, NSString *token) {
- }];
- [self startTimeoutTimer];
- }
- } else if (model.videoType == VIDEO_TYPE_AGORA) {
- [self requestVideo:uid ticket:ticket dial:1 callback:^(BOOL isOK, NSString *token) {
- if (isOK && token.length > 0) {
- self.mToken = token;
- [weak_self showInCallVC:model.videoType isCallIn:NO];
- [weak_self startTimeoutTimer];
- }
- }];
- }
- }
- - (void)videoAnswer {
- DeviceModel* model = [[DataManager shared]getDeviceWithTicket:self.mTicket];
- if (model.videoType == VIDEO_TYPE_JUPHOON) {
- [self answerJuphoon];
- } else if (model.videoType == VIDEO_TYPE_AGORA) {
- [self joinChannel:self.mToken channelId:self.roomId uid:0];
- }
- }
- - (void)termWithTimeout {
- [EasyTextView showErrorText:NSLocalizedString(@"Video.Error.Timeout", nil)];
- [self termWithSelf];
- }
- - (void)termWithSelf {
- [self stopTimeoutTimer];
- [self requestVideo:self.uid ticket:self.mTicket dial:-1 callback:^(BOOL isOK, NSString *token) {
- }];
- [self term];
- }
- - (void)termWithOther {
- [EasyTextView showInfoText:NSLocalizedString(@"Video.Error.Hangup", nil)];
- [self term];
- }
- //别人呼叫我,我拒接
- - (void)termWithRefuse {
- [self requestVideo:self.uid ticket:self.mTicket dial:-1 callback:^(BOOL isOK, NSString *token) {
- }];
- }
- - (void)term {
- DeviceModel* model = [[DataManager shared] getDeviceWithTicket:self.mTicket];
- if (model.videoType == VIDEO_TYPE_JUPHOON) {
- [self termJuphoon];
- [self removeInCallVC];
- } else if (model.videoType == VIDEO_TYPE_AGORA) {
- [self termAgora];
- [self removeInCallVC];
- }
- [self clearValue];
- }
- - (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];
- }
- }
- - (BOOL)isVideoTalking {
- return self.uid.length > 0 && self.mTicket.length > 0;
- }
- - (NSString*)getTalkName {
- NSString* talkId = self.mTicket;
- ChildModel* model = [[DataManager shared] getChildWithTicket:talkId];
- return model ? model.name : @"";
- }
- - (NSString*)getTalkHeadImageURL {
- NSString* talkId = self.mTicket;
- ChildModel* model = [[DataManager shared] getChildWithTicket:talkId];
- return model ? model.avatar : @"";
- }
- - (NSString*)getRoomId:(NSString*)sid ticket:(NSString*)ticket {
- return [NSString stringWithFormat:@"%@_%@_%@", sid, ticket, EUtil.getCurrentTimeMS];
- }
- @end
|