Files
SellyCloudSDK_demo/Example/SellyCloudSDK/Controllers/Home/AVCallViewController.m
2026-03-01 15:59:27 +08:00

224 lines
8.0 KiB
Objective-C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//
// AVCallViewController.m
// AVDemo
//
#import "AVCallViewController.h"
#import "SellyVideoCallViewController.h"
#import "SellyVideoCallConferenceController.h"
#import "AVConfigManager.h"
#import <Masonry/Masonry.h>
@interface AVCallViewController () <UITextFieldDelegate>
@property (nonatomic, strong) UITextField *channelIdTextField;
@property (nonatomic, strong) UIButton *callButton;
@property (nonatomic, strong) UIButton *conferenceButton;
@property (nonatomic, strong) UIView *containerView;
@end
@implementation AVCallViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor systemBackgroundColor];
self.title = @"通话";
[self setupUI];
// 加载上次使用的频道ID优先使用单聊的如果没有则使用会议的
NSString *lastChannelId = [[AVConfigManager sharedManager] loadCallChannelId];
if (lastChannelId.length == 0) {
lastChannelId = [[AVConfigManager sharedManager] loadConferenceChannelId];
}
self.channelIdTextField.text = lastChannelId;
}
- (void)setupUI {
// 创建容器视图
self.containerView = [[UIView alloc] init];
[self.view addSubview:self.containerView];
// 创建频道ID标签
UILabel *titleLabel = [[UILabel alloc] init];
titleLabel.text = @"频道ID";
titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
titleLabel.textColor = [UIColor labelColor];
[self.containerView addSubview:titleLabel];
// 创建频道ID输入框
self.channelIdTextField = [[UITextField alloc] init];
self.channelIdTextField.placeholder = @"请输入频道ID";
self.channelIdTextField.borderStyle = UITextBorderStyleRoundedRect;
self.channelIdTextField.font = [UIFont systemFontOfSize:16];
self.channelIdTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
self.channelIdTextField.returnKeyType = UIReturnKeyDone;
self.channelIdTextField.delegate = self;
self.channelIdTextField.backgroundColor = [UIColor secondarySystemBackgroundColor];
[self.containerView addSubview:self.channelIdTextField];
// 创建音视频单聊按钮
self.callButton = [self createButtonWithTitle:@"音视频单聊"
icon:@"video"
action:@selector(callTapped)];
[self.containerView addSubview:self.callButton];
// 创建音视频会议按钮
self.conferenceButton = [self createButtonWithTitle:@"音视频会议"
icon:@"person.3"
action:@selector(conferenceTapped)];
[self.containerView addSubview:self.conferenceButton];
// 布局
[self.containerView mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.equalTo(self.view);
make.width.equalTo(@320);
}];
[titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.equalTo(self.containerView);
make.right.equalTo(self.containerView);
}];
[self.channelIdTextField mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(titleLabel.mas_bottom).offset(8);
make.left.right.equalTo(self.containerView);
make.height.equalTo(@44);
}];
[self.callButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.channelIdTextField.mas_bottom).offset(32);
make.left.right.equalTo(self.containerView);
make.height.equalTo(@100);
}];
[self.conferenceButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.callButton.mas_bottom).offset(16);
make.left.right.equalTo(self.containerView);
make.height.equalTo(@100);
make.bottom.equalTo(self.containerView);
}];
}
- (UIButton *)createButtonWithTitle:(NSString *)title icon:(NSString *)iconName action:(SEL)action {
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
button.backgroundColor = [UIColor systemBlueColor];
button.layer.cornerRadius = 12;
button.clipsToBounds = YES;
// 创建图标
UIImageView *iconView = [[UIImageView alloc] initWithImage:[UIImage systemImageNamed:iconName]];
iconView.tintColor = [UIColor whiteColor];
iconView.contentMode = UIViewContentModeScaleAspectFit;
// 创建标题
UILabel *titleLabel = [[UILabel alloc] init];
titleLabel.text = title;
titleLabel.textColor = [UIColor whiteColor];
titleLabel.font = [UIFont systemFontOfSize:18 weight:UIFontWeightSemibold];
titleLabel.textAlignment = NSTextAlignmentCenter;
[button addSubview:iconView];
[button addSubview:titleLabel];
[iconView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(button);
make.centerY.equalTo(button).offset(-15);
make.width.height.equalTo(@40);
}];
[titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(button);
make.top.equalTo(iconView.mas_bottom).offset(8);
make.left.greaterThanOrEqualTo(button).offset(8);
make.right.lessThanOrEqualTo(button).offset(-8);
}];
[button addTarget:self action:action forControlEvents:UIControlEventTouchUpInside];
return button;
}
#pragma mark - Button Actions
- (void)callTapped {
NSString *channelId = [self.channelIdTextField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
// 验证输入
if (channelId.length == 0) {
[self showErrorAlert:@"频道ID不能为空"];
return;
}
// 保存频道 ID
[[AVConfigManager sharedManager] saveCallChannelId:channelId];
// 创建并跳转到视频通话页面
SellyVideoCallViewController *vc = [[SellyVideoCallViewController alloc] init];
vc.channelId = channelId;
vc.videoConfig = SellyRTCVideoConfiguration.defaultConfig;
// 隐藏底部 TabBar
vc.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:vc animated:YES];
}
- (void)conferenceTapped {
NSString *channelId = [self.channelIdTextField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
// 验证输入
if (channelId.length == 0) {
[self showErrorAlert:@"频道ID不能为空"];
return;
}
// 保存频道 ID
[[AVConfigManager sharedManager] saveConferenceChannelId:channelId];
// 创建并跳转到视频会议页面
SellyVideoCallConferenceController *vc = [[SellyVideoCallConferenceController alloc] init];
vc.channelId = channelId;
vc.videoConfig = SellyRTCVideoConfiguration.defaultConfig;
// 隐藏底部 TabBar
vc.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:vc animated:YES];
}
#pragma mark - Helper Methods
- (void)showErrorAlert:(NSString *)message {
UIAlertController *errorAlert = [UIAlertController alertControllerWithTitle:@"错误"
message:message
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定"
style:UIAlertActionStyleDefault
handler:nil];
[errorAlert addAction:okAction];
[self presentViewController:errorAlert animated:YES completion:nil];
}
#pragma mark - UITextFieldDelegate
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return YES;
}
#pragma mark - Orientation Support (强制只支持竖屏)
- (BOOL)shouldAutorotate {
return YES;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationPortrait;
}
@end