// // VideoManager+juphoon.m // SikeyComm // // Created by 刘振兴 on 2025/2/11. // Copyright © 2025 BaH Cy. All rights reserved. // #import "VideoManager+juphoon.h" #import "VideoManager+timer.h" @implementation VideoManager (juphoon) //初始化 - (BOOL)initJuphoon { self.mJuphoonClient = [JCClient create:APP_KEY_JUPHOON callback:self createParam:nil]; self.mJuphoonMediaDevice = [JCMediaDevice create:self.mJuphoonClient callback:self]; self.mJuphoonCall = [JCCall create:self.mJuphoonClient mediaDevice:self.mJuphoonMediaDevice callback:self]; self.mJuphoonCall.mediaConfig = [JCCallMediaConfig generateByMode:JCCallMediaConfigModeIOT]; self.mJuphoonMediaDevice.videoAngle = JCMediaDeviceVideoAngel0; [self.mJuphoonMediaDevice setCameraProperty:640 height:360 framerate:10]; //Zmf_VideoCaptureListenRotation(0, 0); //Zmf_VideoRenderListenRotation(0,0); return self.mJuphoonClient.state == JCClientStateIdle; } - (void)loginJuphoon { NSString* uid = [DataManager shared].loginModel.uid; NSString* password = @"123456"; JCClientLoginParam* loginParam = [[JCClientLoginParam alloc] init]; BOOL isOK = [self.mJuphoonClient login:uid password:password loginParam:loginParam]; HDNormalLog(([NSString stringWithFormat:@"VideoManager: login call: %d", isOK])); } - (void)logoutJuphoon { if (self.mJuphoonClient) { [self.mJuphoonClient logout]; } } - (BOOL)call:(NSString*)sid ticket:(NSString*)ticket { self.mSID = sid; self.mTicket = ticket; JCCallParam* callParam = [JCCallParam callParamWithExtraParam:@"" ticket:ticket]; return [self.mJuphoonCall call:ticket video:true callParam:callParam]; } #pragma mark - JCMediaDeviceCallback /** * 登录结果回调 * * 在调用 {@link JCClient#login:password:loginParam: login} 方法成功后会收到此回调 * * @param result 登录是否成功 * - true:登录成功 * - false:登录失败 * @param reason 登录失败原因,当 result 为 false 时该值有效。参见:@ref JCClientReason "错误原因" */ - (void)onLogin:(bool)result reason:(JCClientReason)reason { @weakify(self); HDNormalLog(([NSString stringWithFormat:@"VideoManager: login Result:%d Reason:%ld", result, reason])); if (result) {// 登录成功 } else if (reason == JCClientReasonAuth) {// 账号密码错误 } else { //如果没有成功// if (reason != JCClientReasonNone && reason != JCClientReasonStateCannotLogin) { dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [weak_self loginJuphoon]; }); } } } /** * 登出回调 * * 在调用 {@link JCClient#logout logout} 方法成功会收到此回调 * * @param reason 登出失败原因,参见:@ref JCClientReason "错误原因" */ - (void)onLogout:(JCClientReason)reason { HDNormalLog(@"VideoManager: onLogout"); } /** * 登录状态变化回调 * * 在用户的登录状态发生改变时会收到此回调,登录状态: * - @ref JCClientStateNotInit : 未初始化 * - @ref JCClientStateIdle : 未登录 * - @ref JCClientStateLogining : 登录中 * - @ref JCClientStateLogined : 登录成功 * - @ref JCClientStateLogouting : 登出中 * * @param state 当前状态值 * @param oldState 之前状态值 */ - (void)onClientStateChange:(JCClientState)state oldState:(JCClientState)oldState { if (state == JCClientStateIdle) { [self loginJuphoon]; } } #pragma mark - JCCallCallback /** * 新增通话回调 * * 当上层收到此回调时,可以根据 JCCallItem 对象获得该通话的所有信息及状态,从而更新该通话相关UI * * @param item JCCallItem 对象 */ - (void)onCallItemAdd:(JCCallItem* __nonnull)item { HDNormalLog(([NSString stringWithFormat:@"VideoManager: onCallItemAdd direction: %ld", (long)item.direction])); NSDictionary *dic = @{kCallIetmKey:item}; [[NSNotificationCenter defaultCenter] postNotificationName:kCallNotification object:nil userInfo:dic]; if (self.mJuphoonCall.callItems.count == 1) { [self showInCallVC]; } } /** * 移除通话回调 * * 当上层收到此回调时,可以根据 JCCallItem 对象获得该通话的所有信息及状态,从而更新该通话相关UI * * @param item JCCallItem 对象 * @param reason 通话结束原因,参见:@ref JCCallReason "通话结束原因" * @param description 通话结束原因的描述,只有被动挂断的时候,才会收到这个值,其他情况下则返回空字符串 */ - (void)onCallItemRemove:(JCCallItem *)item reason:(JCCallReason)reason description:(NSString *)description { HDNormalLog(([NSString stringWithFormat:@"VideoManager: onCallItemRemove reason:%ld", reason])); [[NSNotificationCenter defaultCenter] postNotificationName:kCallNotification object:nil]; [self removeInCallVC]; switch (reason) { case JCCallReasonNone: [EasyTextView showInfoText:[NSString stringWithFormat:NSLocalizedString(@"Video.Error.Hangup", nil)]]; break; case JCCallReasonNotFound: [EasyTextView showErrorText:[NSString stringWithFormat:NSLocalizedString(@"Video.Error.User.No", nil)]]; break; case JCCallReasonUserOffline: [EasyTextView showErrorText:[NSString stringWithFormat:NSLocalizedString(@"Video.Error.User.Offline", nil)]]; [self loginJuphoon]; break; case JCCallReasonNotLogin: [EasyTextView showErrorText:[NSString stringWithFormat:NSLocalizedString(@"Video.Error.User.Login", nil)]]; break; case JCCallReasonTimeOut: //[EasyTextView showErrorText:[NSString stringWithFormat:NSLocalizedString(@"Video.Error.Timeout", nil)]]; break; case JCCallReasonNetWork: [EasyTextView showErrorText:[NSString stringWithFormat:NSLocalizedString(@"Video.Error.Network", nil)]]; break; default: { break; } } } /** * 通话状态更新回调 * * 当上层收到此回调时,可以根据 JCCallItem 对象获得该通话的所有信息及状态,从而更新该通话相关UI * * @param item JCCallItem 对象 * @param changeParam JCCallChangeParam 更新标识对象 */ - (void)onCallItemUpdate:(JCCallItem* __nonnull)item changeParam:(JCCallChangeParam * __nullable)changeParam { // if (item.state == JCCallStateTalking && [self.mInCallVC getRemoteCanvas] == nil && item.uploadVideoStreamOther) { // [self stopTimeoutTimer]; // } [[NSNotificationCenter defaultCenter] postNotificationName:kCallNotification object:nil]; } @end