-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
iOS: TUIKit & SDK : Update version to 4.6.1
- Loading branch information
Showing
16 changed files
with
905 additions
and
0 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
iOS/TUIKitDemo/TUIKitDemo/Assets.xcassets/hungup.imageset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "universal", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"idiom" : "universal", | ||
"filename" : "hungup.png", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "universal", | ||
"scale" : "3x" | ||
} | ||
], | ||
"info" : { | ||
"version" : 1, | ||
"author" : "xcode" | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions
12
iOS/TUIKitDemo/TUIKitDemo/Assets.xcassets/videocall.imageset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "universal", | ||
"filename" : "videocall.png" | ||
} | ||
], | ||
"info" : { | ||
"version" : 1, | ||
"author" : "xcode" | ||
} | ||
} |
Binary file added
BIN
+325 Bytes
iOS/TUIKitDemo/TUIKitDemo/Assets.xcassets/videocall.imageset/videocall.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions
12
iOS/TUIKitDemo/TUIKitDemo/Assets.xcassets/videocall_out.imageset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "universal", | ||
"filename" : "videocall_out.png" | ||
} | ||
], | ||
"info" : { | ||
"version" : 1, | ||
"author" : "xcode" | ||
} | ||
} |
Binary file added
BIN
+956 Bytes
iOS/TUIKitDemo/TUIKitDemo/Assets.xcassets/videocall_out.imageset/videocall_out.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// ChatViewController+video.h | ||
// TUIKitDemo | ||
// | ||
// Created by xcoderliu on 9/30/19. | ||
// Copyright © 2019 Tencent. All rights reserved. | ||
// | ||
|
||
|
||
#import "VideoCallCell.h" | ||
#import "ChatViewController.h" | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface ChatViewController (video) | ||
- (BOOL)videoCallTimeOut: (TIMMessage*)message; | ||
- (TUIMessageCellData *)chatController:(TUIChatController *)controller onNewVideoCallMessage:(TIMMessage *)msg; | ||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// | ||
// ChatViewController+video.m | ||
// TUIKitDemo | ||
// | ||
// Created by xcoderliu on 9/30/19. | ||
// Copyright © 2019 Tencent. All rights reserved. | ||
// | ||
|
||
#import "ChatViewController+video.h" | ||
#import "TCUtil.h" | ||
#import "THelper.h" | ||
#import "VideoCallManager.h" | ||
|
||
@implementation ChatViewController (video) | ||
|
||
- (TUIMessageCellData *)chatController:(TUIChatController *)controller onNewVideoCallMessage:(TIMMessage *)msg { | ||
TIMElem *elem = [msg getElem:0]; | ||
if([elem isKindOfClass:[TIMCustomElem class]]) { | ||
NSDictionary *param = [TCUtil jsonData2Dictionary:[(TIMCustomElem *)elem data]]; | ||
UInt32 state = [param[@"videoState"] unsignedIntValue]; | ||
NSString* user = param[@"requestUser"]; | ||
if ( state == VIDEOCALL_REQUESTING || | ||
state == VIDEOCALL_USER_CONNECTTING ) { //请求或开始连接 | ||
|
||
return nil; | ||
} | ||
|
||
BOOL isOutGoing = msg.isSelf; | ||
if (state == VIDEOCALL_USER_REJECT || | ||
state == VIDEOCALL_USER_ONCALLING) { //由我发起请求,对方发送结果 | ||
isOutGoing = !isOutGoing; | ||
} | ||
|
||
if (user != nil) { | ||
NSString *currentUser = [[VideoCallManager shareInstance] currentUserIdentifier]; | ||
isOutGoing = (user == currentUser); | ||
} | ||
|
||
VideoCallCellData *cellData = [[VideoCallCellData alloc] initWithDirection:isOutGoing | ||
? MsgDirectionOutgoing : MsgDirectionIncoming]; | ||
cellData.roomID = [param[@"roomID"] unsignedIntValue]; | ||
cellData.isSelf = msg.isSelf; | ||
cellData.videoState = state; | ||
cellData.requestUser = user; | ||
NSNumber *duration = param[@"duration"]; | ||
if (duration != nil) { | ||
cellData.duration = [duration unsignedIntValue]; | ||
} else { | ||
cellData.duration = 0; | ||
} | ||
cellData.avatarUrl = [NSURL URLWithString:[[TIMFriendshipManager sharedInstance] querySelfProfile].faceURL]; | ||
|
||
return cellData; | ||
} | ||
return nil; | ||
} | ||
|
||
- (BOOL)videoCallTimeOut: (TIMMessage*)message { | ||
NSTimeInterval time = [[NSDate date] timeIntervalSinceDate:message.timestamp]; | ||
if ( time >= VIDEOCALL_TIMEOUT) { | ||
return YES; | ||
} | ||
return NO; | ||
} | ||
|
||
@end |
20 changes: 20 additions & 0 deletions
20
iOS/TUIKitDemo/TUIKitDemo/Chat/Meeting/VideoCallManager+videoMeeting.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// VideoCallManager+videoMeeting.h | ||
// TUIKitDemo | ||
// | ||
// Created by xcoderliu on 10/14/19. | ||
// Copyright © 2019 Tencent. All rights reserved. | ||
// | ||
|
||
|
||
|
||
#import "VideoCallManager.h" | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface VideoCallManager (videoMeeting) | ||
- (void)_enterMeetingRoom; | ||
- (void)_quitMeetingRoom; | ||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
166 changes: 166 additions & 0 deletions
166
iOS/TUIKitDemo/TUIKitDemo/Chat/Meeting/VideoCallManager+videoMeeting.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
// | ||
// VideoCallManager+videoMeeting.m | ||
// TUIKitDemo | ||
// | ||
// Created by xcoderliu on 10/14/19. | ||
// Copyright © 2019 Tencent. All rights reserved. | ||
// | ||
|
||
#import "VideoCallManager+videoMeeting.h" | ||
#import "AppDelegate.h" | ||
#import "GenerateTestUserSig.h" | ||
#import <TRTCCloud.h> | ||
#import <CommonCrypto/CommonCrypto.h> | ||
#import <zlib.h> | ||
|
||
@interface VideoCallManager ()<TRTCCloudDelegate> | ||
|
||
@end | ||
|
||
typedef enum : NSUInteger { | ||
TRTC_IDLE, // SDK 没有进入视频通话状态 | ||
TRTC_ENTERED, // SDK 视频通话进行中 | ||
} TRTCStatus; | ||
|
||
@implementation VideoCallManager (videoMeeting) | ||
- (void)_enterMeetingRoom { | ||
// TRTC相关参数设置 | ||
TRTCParams *param = [[TRTCParams alloc] init]; | ||
param.sdkAppId = SDKAPPID; | ||
param.userId = [self currentUserIdentifier]; | ||
param.roomId = self.currentRoomID; | ||
param.userSig = [GenerateTestUserSig genTestUserSig:[self currentUserIdentifier]]; | ||
param.privateMapKey = @""; | ||
if (self.localVideoView) { | ||
[self.localVideoView removeFromSuperview]; | ||
} | ||
if (self.remoteVideoView) { | ||
[self.remoteVideoView removeFromSuperview]; | ||
} | ||
self.localVideoView = [[UIView alloc] init]; | ||
self.remoteVideoView = [[UIView alloc] init]; | ||
self.hungUP = [[UIButton alloc] init]; | ||
self.localVideoView.backgroundColor = [UIColor grayColor]; | ||
self.remoteVideoView.backgroundColor = [UIColor grayColor]; | ||
UIWindow *window = [[[UIApplication sharedApplication] windows] lastObject]; | ||
[self.remoteVideoView setFrame:window.rootViewController.view.bounds]; | ||
[self.localVideoView setFrame:window.rootViewController.view.bounds]; | ||
|
||
[self.hungUP addTarget:self action:@selector(userQuit) forControlEvents:UIControlEventTouchUpInside]; | ||
[self.hungUP setImage:[UIImage imageNamed:@"hungup"] forState:UIControlStateNormal]; | ||
[self.hungUP setFrame:CGRectMake((window.rootViewController.view.bounds.size.width - 60) / 2, window.rootViewController.view.bounds.size.height - 120, 60, 60)]; | ||
[self.hungUP.layer setCornerRadius:60 / 2]; | ||
[self.hungUP setClipsToBounds:YES]; | ||
[window.rootViewController.view addSubview:self.remoteVideoView]; | ||
[window.rootViewController.view addSubview:self.localVideoView]; | ||
[window.rootViewController.view addSubview:self.hungUP]; | ||
[[TRTCCloud sharedInstance] setDelegate:self]; | ||
[[TRTCCloud sharedInstance] enterRoom:param appScene:(TRTCAppSceneVideoCall)]; | ||
[[TRTCCloud sharedInstance] startLocalPreview:YES view:self.localVideoView]; | ||
[[TRTCCloud sharedInstance] muteLocalVideo:NO]; | ||
[[TRTCCloud sharedInstance] startLocalAudio]; | ||
[self setRoomStatus:TRTC_ENTERED]; | ||
} | ||
|
||
-(void)_quitMeetingRoom { | ||
[self setRoomStatus:TRTC_IDLE]; | ||
[[TRTCCloud sharedInstance] stopLocalPreview]; | ||
[[TRTCCloud sharedInstance] exitRoom]; | ||
if (self.localVideoView) { | ||
[self.localVideoView removeFromSuperview]; | ||
self.localVideoView = nil; | ||
} | ||
if (self.remoteVideoView) { | ||
[self.remoteVideoView removeFromSuperview]; | ||
self.remoteVideoView = nil; | ||
} | ||
if (self.hungUP) { | ||
[self.hungUP removeFromSuperview]; | ||
self.hungUP = nil; | ||
} | ||
} | ||
|
||
#pragma mark - config | ||
|
||
- (NSString *)hmac:(NSString *)plainText | ||
{ | ||
const char *cKey = [@"61cbf613d0cea4b302958e39c7b74acaaed0956fe8c494eda1c45912c324ecab" | ||
cStringUsingEncoding:NSUTF8StringEncoding]; | ||
const char *cData = [plainText cStringUsingEncoding:NSUTF8StringEncoding]; | ||
|
||
unsigned char cHMAC[CC_SHA256_DIGEST_LENGTH]; | ||
|
||
CCHmac(kCCHmacAlgSHA256, cKey, strlen(cKey), cData, strlen(cData), cHMAC); | ||
|
||
NSData *HMACData = [[NSData alloc] initWithBytes:cHMAC length:sizeof(cHMAC)]; | ||
return [HMACData base64EncodedStringWithOptions:0]; | ||
} | ||
|
||
- (NSString *)base64URL:(NSData *)data | ||
{ | ||
NSString *result = [data base64EncodedStringWithOptions:0]; | ||
NSMutableString *final = [[NSMutableString alloc] init]; | ||
const char *cString = [result cStringUsingEncoding:NSUTF8StringEncoding]; | ||
for (int i = 0; i < result.length; ++ i) { | ||
char x = cString[i]; | ||
switch(x){ | ||
case '+': | ||
[final appendString:@"*"]; | ||
break; | ||
case '/': | ||
[final appendString:@"-"]; | ||
break; | ||
case '=': | ||
[final appendString:@"_"]; | ||
break; | ||
default: | ||
[final appendFormat:@"%c", x]; | ||
break; | ||
} | ||
} | ||
return final; | ||
} | ||
|
||
/** | ||
* 防止iOS锁屏:如果视频通话进行中,则方式iPhone进入锁屏状态 | ||
*/ | ||
- (void)setRoomStatus:(TRTCStatus)roomStatus { | ||
|
||
switch (roomStatus) { | ||
case TRTC_IDLE: | ||
[[UIApplication sharedApplication] setIdleTimerDisabled:NO]; | ||
break; | ||
case TRTC_ENTERED: | ||
[[UIApplication sharedApplication] setIdleTimerDisabled:YES]; | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
#pragma mark - callback of TRTC | ||
- (void)onEnterRoom:(NSInteger)result { | ||
NSLog(@"%ld",(long)result); | ||
} | ||
- (void)onUserVideoAvailable:(NSString *)userId available:(BOOL)available { | ||
if (available && userId != [self currentUserIdentifier]) { | ||
[[TRTCCloud sharedInstance] startRemoteView:userId view:self.remoteVideoView]; | ||
} | ||
} | ||
|
||
- (void)onFirstVideoFrame:(NSString *)userId streamType:(TRTCVideoStreamType)streamType width:(int)width height:(int)height { | ||
if (userId != [self currentUserIdentifier]) { //对方视频 | ||
[UIView animateWithDuration:0.6 animations:^{ | ||
[self.localVideoView setFrame:CGRectMake(self.remoteVideoView.bounds.size.width - 100 - 18, 20, 100, 100.0 / 9.0 * 16.0)]; | ||
}]; | ||
} | ||
} | ||
|
||
- (void)onUserExit:(NSString *)userId reason:(NSInteger)reason { | ||
NSLog(@"%ld",(long)reason); | ||
} | ||
|
||
- (void)userQuit { | ||
[self quitRoom:NO]; | ||
} | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// VideoCallCell.h | ||
// TUIKitDemo | ||
// | ||
// Created by xcoderliu on 9/29/19. | ||
// Copyright © 2019 Tencent. All rights reserved. | ||
// | ||
|
||
#import "TUITextMessageCell.h" | ||
#import "VideoCallCellData.h" | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
typedef void(^videoCellClickBlock)(void); | ||
|
||
@interface VideoCallCell : TUITextMessageCell | ||
- (void)fillWithData:(VideoCallCellData *)data; | ||
@property (nonatomic,copy,nullable)videoCellClickBlock videlClick; | ||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#import "VideoCallCell.h" | ||
#import <TUIKit.h> | ||
#import <THeader.h> | ||
#import <TIMFriendshipManager.h> | ||
|
||
@implementation VideoCallCell | ||
|
||
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier | ||
{ | ||
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; | ||
if (self) { | ||
UITapGestureRecognizer *singleFingerTap = | ||
[[UITapGestureRecognizer alloc] initWithTarget:self | ||
action:@selector(handleSingleTap:)]; | ||
[self.container addGestureRecognizer:singleFingerTap]; | ||
} | ||
return self; | ||
} | ||
|
||
- (void)setSelected:(BOOL)selected animated:(BOOL)animated { | ||
[super setSelected:selected animated:animated]; | ||
|
||
// Configure the view for the selected state | ||
} | ||
|
||
-(void)fillWithData:(VideoCallCellData *)data { | ||
[data setAvatarImage:DefaultAvatarImage]; | ||
[data setAvatarUrl:[NSURL URLWithString:@""]]; | ||
[data setName:data.requestUser]; | ||
[super fillWithData:data]; | ||
[[TIMFriendshipManager sharedInstance] getUsersProfile:@[data.requestUser] forceUpdate:NO succ:^(NSArray<TIMUserProfile *> *profiles) { | ||
[data setAvatarUrl:[NSURL URLWithString:profiles[0].faceURL]]; | ||
[data setName:profiles[0].nickname]; | ||
} fail:^(int code, NSString *msg) { | ||
|
||
}]; | ||
} | ||
|
||
- (void)handleSingleTap:(UITapGestureRecognizer *)recognizer | ||
{ | ||
if (self.videlClick) { | ||
self.videlClick(); | ||
} | ||
} | ||
|
||
@end |
Oops, something went wrong.