...
|
...
|
@@ -100,7 +100,6 @@ |
|
|
@property (nonatomic, assign) BOOL loading;
|
|
|
|
|
|
@property (nonatomic, strong) GCDAsyncSocket *socket;
|
|
|
@property (nonatomic, assign) NSInteger currentRetryCount;
|
|
|
@property (nonatomic, strong) NSTimer *socketTimer;
|
|
|
@property (nonatomic, assign) BOOL inPushing;//是否正在直播,直播中无法切换房间以及开始新的频道直播。
|
|
|
|
...
|
...
|
@@ -173,32 +172,42 @@ |
|
|
[self initUI];
|
|
|
[self loadChannelData];
|
|
|
[self setUpPush];
|
|
|
_currentRetryCount = 0;
|
|
|
DLog(@"=====%@",[TXLivePush getSDKVersion]);
|
|
|
}
|
|
|
|
|
|
- (void)continueRTMP {
|
|
|
if (_currentChannel) {
|
|
|
if ([self startRtmp]) {
|
|
|
[self toastTip:@"开始直播"];
|
|
|
_switchLock = NO;
|
|
|
_totalTime = _currentChannel.totalTime.integerValue;
|
|
|
_timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(updateInfoView) userInfo:nil repeats:YES];
|
|
|
[_timer fire];
|
|
|
_liveButton.selected = YES;
|
|
|
|
|
|
[self clearLog];
|
|
|
|
|
|
self.socketService.room = _currentChannel.room;
|
|
|
self.socketService.uid = @"";
|
|
|
self.socketService.userName = @"";
|
|
|
[self.socketService connect];
|
|
|
[[YH_NetworkAdapter adapter] setStatusWithStat:PushStatusStart andRoomId:_currentChannel.room completion:^(BOOL flag, NSError *error) {
|
|
|
|
|
|
if (error) {
|
|
|
[self toastTip:[NSString stringWithFormat:@"开始失败,原因:%@",error.localizedDescription]];
|
|
|
[[NSUserDefaults standardUserDefaults] removeObjectForKey:kPushging];
|
|
|
}else {
|
|
|
if ([self startRtmp]) {
|
|
|
[self toastTip:@"开始直播"];
|
|
|
_switchLock = NO;
|
|
|
_totalTime = _currentChannel.totalTime.integerValue;
|
|
|
_timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(updateInfoView) userInfo:nil repeats:YES];
|
|
|
[_timer fire];
|
|
|
_liveButton.selected = YES;
|
|
|
|
|
|
[self clearLog];
|
|
|
|
|
|
self.socketService.room = _currentChannel.room;
|
|
|
self.socketService.uid = @"";
|
|
|
self.socketService.userName = @"";
|
|
|
[self.socketService connect];
|
|
|
|
|
|
_switchLock=NO;
|
|
|
} else {
|
|
|
[self toastTip:@"直播开始失败"];
|
|
|
[[NSUserDefaults standardUserDefaults] removeObjectForKey:kPushging];
|
|
|
}
|
|
|
}
|
|
|
[_liveButton addTarget:self action:@selector(liveButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
[_liveButton setTitle:@"开始直播" forState:UIControlStateNormal];
|
|
|
[_liveButton setTitle:@"结束直播" forState:UIControlStateSelected];
|
|
|
_switchLock=NO;
|
|
|
}
|
|
|
}];
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
@@ -256,52 +265,6 @@ |
|
|
}
|
|
|
}
|
|
|
}];
|
|
|
// AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
|
|
|
// manager.responseSerializer.acceptableContentTypes = [manager.responseSerializer.acceptableContentTypes setByAddingObject:@"text/html"];
|
|
|
// NSURLSessionDataTask *task= [manager
|
|
|
// GET:[NSString stringWithFormat:@"%@%@", API_BASE_URL_STRING, @"qcloud/getPushFlow"]
|
|
|
// parameters:nil progress:NULL
|
|
|
// success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
|
|
|
// if ([responseObject isKindOfClass:[NSDictionary class]]) {
|
|
|
// id data = responseObject[@"data"];
|
|
|
// if (![data isKindOfClass:[NSArray class]]) {
|
|
|
// [self toastTip:@"没有可用直播间"];
|
|
|
// return;
|
|
|
// }
|
|
|
// NSMutableArray *tempAry = @[].mutableCopy;
|
|
|
// [data enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
|
|
// if (![obj isKindOfClass:[NSDictionary class]]) {
|
|
|
// *stop = YES;
|
|
|
// [self toastTip:@"没有可用直播间"];
|
|
|
// }
|
|
|
// YH_ChannelModel *model = [YH_ChannelModel new];
|
|
|
// model.roomTitle = obj[@"name"];
|
|
|
// model.roomURL = obj[@"url"];
|
|
|
// model.channel_id = obj[@"channel_id"];
|
|
|
// model.cid = obj[@"cid"];
|
|
|
// model.app = obj[@"app"];
|
|
|
// model.type = obj[@"type"];
|
|
|
// model.room = obj[@"id"];
|
|
|
// model.title = obj[@"title"];
|
|
|
// [tempAry addObject:model];
|
|
|
// if (_currentChannel&&[_currentChannel.roomURL isEqualToString:model.roomURL]) {
|
|
|
// _currentChannelIndex = idx;
|
|
|
// }
|
|
|
// }];
|
|
|
// _channels = [NSArray arrayWithArray:tempAry];
|
|
|
// [_channelTable reloadData];
|
|
|
// _currentChannelIndex = -1;
|
|
|
// }
|
|
|
// NSLog(@"bbbb%@",responseObject);
|
|
|
// _loading = NO;
|
|
|
// }
|
|
|
// failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
|
|
|
// _loading = NO;
|
|
|
// [self toastTip:[NSString stringWithFormat:@"房间加载失败:%@",error.localizedDescription]];
|
|
|
// }];
|
|
|
//
|
|
|
// NSLog(@"%@",task.originalRequest.URL.absoluteString);
|
|
|
|
|
|
|
|
|
}
|
|
|
|
...
|
...
|
@@ -508,13 +471,12 @@ |
|
|
@"videoLen":_timeLabel.text,
|
|
|
@"uid":@""
|
|
|
};
|
|
|
[_socket writeDataWithParams:params tag:2];
|
|
|
[_socket writeDataWithParams:params tag:3];
|
|
|
} else {
|
|
|
[self connectSocket];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
- (void)connectSocket {
|
|
|
if (_socket) {
|
|
|
[_socket disconnect];
|
...
|
...
|
@@ -527,20 +489,8 @@ |
|
|
|
|
|
- (void)socket:(GCDAsyncSocket *)sock didConnectToHost:(NSString *)host port:(uint16_t)port
|
|
|
{
|
|
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
_currentRetryCount = 0;
|
|
|
DLog(@"socket connect success!");
|
|
|
NSDictionary *params = @{@"cmd":@(1),
|
|
|
@"uid":@"",
|
|
|
@"room":_currentChannel.room?:@"666",
|
|
|
@"name":@"",
|
|
|
@"avatar":@""
|
|
|
};
|
|
|
|
|
|
[_socket writeDataWithParams:params tag:1];
|
|
|
});
|
|
|
|
|
|
DLog(@"my socket connected....");
|
|
|
[self socketSendEndNotify];
|
|
|
}
|
|
|
|
|
|
- (void)socketDidDisconnect:(GCDAsyncSocket *)sock withError:(NSError *)err{
|
...
|
...
|
@@ -555,11 +505,15 @@ |
|
|
- (void)socket:(GCDAsyncSocket *)sock didWriteDataWithTag:(long)tag
|
|
|
{
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
if (tag == 1) {//登录成功了之后才继续后面的。。。。
|
|
|
[self socketSendEndNotify];
|
|
|
if(_socketTimer == nil){
|
|
|
_socketTimer = [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(socketSendEndNotify) userInfo:nil repeats:YES];
|
|
|
}
|
|
|
if (tag == 1) {
|
|
|
NSDictionary *params = @{@"cmd":@(1),
|
|
|
@"uid":@"",
|
|
|
@"room":_currentChannel.room?:@"666",
|
|
|
@"name":@"",
|
|
|
@"avatar":@""
|
|
|
};
|
|
|
|
|
|
[_socket writeDataWithParams:params tag:2];
|
|
|
}
|
|
|
});
|
|
|
}
|
...
|
...
|
@@ -589,28 +543,6 @@ |
|
|
[[YH_NetworkAdapter adapter] setStatusWithStat:PushStatusEnd andRoomId:_currentChannel.room completion:^(BOOL flag, NSError *error) {
|
|
|
|
|
|
}];
|
|
|
|
|
|
// AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
|
|
|
// manager.responseSerializer.acceptableContentTypes = [manager.responseSerializer.acceptableContentTypes setByAddingObject:@"text/html"];
|
|
|
// manager.requestSerializer = [YH_HTTPRequestSerializer new];
|
|
|
//
|
|
|
// NSLog(@"%@----%@",_currentChannel.room,_currentChannel.cid);
|
|
|
//
|
|
|
// NSString *temp=[NSString stringWithFormat:@"%@yohocms",_currentChannel.room?:@"0"];
|
|
|
// NSString *md5 = [self md5:temp];
|
|
|
//
|
|
|
// NSURLSessionDataTask *task = [manager
|
|
|
// GET:[NSString stringWithFormat:@"%@%@",API_BASE_URL_STRING,@"qcloud/closeLive"]
|
|
|
// parameters:@{@"cid":_currentChannel.room?:@"0",@"secret":md5}
|
|
|
// progress:NULL
|
|
|
// success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
|
|
|
// NSLog(@"bbbb%@",responseObject);
|
|
|
// [self toastTip:responseObject[@"message"]];
|
|
|
// }
|
|
|
// failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
|
|
|
// NSLog(@"error:%@",error.localizedDescription);
|
|
|
// }];
|
|
|
// NSLog(@"%@",task.originalRequest.URL.absoluteString);
|
|
|
[_socketService logout];
|
|
|
_socketService=nil;
|
|
|
});
|
...
|
...
|
@@ -746,49 +678,6 @@ |
|
|
alert.tag = ValidateAlertTag;
|
|
|
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
|
|
|
[alert show];
|
|
|
// AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
|
|
|
// manager.responseSerializer.acceptableContentTypes = [manager.responseSerializer.acceptableContentTypes setByAddingObject:@"text/html"];
|
|
|
// manager.requestSerializer = [YH_HTTPRequestSerializer new];
|
|
|
// NSString *temp=[NSString stringWithFormat:@"%@yohocms",_currentChannel.room?:@"0"];
|
|
|
// NSString *md5 = [self md5:temp];
|
|
|
// NSURLSessionDataTask *task = [manager
|
|
|
// GET:[NSString stringWithFormat:@"%@%@",API_BASE_URL_STRING,@"qcloud/startLive"]
|
|
|
// parameters:@{@"cid":_currentChannel.room?:@"0",@"secret":md5}
|
|
|
// progress:NULL
|
|
|
// success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
|
|
|
// if ([responseObject[@"status"] isEqualToString:@"0"]) {
|
|
|
// if ([self startRtmp]) {
|
|
|
// [self toastTip:@"开始直播"];
|
|
|
//
|
|
|
//
|
|
|
// _totalTime = 0;
|
|
|
// _timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(updateInfoView) userInfo:nil repeats:YES];
|
|
|
// [_timer fire];
|
|
|
// _liveButton.selected = !_liveButton.selected;
|
|
|
//
|
|
|
// [self clearLog];
|
|
|
//
|
|
|
// self.socketService.room = _currentChannel.room;
|
|
|
// self.socketService.uid = @"";
|
|
|
// self.socketService.userName = @"";
|
|
|
// [self.socketService connect];
|
|
|
//
|
|
|
// }else {
|
|
|
// [self toastTip:@"直播开始失败"];
|
|
|
// }
|
|
|
//
|
|
|
// }else {
|
|
|
// [self toastTip:responseObject[@"message"]];
|
|
|
// }
|
|
|
//
|
|
|
// NSLog(@"bbbb%@",responseObject);
|
|
|
// }
|
|
|
// failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
|
|
|
// NSLog(@"ccc");
|
|
|
// [self toastTip:[NSString stringWithFormat:@"开始失败,原因:%@",error.localizedDescription]];
|
|
|
// }];
|
|
|
//
|
|
|
// NSLog(@"%@",task.originalRequest.URL.absoluteString);
|
|
|
|
|
|
} else {
|
|
|
|
...
|
...
|
@@ -827,11 +716,6 @@ |
|
|
|
|
|
[self clearLog];
|
|
|
|
|
|
self.socketService.room = _currentChannel.room;
|
|
|
self.socketService.uid = @"";
|
|
|
self.socketService.userName = @"";
|
|
|
[self.socketService connect];
|
|
|
|
|
|
}else {
|
|
|
[self toastTip:@"直播开始失败"];
|
|
|
}
|
...
|
...
|
|