fix
This commit is contained in:
@@ -13,71 +13,131 @@
|
||||
#import "GiGaCommentModel.h"
|
||||
#import "LXDanMuManagerConfig.h"
|
||||
#import "IQKeyboardManager.h"
|
||||
#import <SocketIO/SocketIO-Swift.h>
|
||||
#import "NSString+Unicode.h"
|
||||
|
||||
//弹幕控制器
|
||||
@interface GiGaFlingCommitVC ()
|
||||
@property (nonatomic,strong) GiGaFlyingCommitInputView *commitInputView;
|
||||
@property (nonatomic,strong) SocketIOClient *client;
|
||||
@property (nonatomic,strong) SocketManager *manager;
|
||||
|
||||
|
||||
@end
|
||||
|
||||
@implementation GiGaFlingCommitVC
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
// Do any additional setup after loading the view.
|
||||
NC_ADD_TARGET_NAME_OBJECT(self, @selector(maskTimeEnd), kUserNoti_MASKEND, nil);
|
||||
[self.view addSubview: self.commitInputView];
|
||||
self.commitInputView.SendCommentHandler = ^(NSString *content) {
|
||||
GILog(@"发送->:%@",content);
|
||||
};
|
||||
[[LXDanMuManager shareInstance] createDanmuWithTrackSpeedArray:@[@1.00,@1.00,@3.00,@4.00] centerY:self.view.frame.size.height / 4 trackWidth:self.view.frame.size.width showInView:self.view];
|
||||
[[LXDanMuManager shareInstance] start];
|
||||
|
||||
[NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(danmuAction) userInfo:nil repeats:YES];
|
||||
|
||||
|
||||
}
|
||||
|
||||
-(void)danmuAction{
|
||||
|
||||
[self showFlyingCommit];
|
||||
}
|
||||
|
||||
- (GiGaFlyingCommitInputView *)commitInputView{
|
||||
|
||||
if (!_commitInputView) {
|
||||
// _commitInputView = [[GiGaFlyingCommitInputView alloc] initWithFrame:CGRectMake(0,self.view.frame.size.height - 60 , KMainW, 60)];
|
||||
_commitInputView = [[GiGaFlyingCommitInputView alloc] initWithFrame:self.view.bounds];
|
||||
[_commitInputView setPalceholderText:@"请输入弹幕"];
|
||||
}
|
||||
return _commitInputView;
|
||||
}
|
||||
-(void)viewWillAppear:(BOOL)animated{
|
||||
[super viewWillAppear:animated];
|
||||
NC_ADD_TARGET_NAME_OBJECT(self, @selector(maskTimeEnd), kUserNoti_MASKEND, nil);
|
||||
[IQKeyboardManager sharedManager].enable = NO;
|
||||
[[IQKeyboardManager sharedManager] setEnableAutoToolbar:NO];
|
||||
}
|
||||
|
||||
- (void)viewWillDisappear:(BOOL)animated{
|
||||
[super viewWillDisappear:animated];
|
||||
NC_REMOVE_NAME(self, kUserNoti_MASKEND, nil);
|
||||
[IQKeyboardManager sharedManager].enable = YES;
|
||||
[[IQKeyboardManager sharedManager] setEnableAutoToolbar:YES];
|
||||
}
|
||||
|
||||
-(void)showFlyingCommit{
|
||||
NSArray *classArray = @[@"GiGaCommentView",@"GiGaCommentView"];
|
||||
NSArray *nameArray = @[@"mc子龙",@"小明",@"赵四",@"狂小狗",@"葬爱"];
|
||||
NSArray *msgArray = @[@"老铁666",@"主播,多少礼物给卡黄啊?",@"文明观球,大家有秩序排队观看,不要着急",@"主播,我报警啦",@"就是个萨比,还扮滴酷酷滴aaaaa"];
|
||||
NSArray *avatarArray = @[@"home_login_qq_color",@"home_login_qq_color",@"home_login_qq_color",@"home_login_qq_color",@"home_login_qq_color"];
|
||||
int classRandomIndex = arc4random() % 2;
|
||||
int nameRandomIndex = arc4random() % 5;
|
||||
int msgRandomIndex = arc4random() % 5;
|
||||
int avatarRandomIndex = arc4random() % 5;
|
||||
- (void)viewDidLoad {
|
||||
|
||||
GiGaCommentModel *model = [[GiGaCommentModel alloc]init];
|
||||
model.userName = nameArray[nameRandomIndex];
|
||||
model.msg = msgArray[msgRandomIndex];
|
||||
model.userAvatar = avatarArray[avatarRandomIndex];
|
||||
[super viewDidLoad];
|
||||
|
||||
// Do any additional setup after loading the view.
|
||||
[self.view addSubview: self.commitInputView];
|
||||
weakify(self);
|
||||
|
||||
self.commitInputView.SendCommentHandler = ^(NSString *content) {
|
||||
GILog(@"发送->:%@",content);
|
||||
NSArray *arr = @[@{
|
||||
@"content":content,
|
||||
@"room":@"",
|
||||
@"sendUserName":@"lianxiang"
|
||||
}];
|
||||
|
||||
[weakSelf.client emit:@"talk" with:arr];
|
||||
|
||||
};
|
||||
|
||||
//开启弹幕
|
||||
|
||||
[[LXDanMuManager shareInstance] createDanmuWithTrackSpeedArray:@[@1.00,@1.00,@3.00,@4.00] centerY:KMainH / 4 trackWidth:KMainW showInView:self.view];
|
||||
[[LXDanMuManager shareInstance] start];
|
||||
//socket
|
||||
[self connetction];
|
||||
|
||||
}
|
||||
|
||||
-(void)connetction{
|
||||
|
||||
NSURL* url = [[NSURL alloc] initWithString:@"http://wsyts.s1.natapp.cc"];
|
||||
// NSDictionary* headers = @{@"EncodeUTF8":@YES};
|
||||
SocketManager *manager = [[SocketManager alloc] initWithSocketURL:url config:@{@"log": @NO, @"forcePolling": @YES,@"connectParams":@{@"token":@""},@"doubleEncodeUTF8":@YES}];
|
||||
|
||||
|
||||
_manager = manager;
|
||||
_client = manager.defaultSocket;
|
||||
|
||||
[self.manager connect];
|
||||
weakify(self);
|
||||
[self.client on:@"connect" callback:^(NSArray* data, SocketAckEmitter* ack) {
|
||||
NSLog(@"*************\n\niOS客户端上线\n\n*************");
|
||||
}];
|
||||
|
||||
[self.client on:@"connectedSocket" callback:^(NSArray * _Nonnull event, SocketAckEmitter * _Nonnull ack) {
|
||||
NSLog(@"connectedSocket:%@",event);
|
||||
}];
|
||||
|
||||
[self.client on:@"onTalk" callback:^(NSArray * _Nonnull envent, SocketAckEmitter * _Nonnull ack) {
|
||||
|
||||
NSString *json =envent[0];
|
||||
NSLog(@"callback json***:%@",json);
|
||||
NSDictionary *dic = [GiGaHelper dictionaryWithJsonString:json];
|
||||
|
||||
if (dic == nil) {
|
||||
NSLog(@"解析失败");
|
||||
}else{
|
||||
GiGaCommentModel *commentModel = [[GiGaCommentModel alloc] initWithDictionary:dic error:nil];
|
||||
GILog(@"接收->:%@",[dic[@"content"] replaceUnicode:dic[@"content"]]);
|
||||
[weakSelf showDanMuWith:commentModel];
|
||||
}
|
||||
}];
|
||||
|
||||
[self.client on:@"disconnect" callback:^(NSArray * _Nonnull event, SocketAckEmitter * _Nonnull ack) {
|
||||
NSLog(@"*************\n\niOS客户端下线\n\n*************%@",event?event[0]:@"");
|
||||
}];
|
||||
|
||||
[self.client on:@"error" callback:^(NSArray * _Nonnull event, SocketAckEmitter * _Nonnull ack) {
|
||||
// NSString *htmlString =event[0];
|
||||
// htmlString = [self htmlEntityDecode:htmlString];
|
||||
//
|
||||
// UIWebView * webView = [[UIWebView alloc]initWithFrame:CGRectMake(20, 300, self.view.frame.size.width - 40, 400)];
|
||||
// [webView loadHTMLString:htmlString baseURL:nil];
|
||||
// [self.view addSubview:webView];
|
||||
//
|
||||
// NSLog(@"*************\n\n%@\n\n*************",event?event[0]:@"");
|
||||
GILog(@"请求超时");
|
||||
|
||||
}];
|
||||
}
|
||||
|
||||
- (GiGaFlyingCommitInputView *)commitInputView{
|
||||
|
||||
if (!_commitInputView) {
|
||||
_commitInputView = [[GiGaFlyingCommitInputView alloc] initWithFrame:self.view.bounds];
|
||||
[_commitInputView setPalceholderText:@"请输入弹幕"];
|
||||
}
|
||||
return _commitInputView;
|
||||
}
|
||||
|
||||
|
||||
//弹幕插入
|
||||
-(void)showDanMuWith:(GiGaCommentModel *)model{
|
||||
|
||||
NSArray *classArray = @[@"GiGaCommentView",@"GiGaCommentView"];
|
||||
int classRandomIndex = arc4random() % 2;
|
||||
GiGaCommentView *customView = [[NSClassFromString(classArray[classRandomIndex]) alloc] initWithMsgModel:model height:TRACK_HEIGHT];
|
||||
[[LXDanMuManager shareInstance] appendDanMuWithCustomView:customView toTrackIndex:-1];
|
||||
}
|
||||
@@ -90,11 +150,19 @@
|
||||
|
||||
- (void)didReceiveMemoryWarning {
|
||||
[super didReceiveMemoryWarning];
|
||||
// Dispose of any resources that can be recreated.
|
||||
}
|
||||
|
||||
-(void)dealloc{
|
||||
NC_REMOVE_NAME(self, kUserNoti_MASKEND, nil);
|
||||
NSLog(@"dealloc");
|
||||
}
|
||||
|
||||
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
|
||||
[self.manager disconnectSocket:self.client];
|
||||
[self.manager disconnect];
|
||||
[self.client disconnect];
|
||||
self.client = nil;
|
||||
self.manager = nil;
|
||||
[self dismissViewControllerAnimated:YES completion:nil];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user