1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- //
- // RCConnectionManager.m
- // StudentDaya
- //
- // Created by Kyle on 2019/9/10.
- // Copyright © 2019 DayaMusic. All rights reserved.
- //
- #import "RCConnectionManager.h"
- #import "LoginHelper.h"
- #import "ClassroomService.h"
- @interface RCConnectionManager ()
- @end
- @implementation RCConnectionManager
- + (instancetype)shareManager {
- static RCConnectionManager *manager = nil;
- static dispatch_once_t onceToken;
- dispatch_once(&onceToken, ^{
- manager = [[RCConnectionManager alloc] init];
- });
- return manager;
- }
- - (void)setIsNeedJoin:(BOOL)isNeedJoin {
- _isNeedJoin = isNeedJoin;
- if (self.isConnected && isNeedJoin) {
- dispatch_main_async_safe(^{
- [[LoginHelper sharedInstance] joinRongRTCRoom];
- });
- }
- else if (isNeedJoin && !self.isConnected) {
- dispatch_main_async_safe(^{
- NSString *tipsMessage = [NSString isEmptyString:UserDefault(RongTokenKey)] ? @"无IM token,请重新登录获取" : @"IM未能连接上,请检查您的网络";
- [MBProgressHUD ksShowMessage:tipsMessage];
- // 失败回调
- [[ClassroomService sharedService] joinRoomFailerNotify];
- });
- }
- }
- // 极端情况 IM稍后连上的 还没有进入房间
- - (void)setIsConnected:(BOOL)isConnected {
- _isConnected = isConnected;
- if (self.isNeedJoin && isConnected) {
- dispatch_main_async_safe(^{
- [[LoginHelper sharedInstance] joinRongRTCRoom];
- });
- }
- }
- - (void)onRCIMConnectionStatusChanged:(RCConnectionStatus)status {
- if (status == ConnectionStatus_Connected) { // RTC会自动断线重连 此处多余
- self.isConnected = YES;
- NSLog(@"connect im success");
- [[NSNotificationCenter defaultCenter] postNotificationName:@"RongIMConnected" object:nil];
- }
- else if (status == ConnectionStatus_KICKED_OFFLINE_BY_OTHER_CLIENT) { // 账号被挤掉
-
- self.isNeedJoin = NO;
- self.isNeedShowMessage = NO;
- [[RCIM sharedRCIM] logout];
- [[NSNotificationCenter defaultCenter] postNotificationName:@"otherLogin" object:nil];
- }
- else if (status == ConnectionStatus_Unconnected) {
- if (_isNeedShowMessage) {
- dispatch_main_async_safe(^{
- [MBProgressHUD ksShowMessage:@"连接断开,请检查您的网络"];
- });
- }
- }
- }
- @end
|