initial commit

This commit is contained in:
Caleb
2026-03-01 15:59:27 +08:00
commit a9e97d56cb
1426 changed files with 172367 additions and 0 deletions

View File

@@ -0,0 +1,223 @@
//
// 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