Skip to content

Commit

Permalink
report userlist
Browse files Browse the repository at this point in the history
  • Loading branch information
eagleychen committed Apr 26, 2024
1 parent c1fc399 commit 7fe59e0
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 18 deletions.
8 changes: 4 additions & 4 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ PODS:
- TIoTLinkKit_SoundTouch (1.0.0)
- TIoTLinkKit_TPNS (1.0.1)
- TIoTLinkKit_WechatOpenSDK (1.0.1)
- TIoTLinkKit_XP2P (2.4.49-beta.202404190227)
- TIoTLinkKit_XP2P (2.4.49-beta.202404260903)
- TIoTLinkVideo (1.0.0):
- CocoaAsyncSocket (= 7.6.5)
- TIoTLinkKit_FLV (= 2.2.3)
- TIoTLinkKit_GVoiceSE (>= 1.0.7)
- TIoTLinkKit_SoundTouch (= 1.0.0)
- TIoTLinkKit_XP2P (= 2.4.49-beta.202404190227)
- TIoTLinkKit_XP2P (= 2.4.49-beta.202404260903)
- TPCircularBuffer (= 1.6.1)
- TPCircularBuffer (1.6.1)
- TrueTime (5.0.3)
Expand Down Expand Up @@ -133,8 +133,8 @@ SPEC CHECKSUMS:
TIoTLinkKit_SoundTouch: cf79ae182b6c2349ff65bac7a338974bc538fa77
TIoTLinkKit_TPNS: 7cea4fc1d20ef6c4c11c4f0b66bbb10ecf4ed968
TIoTLinkKit_WechatOpenSDK: 7822d68cc5c46edf3f6020422202e7b65ea87614
TIoTLinkKit_XP2P: 7d72dc5406877f632309bddf1c4563095170487a
TIoTLinkVideo: 5ed3782635c8c970dd03f09d4700e6052bc4a24a
TIoTLinkKit_XP2P: 24e210fd96fd88c991c98b8ddc8a3c91bb823981
TIoTLinkVideo: 99852d5bd081a8774b341b86181680346928be1b
TPCircularBuffer: c13243556527551c4d320709c7b14a6d20cdc30a
TrueTime: b49551ffafb28a9dee04e51b226f42a416010842
TXLiteAVSDK_TRTC: e3383a81565e8bb2aaaaab4bd099ad5239cd5b2d
Expand Down
72 changes: 59 additions & 13 deletions Source/SDK/LinkVideo/TIoTCoreXP2PBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,20 @@

@interface TIoTCoreXP2PBridge ()<TIoTAVCaptionFLVDelegate>
@property (nonatomic, strong) NSString *dev_name;
@property (nonatomic, strong) NSString *pro_id;
@property (nonatomic, assign) BOOL isSending;
@property (nonatomic, strong) AVCaptureSessionPreset resolution;
@property (nonatomic, strong) NSTimer *getBufTimer;
@property (nonatomic, assign) NSInteger startTime;
- (void)cancelTimer;
- (void)doTick:(uint8_t *)recv_buf len:(size_t)recv_len;
- (void)doTick:(data_report_t)data_buf;
@end

const char* XP2PMsgHandle(const char *idd, XP2PType type, const char* msg) {

BOOL logEnable = [TIoTCoreXP2PBridge sharedInstance].logEnable;
if (logEnable) {
printf("XP2P log: %s", msg);
printf("XP2Plog: %s", msg);
}

if (type == XP2PTypeLog) {
Expand Down Expand Up @@ -139,9 +141,9 @@ void XP2PDataMsgHandle(const char *idd, uint8_t* recv_buf, size_t recv_len) {
return response_msg;
}

void XP2PReciveLogReportDataHandle(const char *idd, uint8_t* recv_buf, size_t recv_len) {
void XP2PReciveLogReportDataHandle(const char *idd, data_report_t data_buf) {
// NSString *DeviceName = [NSString stringWithCString:idd encoding:[NSString defaultCStringEncoding]]?:@"";
[[TIoTCoreXP2PBridge sharedInstance] doTick:recv_buf len:recv_len];
[[TIoTCoreXP2PBridge sharedInstance] doTick:data_buf];
}


Expand Down Expand Up @@ -241,9 +243,9 @@ - (XP2PErrCode)startAppWith:(NSString *)pro_id dev_name:(NSString *)dev_name {
- (XP2PErrCode)startAppWith:(NSString *)pro_id dev_name:(NSString *)dev_name type:(XP2PProtocolType)type{
// setStunServerToXp2p("11.11.11.11", 111);
// setLogEnable(false, false);
NSString *bundleid = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleIdentifier"];
NSString *bundleid = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleIdentifier"]?:@"";
NSString *nsstr_user_id = [self getAppUUID];
setContentDetail([self dicConvertString:@{@"good":@"morning", @"str_user_id":nsstr_user_id, @"version":@"video-v2.4.30_beta1", @"str_package_name": bundleid}],
setContentDetail([self dicConvertString:@{@"str_user_id":nsstr_user_id, @"version":@"video-v2.4.30_beta1", @"str_package_name": bundleid}],
[self dicConvertString:@{@"punch_cost": @510}],
XP2PReciveLogReportDataHandle);

Expand All @@ -256,6 +258,7 @@ - (XP2PErrCode)startAppWith:(NSString *)pro_id dev_name:(NSString *)dev_name typ
setUserCallbackToXp2p(XP2PDataMsgHandle, XP2PMsgHandle, XP2PReviceDeviceCustomMsgHandle);

//1.配置IOT_P2P SDK
self.pro_id = pro_id;
self.dev_name = dev_name;
int ret = startService(dev_name.UTF8String, pro_id.UTF8String, dev_name.UTF8String, type);
return (XP2PErrCode)ret;
Expand All @@ -270,8 +273,11 @@ - (XP2PErrCode)setXp2pInfo:(NSString *)dev_name sec_id:(NSString *)sec_id sec_ke
}
setQcloudApiCred([sec_id UTF8String], [sec_key UTF8String]); //正式版app发布时候不需要传入secretid和secretkey,避免泄露secretid和secretkey,此处仅为演示
}

int ret = setDeviceXp2pInfo(dev_name.UTF8String, xp2pinfo.UTF8String);

self.startTime = [[TIoTCoreXP2PBridge getNowTimeTimestamp] integerValue];
[self reportUserList:0 status:@"start"];
return (XP2PErrCode)ret;
}

Expand Down Expand Up @@ -498,6 +504,7 @@ - (void)stopService:(NSString *)dev_name {
[self stopVoiceToServer];
stopService(dev_name.UTF8String);

[self reportUserList:0 status:@"end"];
//关闭文件
// [fileHandle closeFile];
// fileHandle = NULL;
Expand Down Expand Up @@ -598,19 +605,17 @@ - (NSString *)readKeychainValue:(NSString *)sKey
return ret;
}

- (void)doTick:(uint8_t *)recv_buf len:(size_t)recv_len {
if (recv_len < 2) {
- (void)doTick:(data_report_t)data_buf {
if (data_buf.report_size < 2) {
return;
}

NSData *body = [NSData dataWithBytes:recv_buf length:recv_len];

NSData *body = [NSData dataWithBytes:data_buf.report_buf length:data_buf.report_size];
NSURL *urlString = [NSURL URLWithString:@"http://log.qvb.qcloud.com/reporter/vlive"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:urlString cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:5];
[request setValue:@"application/octet-stream" forHTTPHeaderField:@"Content-Type"];
request.HTTPMethod = @"POST";
request.HTTPBody = body;

NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {

NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
Expand All @@ -619,8 +624,42 @@ - (void)doTick:(uint8_t *)recv_buf len:(size_t)recv_len {
}
}];
[task resume];

[self reportUserList:data_buf.xntp_size status:@"bytecount"];
}

- (void)reportUserList:(size_t)xntp_size status:(NSString *)status {

static NSString *reqid = [[NSUUID UUID] UUIDString];
NSMutableDictionary *accessParam = [NSMutableDictionary dictionary];
[accessParam setValue:@"P2PReport" forKey:@"Action"];
[accessParam setValue:@"byteCount" forKey:@"Status"];
[accessParam setValue:@"live" forKey:@"DataAction"];
[accessParam setValue:reqid forKey:@"UniqueId"];
[accessParam setValue:@(self.startTime) forKey:@"StartTime"];
[accessParam setValue:@([[TIoTCoreXP2PBridge getNowTimeTimestamp] integerValue]) forKey:@"Time"];
[accessParam setValue:@"ios" forKey:@"System"];
[accessParam setValue:@"app" forKey:@"Platform"];
[accessParam setValue:[self getAppUUID] forKey:@"Uuid"];
[accessParam setValue:[self getAppUUID] forKey:@"UserId"];
[accessParam setValue:self.pro_id forKey:@"ProductId"];
[accessParam setValue:self.dev_name forKey:@"DeviceName"];
[accessParam setValue:@(xntp_size) forKey:@"ByteCount"];
[accessParam setValue:@(1) forKey:@"Channel"];
NSURL *url = [NSURL URLWithString:@"https://applog.iotcloud.tencentiotcloud.com/api/xp2p_ops/applog"];
NSMutableURLRequest *reqlog = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:5];
[reqlog setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
reqlog.HTTPMethod = @"POST";
reqlog.HTTPBody = [NSJSONSerialization dataWithJSONObject:accessParam options:NSJSONWritingFragmentsAllowed error:nil];;
NSURLSessionDataTask *tasklog = [[NSURLSession sharedSession] dataTaskWithRequest:reqlog completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {

NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
if (httpResponse.statusCode == 200) {
NSLog(@"app log: %@",response);
}
}];
[tasklog resume];
}

+ (NSString *)getSDKVersion {
return [NSString stringWithUTF8String:VIDEOSDKVERSION];
}
Expand All @@ -632,4 +671,11 @@ + (void)recordstream:(NSString *)dev_name {
+ (int)getStreamLinkMode:(NSString *)dev_name {
return getStreamLinkMode(dev_name.UTF8String);
}

+(NSString *)getNowTimeTimestamp {
NSDate *datenow = [NSDate date];
NSString *timeSp = [NSString stringWithFormat:@"%ld", (long)([datenow timeIntervalSince1970]*1000)];
return timeSp;
}

@end
2 changes: 1 addition & 1 deletion TIoTLinkVideo.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Pod::Spec.new do |s|
s.source_files = 'Source/SDK/LinkVideo/**/*.{h,m,c,mm}'
s.resource = 'Source/SDK/LinkVideo/FLV/asset/GvoiceSE_v1_239-119-oneref-e.nn'

s.dependency 'TIoTLinkKit_XP2P', '2.4.49-beta.202404190227'
s.dependency 'TIoTLinkKit_XP2P', '2.4.49-beta.202404260903'
s.dependency 'TIoTLinkKit_FLV', '2.2.3'
s.dependency 'CocoaAsyncSocket', '7.6.5'
s.dependency 'TIoTLinkKit_SoundTouch', '1.0.0'
Expand Down

0 comments on commit 7fe59e0

Please sign in to comment.