12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- //
- // RCConnectionManager.m
- // MusicGradeExam
- //
- // Created by Kyle on 2020/7/10.
- // Copyright © 2020 DayaMusic. All rights reserved.
- //
- #import "RCConnectionManager.h"
- #import "RoomLoginHelper.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(^{
- [[RoomLoginHelper sharedInstance] joinRongRTCRoom];
- });
- }
- else if (isNeedJoin && !self.isConnected) {
- dispatch_main_async_safe(^{
- [MBProgressHUD ksShowMessage:@"IM未连接上"];
- });
- }
- }
- // 极端情况 IM稍后连上的
- - (void)setIsConnected:(BOOL)isConnected {
- _isConnected = isConnected;
- if (self.isNeedJoin && isConnected) {
- dispatch_main_async_safe(^{
- [[RoomLoginHelper sharedInstance] joinRongRTCRoom];
- });
- }
- }
- - (void)onRCIMConnectionStatusChanged:(RCConnectionStatus)status {
- if (status == ConnectionStatus_Connected) { // RTC会自动断线重连 此处多余
- self.isConnected = YES;
- NSLog(@"connect im success");
- }
- else if (status == ConnectionStatus_KICKED_OFFLINE_BY_OTHER_CLIENT) { // 账号被挤掉
-
- self.isNeedJoin = NO;
- self.isNeedShowMessage = NO;
- [[NSNotificationCenter defaultCenter] postNotificationName:@"otherLogin" object:nil];
- }
- else if (status == ConnectionStatus_Unconnected) {
- if (_isNeedShowMessage) {
- dispatch_main_async_safe(^{
- [MBProgressHUD ksShowMessage:@"连接断开,请检查您的网络"];
- });
- }
- }
-
- }
- @end
|