Skip to content

Commit 4c1f61b

Browse files
ccharlesrenoldcodefarmer
authored andcommitted
将SDKDemo 中 RTC 功能与App 的进行对齐
Change-Id: Iadd3aa87347030a48f8182b632defbf1b8d84b3f
1 parent d6771d0 commit 4c1f61b

File tree

8 files changed

+568
-135
lines changed

8 files changed

+568
-135
lines changed

Source/LinkApp/Classes/Universal/WebSocket/TIoTTRTCUIManage.m

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
#import "TIoTTRTCUIManage.h"
88
#import "TIoTCoreUtil.h"
99
#import "TIoTTRTCSessionManager.h"
10+
#import "HXYNotice.h"
11+
#import "TIoTCoreUserManage.h"
12+
//#import "TIoTRequestObject.h"
13+
#import "YYModel.h"
14+
#import "NSString+Extension.h"
15+
#import "TIoTCoreRequestObject.h"
1016

1117
@interface TIoTTRTCUIManage ()<TRTCCallingViewDelegate> {
1218
TRTCCallingAuidoViewController *_callAudioVC;
@@ -223,7 +229,7 @@ - (void)didAcceptJoinRoom {
223229
//开始准备进房间,通话中状态
224230
NSDictionary *param = @{@"DeviceId":_deviceParam.deviceName};
225231

226-
[[TIoTRequestObject shared] post:AppIotRTCCallDevice Param:param success:^(id responseObject) {
232+
[[TIoTCoreRequestObject shared] post:AppIotRTCCallDevice Param:param success:^(id responseObject) {
227233

228234
NSDictionary *tempDic = responseObject[@"TRTCParams"];
229235
TIOTTRTCModel *model = [TIOTTRTCModel yy_modelWithJSON:tempDic];
@@ -310,7 +316,7 @@ - (void)refuseOtherCallWithDeviceReport:(NSDictionary *)reportDic deviceID:(NSSt
310316
@"DeviceName":[deviceID?:@"" componentsSeparatedByString:@"/"].lastObject?:@"",
311317
@"Data":[NSString objectToJson:trtcReport]?:@""};
312318

313-
[[TIoTRequestObject shared] post:AppControlDeviceData Param:tmpDic success:^(id responseObject) {
319+
[[TIoTCoreRequestObject shared] post:AppControlDeviceData Param:tmpDic success:^(id responseObject) {
314320
NSLog(@"--!!!--%@",responseObject);
315321
} failure:^(NSString *reason, NSError *error,NSDictionary *dic) {
316322

@@ -330,7 +336,7 @@ - (void)repeatDeviceData:(NSArray *)devices{
330336

331337
NSArray *productIDs = [devices valueForKey:@"ProductId"];
332338
NSSet *productIDSet = [NSSet setWithArray:productIDs];//去chong
333-
[[TIoTRequestObject shared] post:AppGetProducts Param:@{@"ProductIds":productIDSet.allObjects} success:^(id responseObject) {
339+
[[TIoTCoreRequestObject shared] post:AppGetProducts Param:@{@"ProductIds":productIDSet.allObjects} success:^(id responseObject) {
334340

335341
NSArray *tmpArr = responseObject[@"Products"];
336342
if (tmpArr.count > 0) {
@@ -371,7 +377,7 @@ - (void)getTRTCDeviceData:(NSString *)productID devices:(NSArray *)devices {
371377
continue;
372378
}
373379
//2.是trtc设备,查看trtc状态是否为呼叫中1
374-
[[TIoTRequestObject shared] post:AppGetDeviceData Param:@{@"DeviceId":device.DeviceId} success:^(id responseObject) {
380+
[[TIoTCoreRequestObject shared] post:AppGetDeviceData Param:@{@"DeviceId":device.DeviceId} success:^(id responseObject) {
375381
NSString *tmpStr = (NSString *)responseObject[@"Data"];
376382
TIoTDeviceDataModel *product = [TIoTDeviceDataModel yy_modelWithJSON:tmpStr];
377383

Source/LinkSDKDemo/Core/Controller/Device/ControlDeviceVC.m

Lines changed: 149 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@
1414
#import "TIoTCoreSocketCover.h"
1515
#import <YYModel/YYModel.h>
1616
#import "TIoTCoreUtil.h"
17+
#import "TIoTCoreRequestObject.h"
18+
#import "TIoTTRTCUIManage.h"
19+
#import "HXYNotice.h"
1720

18-
@interface ControlDeviceVC ()<UITableViewDelegate,UITableViewDataSource, TIoTTRTCSessionUIDelegate, TRTCCallingViewDelegate>
21+
@interface ControlDeviceVC ()<UITableViewDelegate,UITableViewDataSource>
1922

2023
@property (nonatomic,strong) DeviceInfo *ci;
2124
@property (weak, nonatomic) IBOutlet UILabel *theme;
@@ -25,6 +28,9 @@ @interface ControlDeviceVC ()<UITableViewDelegate,UITableViewDataSource, TIoTTRT
2528
@property (weak, nonatomic) IBOutlet UILabel *timing;
2629
@property (weak, nonatomic) IBOutlet UITableView *tableView;
2730

31+
@property (nonatomic, strong) NSDictionary *reportData;
32+
@property (nonatomic, strong) TIOTtrtcPayloadModel *reportModel;
33+
@property (nonatomic, strong) DeviceInfo *deviceInfomation;
2834
@end
2935

3036
@implementation ControlDeviceVC{
@@ -37,11 +43,10 @@ @implementation ControlDeviceVC{
3743
- (void)viewDidLoad {
3844
[super viewDidLoad];
3945
// Do any additional setup after loading the view from its nib.
40-
41-
[TIoTCoreSocketManager shared].delegate = [TIoTCoreSocketCover shared];
42-
//TRTC UI Delegate
43-
[TIoTTRTCSessionManager sharedManager].uidelegate = self;
4446

47+
[HXYNotice addReportDeviceListener:self reaction:@selector(deviceReport:)];
48+
self.deviceInfomation.deviceId = self.deviceInfo[@"DeviceId"];
49+
4550
[[TIoTCoreDeviceSet shared] activePushWithDeviceIds:@[self.deviceInfo[@"DeviceId"]] complete:^(BOOL success, id data) {
4651

4752
}];
@@ -117,29 +122,6 @@ - (void)refresh
117122

118123
[self.tableView reloadData];
119124

120-
121-
//这是trtc设备
122-
BOOL isTRTC = NO;
123-
for (NSDictionary *prototo in self.ci.zipData) {
124-
NSString *syskey = prototo[@"id"];
125-
if ([syskey isEqualToString:@"_sys_video_call_status"] || [syskey isEqualToString:@"_sys_audio_call_status"] ) {
126-
isTRTC = YES;
127-
break;
128-
}
129-
}
130-
131-
if (isTRTC) {
132-
UIBarButtonItem *testItem = [[UIBarButtonItem alloc] initWithTitle:@"TRTC打电话"
133-
style:UIBarButtonItemStylePlain
134-
target:self
135-
action:@selector(handleTestAction)];
136-
self.navigationItem.rightBarButtonItem = testItem;
137-
}
138-
}
139-
140-
- (void)handleTestAction {
141-
[self callDeviceFromPanel:TIoTTRTCSessionCallType_video];
142-
[self sendControlData:@{@"_sys_video_call_status":@1}];
143125
}
144126
#pragma mark - tableView
145127

@@ -176,6 +158,140 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
176158
return cell;
177159
}
178160

161+
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
162+
NSDictionary *dic = self.ci.zipData[indexPath.row]?:@{};
163+
164+
if (indexPath.row == 0 || indexPath.row == 1) {
165+
//视频 语音呼叫
166+
if (dic.allKeys.count != 0) {
167+
//trtc特殊判断逻辑
168+
NSString *key = dic[@"id"];
169+
if ([key isEqualToString:TIoTTRTCaudio_call_status] || [key isEqualToString:TIoTTRTCvideo_call_status]) {
170+
self.reportData = dic;
171+
[self reportDeviceData:@{key: @1}];
172+
return;
173+
}
174+
}
175+
}
176+
}
177+
178+
//下发数据
179+
- (void)reportDeviceData:(NSDictionary *)deviceReport {
180+
181+
//在这里都是主动呼叫,不存在被动
182+
NSString *key = self.reportData[@"id"];
183+
// NSNumber *statusValue = self.reportData[@"status"][@"Value"];
184+
185+
if (![[TIoTCoreUserManage shared].sys_call_status isEqualToString:@"-1"]) {
186+
NSLog(@"--!!-%@---",[TIoTCoreUserManage shared].sys_call_status);
187+
if ([key isEqualToString:@"_sys_audio_call_status"]) {
188+
if (![[TIoTCoreUserManage shared].sys_call_status isEqualToString:@"0"]) {
189+
[MBProgressHUD showError:NSLocalizedString(@"other_part_busy", @"对方正忙...") toView:self.view];
190+
return;
191+
}
192+
}else if ([key isEqualToString:@"_sys_video_call_status"]) {
193+
if (![[TIoTCoreUserManage shared].sys_call_status isEqualToString:@"0"]) {
194+
[MBProgressHUD showError:NSLocalizedString(@"other_part_busy", @"对方正忙...") toView:self.view];
195+
return;
196+
}
197+
}
198+
}
199+
200+
NSMutableDictionary *trtcReport = [deviceReport mutableCopy];
201+
NSString *userId = [TIoTCoreUserManage shared].userId;
202+
if (userId) {
203+
[trtcReport setValue:userId forKey:@"_sys_userid"];
204+
}
205+
NSString *username = [TIoTCoreUserManage shared].nickName;
206+
if (username) {
207+
[trtcReport setValue:username forKey:@"username"];
208+
}
209+
210+
NSDictionary *tmpDic = @{
211+
@"ProductId":self.deviceInfo[@"ProductId"],
212+
@"DeviceName":self.deviceInfo[@"DeviceName"],
213+
// @"Data":[NSString objectToJson:deviceReport],
214+
@"Data":[NSString objectToJson:trtcReport]
215+
};
216+
217+
[[TIoTCoreRequestObject shared] post:AppControlDeviceData Param:tmpDic success:^(id responseObject) {
218+
} failure:^(NSString *reason, NSError *error,NSDictionary *dic) {
219+
220+
}];
221+
222+
//主动呼叫,开始拨打
223+
TIoTTRTCSessionCallType audioORvideo = TIoTTRTCSessionCallType_audio;//audio
224+
BOOL isTRTCDevice = NO;
225+
for (NSString *prototype in deviceReport.allKeys) {
226+
227+
NSString *protoValue = deviceReport[prototype];
228+
if ([prototype isEqualToString:TIoTTRTCaudio_call_status] || [prototype isEqualToString:TIoTTRTCvideo_call_status]) {
229+
230+
if (protoValue.intValue == 1) {
231+
isTRTCDevice = YES;
232+
233+
if ([prototype isEqualToString:TIoTTRTCaudio_call_status]) {
234+
audioORvideo = TIoTTRTCSessionCallType_audio;
235+
}else {
236+
audioORvideo = TIoTTRTCSessionCallType_video;
237+
}
238+
break;
239+
}
240+
}
241+
}
242+
if (isTRTCDevice) {
243+
244+
[[TIoTTRTCUIManage sharedManager] callDeviceFromPanel:audioORvideo withDevideId:[NSString stringWithFormat:@"%@/%@",self.deviceInfo[@"ProductId"]?:@"",self.deviceInfo[@"DeviceName"]?:@""]];
245+
}
246+
}
247+
248+
//收到上报
249+
- (void)deviceReport:(NSNotification *)notification{
250+
NSDictionary *dic = notification.userInfo;
251+
[self.deviceInfomation handleReportDevice:dic];
252+
253+
[self reloadForBig];
254+
[self.tableView reloadData];
255+
256+
257+
NSDictionary *payloadDic = [NSString base64Decode:dic[@"Payload"]];
258+
NSLog(@"\n----收到设备上报信息 payloadDic: %@---\n",payloadDic);
259+
NSLog(@"\n---收到设备上报 userid---%@\n",[TIoTCoreUserManage shared].userId);
260+
261+
if ([payloadDic.allKeys containsObject:@"params"]) {
262+
NSDictionary *paramsDic = payloadDic[@"params"];
263+
self.reportModel = [TIOTtrtcPayloadModel yy_modelWithJSON:payloadDic];
264+
if (paramsDic[@"_sys_audio_call_status"]) {
265+
[TIoTCoreUserManage shared].sys_call_status = self.reportModel.params._sys_audio_call_status;
266+
}else if (paramsDic[@"_sys_video_call_status"]) {
267+
[TIoTCoreUserManage shared].sys_call_status = self.reportModel.params._sys_video_call_status;
268+
}
269+
}
270+
271+
272+
if ([dic.allKeys containsObject:@"SubType"] && [dic.allKeys containsObject:@"DeviceId"]) {
273+
274+
NSString *device_Id = dic[@"DeviceId"];
275+
if (![[NSString stringWithFormat:@"%@/%@",self.deviceInfo[@"ProductId"] , self.deviceInfo[@"DeviceName"]] isEqualToString:device_Id]) {
276+
return;
277+
}
278+
279+
NSString *line_status = dic[@"SubType"];
280+
if ([line_status isEqualToString:@"Offline"]) {
281+
//下线
282+
// [MBProgressHUD showError:@"设备已离线"];
283+
284+
}else if ([line_status isEqualToString:@"Online"]) {
285+
286+
}
287+
}
288+
}
289+
290+
//刷新大按钮
291+
- (void)reloadForBig
292+
{
293+
294+
}
179295

180296
#pragma mark -
181297

@@ -272,112 +388,15 @@ - (void)receiveData:(NSDictionary *)deviceChange{
272388

273389
[self zipData:deviceChange];
274390
[self.tableView reloadData];
275-
276-
277-
//检测是否TRTC设备,是否在呼叫中
278-
NSDictionary *payloadDic = [NSString base64Decode:deviceChange[@"Payload"]];
279-
TIOTtrtcPayloadModel *model = [TIOTtrtcPayloadModel yy_modelWithJSON:payloadDic];
280-
if (model.params._sys_userid.length < 1) {
281-
model.params._sys_userid = deviceChange[@"DeviceId"];
282-
}
283-
284-
if (model.params._sys_audio_call_status.intValue == 1 || model.params._sys_video_call_status.intValue == 1) {
285-
_deviceParam = model.params;
286-
287-
[self isActiveCalling:_deviceParam._sys_userid];
288-
}
289-
}
290-
291-
292-
- (void)callDeviceFromPanel: (TIoTTRTCSessionCallType)audioORvideo {
293-
UIViewController *topVC = [TIoTCoreUtil topViewController];
294-
if (_callAudioVC == topVC || _callVideoVC == topVC) {
295-
//正在主动呼叫中,或呼叫UI已启动
296-
return;
297-
}
298-
299-
if (audioORvideo == TIoTTRTCSessionCallType_audio) { //audio
300-
_callAudioVC = [[TRTCCallingAuidoViewController alloc] initWithOcUserID:nil];
301-
_callAudioVC.actionDelegate = self;
302-
_callAudioVC.modalPresentationStyle = UIModalPresentationFullScreen;
303-
[[TIoTCoreUtil topViewController] presentViewController:_callAudioVC animated:NO completion:^{}];
304-
305-
}else if (audioORvideo == TIoTTRTCSessionCallType_video) { //video
306-
307-
_callVideoVC = [[TRTCCallingVideoViewController alloc] initWithOcUserID:nil];
308-
_callVideoVC.actionDelegate = self;
309-
_callVideoVC.modalPresentationStyle = UIModalPresentationFullScreen;
310-
[[TIoTCoreUtil topViewController] presentViewController:_callVideoVC animated:NO completion:^{}];
311-
}
312391
}
313392

314-
315-
//被动呼叫的UI逻辑
316-
- (BOOL)isActiveCalling:(NSString *)deviceUserID {
317-
UIViewController *topVC = [TIoTCoreUtil topViewController];
318-
if (_callAudioVC == topVC || _callVideoVC == topVC) {
319-
//正在主动呼叫中,或呼叫UI已启动,直接进房间
320-
[self didAcceptJoinRoom];
321-
return YES;
322-
}
323-
324-
325-
//被呼叫了,点击接听后才进房间吧
326-
if (_deviceParam._sys_audio_call_status.intValue == 1) { //audio
327-
328-
_callAudioVC = [[TRTCCallingAuidoViewController alloc] initWithOcUserID:_deviceParam._sys_userid];
329-
_callAudioVC.actionDelegate = self;
330-
_callAudioVC.modalPresentationStyle = UIModalPresentationFullScreen;
331-
[[TIoTCoreUtil topViewController] presentViewController:_callAudioVC animated:NO completion:nil];
332-
333-
}else if (_deviceParam._sys_video_call_status.intValue == 1) { //video
334-
335-
_callVideoVC = [[TRTCCallingVideoViewController alloc] initWithOcUserID:_deviceParam._sys_userid];
336-
_callVideoVC.actionDelegate = self;
337-
_callVideoVC.modalPresentationStyle = UIModalPresentationFullScreen;
338-
[[TIoTCoreUtil topViewController] presentViewController:_callVideoVC animated:NO completion:^{
339-
// [[TIoTTRTCSessionManager sharedManager] enterRoom];
340-
}];
341-
}
342-
343-
return NO;
344-
}
345-
346-
347-
#pragma mark- TRTCCallingViewDelegate ui决定是否进入房间
348-
- (void)didAcceptJoinRoom {
349-
//2.根据UI决定是否进入房间
350-
351-
//开始准备进房间,通话中状态
352-
// NSDictionary *param = @{@"DeviceId":_deviceParam._sys_userid};
353-
354-
//TRTC设备需要通话,开始通话,防止不是trtc设备的通知
355-
[[TIoTTRTCSessionManager sharedManager] preEnterRoom:_deviceParam failure:^(NSString * _Nullable reason, NSError * _Nullable error, NSDictionary * _Nullable dic) {
356-
357-
[MBProgressHUD showError:reason];
358-
}];
359-
}
360-
361-
362-
#pragma mark -TIoTTRTCSessionUIDelegate
363-
//呼起被叫页面,如果当前正在主叫页面,则外界UI不处理
364-
365-
- (void)showRemoteUser:(NSString *)remoteUserID {
366-
UIViewController *topVC = [TIoTCoreUtil topViewController];
367-
if (_callAudioVC == topVC) {
368-
//正在主动呼叫中,或呼叫UI已启动
369-
[_callAudioVC OCEnterUserWithUserID:remoteUserID];
370-
}else {
371-
[_callVideoVC OCEnterUserWithUserID:remoteUserID];
393+
- (DeviceInfo *)deviceInfomation
394+
{
395+
if (!_deviceInfomation) {
396+
_deviceInfomation = [[DeviceInfo alloc] init];
372397
}
398+
return _deviceInfomation;
373399
}
374400

375-
- (void)exitRoom:(NSString *)remoteUserID {
376-
[_callAudioVC remoteDismiss];
377-
[_callVideoVC remoteDismiss];
378-
379-
_callAudioVC = nil;
380-
_callVideoVC = nil;
381-
}
382401

383402
@end
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//
2+
// TIoTDemoWebSocketManager.h
3+
// LinkSDKDemo
4+
//
5+
//
6+
7+
#import <Foundation/Foundation.h>
8+
#import "TIoTCoreSocketManager.h"
9+
10+
NS_ASSUME_NONNULL_BEGIN
11+
12+
typedef void(^didReceiveMessage) (BOOL sucess, NSDictionary *data);
13+
14+
@interface TIoTDemoWebSocketManager : NSObject
15+
/** 连接状态 */
16+
@property (nonatomic,assign) WCReadyState socketReadyState;
17+
18+
+(instancetype)shared;
19+
- (void)SRWebSocketOpen;//开启连接
20+
- (void)SRWebSocketClose;//关闭连接
21+
@end
22+
23+
NS_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)