@onekeyfe/react-native-ping 1.1.57
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Ping.podspec +19 -0
- package/android/build.gradle +77 -0
- package/android/src/main/java/com/rnping/RNReactNativePingModule.kt +37 -0
- package/android/src/main/java/com/rnping/RNReactNativePingPackage.kt +33 -0
- package/ios/GBPing/GBPing.h +50 -0
- package/ios/GBPing/GBPing.m +944 -0
- package/ios/GBPing/GBPingSummary.h +24 -0
- package/ios/GBPing/GBPingSummary.m +67 -0
- package/ios/GBPing/ICMPHeader.h +79 -0
- package/ios/LHNetwork/LHDefinition.h +24 -0
- package/ios/LHNetwork/LHNetwork.h +34 -0
- package/ios/LHNetwork/LHNetwork.m +223 -0
- package/ios/Ping.h +10 -0
- package/ios/Ping.mm +91 -0
- package/lib/module/NativePing.js +5 -0
- package/lib/module/NativePing.js.map +1 -0
- package/lib/module/index.js +5 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/NativePing.d.ts +10 -0
- package/lib/typescript/src/NativePing.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +3 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/package.json +87 -0
- package/src/NativePing.ts +8 -0
- package/src/index.tsx +4 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//
|
|
2
|
+
// GBPingSummary.h
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
#import <Foundation/Foundation.h>
|
|
6
|
+
|
|
7
|
+
@interface GBPingSummary : NSObject <NSCopying>
|
|
8
|
+
|
|
9
|
+
typedef enum {
|
|
10
|
+
GBPingStatusPending,
|
|
11
|
+
GBPingStatusSuccess,
|
|
12
|
+
GBPingStatusFail,
|
|
13
|
+
} GBPingStatus;
|
|
14
|
+
|
|
15
|
+
@property (assign, nonatomic) NSUInteger sequenceNumber;
|
|
16
|
+
@property (assign, nonatomic) NSUInteger payloadSize;
|
|
17
|
+
@property (assign, nonatomic) NSUInteger ttl;
|
|
18
|
+
@property (strong, nonatomic, nullable) NSString *host;
|
|
19
|
+
@property (strong, nonatomic, nullable) NSDate *sendDate;
|
|
20
|
+
@property (strong, nonatomic, nullable) NSDate *receiveDate;
|
|
21
|
+
@property (assign, nonatomic) NSTimeInterval rtt;
|
|
22
|
+
@property (assign, nonatomic) GBPingStatus status;
|
|
23
|
+
|
|
24
|
+
@end
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
//
|
|
2
|
+
// GBPingSummary.m
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
#import "GBPingSummary.h"
|
|
6
|
+
|
|
7
|
+
@implementation GBPingSummary
|
|
8
|
+
|
|
9
|
+
#pragma mark - custom acc
|
|
10
|
+
|
|
11
|
+
- (void)setHost:(NSString *)host
|
|
12
|
+
{
|
|
13
|
+
_host = host;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
- (NSTimeInterval)rtt
|
|
17
|
+
{
|
|
18
|
+
if (self.sendDate) {
|
|
19
|
+
return [self.receiveDate timeIntervalSinceDate:self.sendDate];
|
|
20
|
+
} else {
|
|
21
|
+
return 0;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
#pragma mark - copying
|
|
26
|
+
|
|
27
|
+
- (id)copyWithZone:(NSZone *)zone
|
|
28
|
+
{
|
|
29
|
+
GBPingSummary *copy = [[[self class] allocWithZone:zone] init];
|
|
30
|
+
|
|
31
|
+
copy.sequenceNumber = self.sequenceNumber;
|
|
32
|
+
copy.payloadSize = self.payloadSize;
|
|
33
|
+
copy.ttl = self.ttl;
|
|
34
|
+
copy.host = [self.host copy];
|
|
35
|
+
copy.sendDate = [self.sendDate copy];
|
|
36
|
+
copy.receiveDate = [self.receiveDate copy];
|
|
37
|
+
copy.status = self.status;
|
|
38
|
+
|
|
39
|
+
return copy;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
#pragma mark - memory
|
|
43
|
+
|
|
44
|
+
- (id)init
|
|
45
|
+
{
|
|
46
|
+
if (self = [super init]) {
|
|
47
|
+
self.status = GBPingStatusPending;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return self;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
- (void)dealloc
|
|
54
|
+
{
|
|
55
|
+
self.host = nil;
|
|
56
|
+
self.sendDate = nil;
|
|
57
|
+
self.receiveDate = nil;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
#pragma mark - description
|
|
61
|
+
|
|
62
|
+
- (NSString *)description
|
|
63
|
+
{
|
|
64
|
+
return [NSString stringWithFormat:@"host: %@, seq: %lu, status: %d, ttl: %lu, payloadSize: %lu, sendDate: %@, receiveDate: %@, rtt: %f", self.host, (unsigned long)self.sequenceNumber, self.status, (unsigned long)self.ttl, (unsigned long)self.payloadSize, self.sendDate, self.receiveDate, self.rtt];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
@end
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
//
|
|
2
|
+
// ICMPHeader.h
|
|
3
|
+
// GBPing
|
|
4
|
+
//
|
|
5
|
+
// Created by Luka Mirosevic on 15/11/2012.
|
|
6
|
+
// Copyright (c) 2012 Goonbee. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
#ifndef GBPing_ICMPHeader_h
|
|
10
|
+
#define GBPing_ICMPHeader_h
|
|
11
|
+
|
|
12
|
+
#include <AssertMacros.h>
|
|
13
|
+
|
|
14
|
+
#pragma mark - IP and ICMP On-The-Wire Format
|
|
15
|
+
|
|
16
|
+
// The following declarations specify the structure of ping packets on the wire.
|
|
17
|
+
|
|
18
|
+
// IP header structure:
|
|
19
|
+
|
|
20
|
+
struct IPHeader {
|
|
21
|
+
uint8_t versionAndHeaderLength;
|
|
22
|
+
uint8_t differentiatedServices;
|
|
23
|
+
uint16_t totalLength;
|
|
24
|
+
uint16_t identification;
|
|
25
|
+
uint16_t flagsAndFragmentOffset;
|
|
26
|
+
uint8_t timeToLive;
|
|
27
|
+
uint8_t protocol;
|
|
28
|
+
uint16_t headerChecksum;
|
|
29
|
+
uint8_t sourceAddress[4];
|
|
30
|
+
uint8_t destinationAddress[4];
|
|
31
|
+
// options...
|
|
32
|
+
// data...
|
|
33
|
+
};
|
|
34
|
+
typedef struct IPHeader IPHeader;
|
|
35
|
+
|
|
36
|
+
__Check_Compile_Time(sizeof(IPHeader) == 20);
|
|
37
|
+
__Check_Compile_Time(offsetof(IPHeader, versionAndHeaderLength) == 0);
|
|
38
|
+
__Check_Compile_Time(offsetof(IPHeader, differentiatedServices) == 1);
|
|
39
|
+
__Check_Compile_Time(offsetof(IPHeader, totalLength) == 2);
|
|
40
|
+
__Check_Compile_Time(offsetof(IPHeader, identification) == 4);
|
|
41
|
+
__Check_Compile_Time(offsetof(IPHeader, flagsAndFragmentOffset) == 6);
|
|
42
|
+
__Check_Compile_Time(offsetof(IPHeader, timeToLive) == 8);
|
|
43
|
+
__Check_Compile_Time(offsetof(IPHeader, protocol) == 9);
|
|
44
|
+
__Check_Compile_Time(offsetof(IPHeader, headerChecksum) == 10);
|
|
45
|
+
__Check_Compile_Time(offsetof(IPHeader, sourceAddress) == 12);
|
|
46
|
+
__Check_Compile_Time(offsetof(IPHeader, destinationAddress) == 16);
|
|
47
|
+
|
|
48
|
+
// ICMP type and code combinations:
|
|
49
|
+
|
|
50
|
+
enum {
|
|
51
|
+
kICMPv4TypeEchoRequest = 8,
|
|
52
|
+
kICMPv4TypeEchoReply = 0
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
enum {
|
|
56
|
+
kICMPv6TypeEchoRequest = 128,
|
|
57
|
+
kICMPv6TypeEchoReply = 129
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// ICMP header structure:
|
|
61
|
+
|
|
62
|
+
struct ICMPHeader {
|
|
63
|
+
uint8_t type;
|
|
64
|
+
uint8_t code;
|
|
65
|
+
uint16_t checksum;
|
|
66
|
+
uint16_t identifier;
|
|
67
|
+
uint16_t sequenceNumber;
|
|
68
|
+
// data...
|
|
69
|
+
};
|
|
70
|
+
typedef struct ICMPHeader ICMPHeader;
|
|
71
|
+
|
|
72
|
+
__Check_Compile_Time(sizeof(ICMPHeader) == 8);
|
|
73
|
+
__Check_Compile_Time(offsetof(ICMPHeader, type) == 0);
|
|
74
|
+
__Check_Compile_Time(offsetof(ICMPHeader, code) == 1);
|
|
75
|
+
__Check_Compile_Time(offsetof(ICMPHeader, checksum) == 2);
|
|
76
|
+
__Check_Compile_Time(offsetof(ICMPHeader, identifier) == 4);
|
|
77
|
+
__Check_Compile_Time(offsetof(ICMPHeader, sequenceNumber) == 6);
|
|
78
|
+
|
|
79
|
+
#endif
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//
|
|
2
|
+
// LHDefinition.h
|
|
3
|
+
// RNReactNativePing
|
|
4
|
+
//
|
|
5
|
+
// Created by Jerry-Luo on 2019/3/29.
|
|
6
|
+
// Copyright © 2019 Pomato. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
#ifndef LHDefinition_h
|
|
10
|
+
#define LHDefinition_h
|
|
11
|
+
|
|
12
|
+
#define DEFINE_NSError(errorName,description) NSError *errorName = [NSError errorWithDomain:@#description code:description userInfo:@{@"code":@(description),@"message":@#description}];
|
|
13
|
+
|
|
14
|
+
typedef NS_ENUM (NSUInteger, PingErrorCode) {
|
|
15
|
+
PingUtil_Message_Timeout,
|
|
16
|
+
PingUtil_Message_PreviousPingIsStillRunning,
|
|
17
|
+
PingUtil_Message_HostErrorNotSetHost,
|
|
18
|
+
PingUtil_Message_HostErrorUnknown,
|
|
19
|
+
PingUtil_Message_HostErrorHostNotFound,
|
|
20
|
+
PingUtil_Message_Unknown,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
#endif /* LHDefinition_h */
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
//
|
|
2
|
+
// LHNetwork.h
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
#import <Foundation/Foundation.h>
|
|
6
|
+
#import <UIKit/UIKit.h>
|
|
7
|
+
|
|
8
|
+
@interface LHNetwork : NSObject
|
|
9
|
+
|
|
10
|
+
@property (nonatomic, copy, readonly) NSString *receivedNetworkSpeed;
|
|
11
|
+
|
|
12
|
+
@property (nonatomic, copy, readonly) NSString *sendNetworkSpeed;
|
|
13
|
+
|
|
14
|
+
@property (nonatomic, copy, readonly) NSString *receivedNetworkTotal;
|
|
15
|
+
|
|
16
|
+
@property (nonatomic, copy, readonly) NSString *sendNetworkTotal;
|
|
17
|
+
+ (instancetype)shareNetworkSpeed;
|
|
18
|
+
|
|
19
|
+
- (void)startMonitoringNetwork;
|
|
20
|
+
|
|
21
|
+
- (void)stopMonitoringNetwork;
|
|
22
|
+
|
|
23
|
+
- (void)checkNetworkflow;
|
|
24
|
+
@end
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @{@"received":@"100kB/s"}
|
|
28
|
+
*/
|
|
29
|
+
FOUNDATION_EXTERN NSString *const kNetworkReceivedSpeedNotification;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @{@"send":@"100kB/s"}
|
|
33
|
+
*/
|
|
34
|
+
FOUNDATION_EXTERN NSString *const kNetworkSendSpeedNotification;
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
//
|
|
2
|
+
// LHNetwork.m
|
|
3
|
+
//
|
|
4
|
+
#import "LHNetwork.h"
|
|
5
|
+
#include <arpa/inet.h>
|
|
6
|
+
#include <net/if.h>
|
|
7
|
+
#include <ifaddrs.h>
|
|
8
|
+
#include <net/if_dl.h>
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @{@"received":@"100kB/s"}
|
|
12
|
+
*/
|
|
13
|
+
NSString *const kNetworkReceivedSpeedNotification = @"kNetworkReceivedSpeedNotification";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @{@"send":@"100kB/s"}
|
|
17
|
+
*/
|
|
18
|
+
NSString *const kNetworkSendSpeedNotification = @"kNetworkSendSpeedNotification";
|
|
19
|
+
|
|
20
|
+
@interface LHNetwork ()
|
|
21
|
+
{
|
|
22
|
+
uint32_t _iBytes;
|
|
23
|
+
uint32_t _oBytes;
|
|
24
|
+
uint32_t _allFlow;
|
|
25
|
+
uint32_t _wifiIBytes;
|
|
26
|
+
uint32_t _wifiOBytes;
|
|
27
|
+
uint32_t _wifiFlow;
|
|
28
|
+
uint32_t _wwanIBytes;
|
|
29
|
+
uint32_t _wwanOBytes;
|
|
30
|
+
uint32_t _wwanFlow;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@property (nonatomic, copy) NSString *receivedNetworkSpeed;
|
|
34
|
+
|
|
35
|
+
@property (nonatomic, copy) NSString *sendNetworkSpeed;
|
|
36
|
+
|
|
37
|
+
@property (nonatomic, copy) NSString *receivedNetworkTotal;
|
|
38
|
+
|
|
39
|
+
@property (nonatomic, copy) NSString *sendNetworkTotal;
|
|
40
|
+
|
|
41
|
+
@property (nonatomic, strong) NSTimer *timer;
|
|
42
|
+
|
|
43
|
+
@end
|
|
44
|
+
|
|
45
|
+
@implementation LHNetwork
|
|
46
|
+
|
|
47
|
+
static LHNetwork *instance = nil;
|
|
48
|
+
|
|
49
|
+
+ (instancetype)shareNetworkSpeed
|
|
50
|
+
{
|
|
51
|
+
if (instance == nil) {
|
|
52
|
+
static dispatch_once_t onceToken;
|
|
53
|
+
dispatch_once(&onceToken, ^{
|
|
54
|
+
instance = [[self alloc] init];
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
return instance;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
+ (instancetype)allocWithZone:(struct _NSZone *)zone
|
|
61
|
+
{
|
|
62
|
+
if (instance == nil) {
|
|
63
|
+
static dispatch_once_t onceToken;
|
|
64
|
+
dispatch_once(&onceToken, ^{
|
|
65
|
+
instance = [super allocWithZone:zone];
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
return instance;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
- (instancetype)init
|
|
72
|
+
{
|
|
73
|
+
static dispatch_once_t onceToken;
|
|
74
|
+
dispatch_once(&onceToken, ^{
|
|
75
|
+
instance = [super init];
|
|
76
|
+
_iBytes = _oBytes = _allFlow = _wifiIBytes = _wifiOBytes = _wifiFlow = _wwanIBytes = _wwanOBytes = _wwanFlow = 0;
|
|
77
|
+
});
|
|
78
|
+
return instance;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
- (void)startMonitoringNetwork
|
|
82
|
+
{
|
|
83
|
+
if (_timer) [self stopMonitoringNetwork];
|
|
84
|
+
|
|
85
|
+
[[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:nil];
|
|
86
|
+
_timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(netSpeedNotification) userInfo:nil repeats:YES];
|
|
87
|
+
[[NSRunLoop currentRunLoop] addTimer:_timer forMode:NSRunLoopCommonModes];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
- (void)stopMonitoringNetwork
|
|
91
|
+
{
|
|
92
|
+
if ([_timer isValid]) {
|
|
93
|
+
[_timer invalidate];
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
- (void)netSpeedNotification
|
|
98
|
+
{
|
|
99
|
+
[self checkNetworkflow];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
- (NSString *)bytesToAvaiUnit:(uint32_t)bytes
|
|
103
|
+
{
|
|
104
|
+
if (bytes < 1024) { // B
|
|
105
|
+
return [NSString stringWithFormat:@"%dB", bytes];
|
|
106
|
+
} else if (bytes >= 1024 && bytes < 1024 * 1024) { // KB
|
|
107
|
+
return [NSString stringWithFormat:@"%.1fKB", (double)bytes / 1024];
|
|
108
|
+
} else if (bytes >= 1024 * 1024 && bytes < 1024 * 1024 * 1024) { // MB
|
|
109
|
+
return [NSString stringWithFormat:@"%.1fMB", (double)bytes / (1024 * 1024)];
|
|
110
|
+
} else { // GB
|
|
111
|
+
return [NSString stringWithFormat:@"%.1fGB", (double)bytes / (1024 * 1024 * 1024)];
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
- (void)checkNetworkflow
|
|
116
|
+
{
|
|
117
|
+
struct ifaddrs *ifa_list = 0, *ifa;
|
|
118
|
+
if (getifaddrs(&ifa_list) == -1) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
uint32_t iBytes = 0;
|
|
123
|
+
uint32_t oBytes = 0;
|
|
124
|
+
uint32_t allFlow = 0;
|
|
125
|
+
uint32_t wifiIBytes = 0;
|
|
126
|
+
uint32_t wifiOBytes = 0;
|
|
127
|
+
uint32_t wifiFlow = 0;
|
|
128
|
+
uint32_t wwanIBytes = 0;
|
|
129
|
+
uint32_t wwanOBytes = 0;
|
|
130
|
+
uint32_t wwanFlow = 0;
|
|
131
|
+
// struct timeval32 time;
|
|
132
|
+
|
|
133
|
+
for (ifa = ifa_list; ifa; ifa = ifa->ifa_next) {
|
|
134
|
+
if (AF_LINK != ifa->ifa_addr->sa_family) continue;
|
|
135
|
+
|
|
136
|
+
if (!(ifa->ifa_flags & IFF_UP) && !(ifa->ifa_flags & IFF_RUNNING)) continue;
|
|
137
|
+
|
|
138
|
+
if (ifa->ifa_data == 0) continue;
|
|
139
|
+
|
|
140
|
+
// network flow
|
|
141
|
+
if (strncmp(ifa->ifa_name, "lo", 2)) {
|
|
142
|
+
struct if_data *if_data = (struct if_data *)ifa->ifa_data;
|
|
143
|
+
|
|
144
|
+
iBytes += if_data->ifi_ibytes;
|
|
145
|
+
oBytes += if_data->ifi_obytes;
|
|
146
|
+
allFlow = iBytes + oBytes;
|
|
147
|
+
// time = if_data->ifi_lastchange;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
//wifi flow
|
|
151
|
+
if (!strcmp(ifa->ifa_name, "en0")) {
|
|
152
|
+
struct if_data *if_data = (struct if_data *)ifa->ifa_data;
|
|
153
|
+
|
|
154
|
+
wifiIBytes += if_data->ifi_ibytes;
|
|
155
|
+
wifiOBytes += if_data->ifi_obytes;
|
|
156
|
+
wifiFlow = wifiIBytes + wifiOBytes;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
//3G and gprs flow
|
|
160
|
+
if (!strcmp(ifa->ifa_name, "pdp_ip0")) {
|
|
161
|
+
struct if_data *if_data = (struct if_data *)ifa->ifa_data;
|
|
162
|
+
|
|
163
|
+
wwanIBytes += if_data->ifi_ibytes;
|
|
164
|
+
wwanOBytes += if_data->ifi_obytes;
|
|
165
|
+
wwanFlow = wwanIBytes + wwanOBytes;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
freeifaddrs(ifa_list);
|
|
169
|
+
|
|
170
|
+
if (_iBytes != 0) {
|
|
171
|
+
self.receivedNetworkSpeed = [[self bytesToAvaiUnit:iBytes - _iBytes] stringByAppendingString:@"/s"];
|
|
172
|
+
self.receivedNetworkTotal = [self bytesToAvaiUnit:iBytes];
|
|
173
|
+
[[NSNotificationCenter defaultCenter] postNotificationName:kNetworkReceivedSpeedNotification object:@{ @"received": self.receivedNetworkSpeed }];
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
_iBytes = iBytes;
|
|
177
|
+
|
|
178
|
+
if (_oBytes != 0) {
|
|
179
|
+
self.sendNetworkSpeed = [[self bytesToAvaiUnit:oBytes - _oBytes] stringByAppendingString:@"/s"];
|
|
180
|
+
self.sendNetworkTotal = [self bytesToAvaiUnit:oBytes];
|
|
181
|
+
[[NSNotificationCenter defaultCenter] postNotificationName:kNetworkSendSpeedNotification object:@{ @"send": self.sendNetworkSpeed }];
|
|
182
|
+
}
|
|
183
|
+
_oBytes = oBytes;
|
|
184
|
+
|
|
185
|
+
// //
|
|
186
|
+
// // NSLog(@"sentBytes==%@",sentBytes);
|
|
187
|
+
// NSString *networkFlow = [self bytesToAvaiUnit:allFlow];
|
|
188
|
+
// //
|
|
189
|
+
// NSLog(@"networkFlow==%@", networkFlow);
|
|
190
|
+
// //
|
|
191
|
+
// NSString *wifiReceived = [self bytesToAvaiUnit:wifiIBytes];
|
|
192
|
+
|
|
193
|
+
// NSLog(@"wifiReceived==%@", wifiReceived);
|
|
194
|
+
|
|
195
|
+
// NSString *wifiSent = [self bytesToAvaiUnit:wifiOBytes];
|
|
196
|
+
|
|
197
|
+
// NSLog(@"wifiSent==%@", wifiSent);
|
|
198
|
+
|
|
199
|
+
// NSString *wifiBytes = [self bytesToAvaiUnit:wifiFlow];
|
|
200
|
+
// //
|
|
201
|
+
// NSLog(@"wifiBytes==%@", wifiBytes);
|
|
202
|
+
// NSString *wwanReceived = [self bytesToAvaiUnit:wwanIBytes];
|
|
203
|
+
|
|
204
|
+
// NSLog(@"wwanReceived==%@", wwanReceived);
|
|
205
|
+
// NSString *wwanSent = [self bytesToAvaiUnit:wwanOBytes];
|
|
206
|
+
|
|
207
|
+
// NSLog(@"wwanSent==%@", wwanSent);
|
|
208
|
+
// NSString *wwanBytes = [self bytesToAvaiUnit:wwanFlow];
|
|
209
|
+
// //
|
|
210
|
+
// NSLog(@"wwanBytes==%@", wwanBytes);
|
|
211
|
+
|
|
212
|
+
// NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
|
|
213
|
+
|
|
214
|
+
// [formatter setDateFormat:@"YYYY-MM-dd hh:mm:ss:SSS"];
|
|
215
|
+
|
|
216
|
+
// NSDate *datenow = [NSDate date];
|
|
217
|
+
|
|
218
|
+
// NSString *nowtimeStr = [formatter stringFromDate:datenow];
|
|
219
|
+
|
|
220
|
+
// NSLog(@"time 2 = %@", nowtimeStr);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
@end
|
package/ios/Ping.h
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#import <RNPingSpec/RNPingSpec.h>
|
|
2
|
+
|
|
3
|
+
@interface Ping : NativeRNReactNativePingSpecBase <NativeRNReactNativePingSpec>
|
|
4
|
+
|
|
5
|
+
- (void)start:(NSString *)ipAddress
|
|
6
|
+
option:(JS::NativeRNReactNativePing::SpecStartOption &)option
|
|
7
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
8
|
+
reject:(RCTPromiseRejectBlock)reject;
|
|
9
|
+
|
|
10
|
+
@end
|
package/ios/Ping.mm
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
#import "Ping.h"
|
|
2
|
+
#import "GBPing/GBPing.h"
|
|
3
|
+
#import "LHNetwork/LHNetwork.h"
|
|
4
|
+
#import "LHNetwork/LHDefinition.h"
|
|
5
|
+
|
|
6
|
+
@interface Ping ()
|
|
7
|
+
@property (nonatomic, strong) dispatch_queue_t queue;
|
|
8
|
+
@end
|
|
9
|
+
|
|
10
|
+
@implementation Ping
|
|
11
|
+
|
|
12
|
+
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
|
|
13
|
+
(const facebook::react::ObjCTurboModule::InitParams &)params
|
|
14
|
+
{
|
|
15
|
+
return std::make_shared<facebook::react::NativeRNReactNativePingSpecJSI>(params);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
+ (NSString *)moduleName
|
|
19
|
+
{
|
|
20
|
+
return @"RNReactNativePing";
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
+ (BOOL)requiresMainQueueSetup
|
|
24
|
+
{
|
|
25
|
+
return NO;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
- (dispatch_queue_t)methodQueue
|
|
29
|
+
{
|
|
30
|
+
if (!_queue) {
|
|
31
|
+
_queue = dispatch_queue_create("com.onekey.RNPing", DISPATCH_QUEUE_SERIAL);
|
|
32
|
+
}
|
|
33
|
+
return _queue;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
- (void)start:(NSString *)ipAddress
|
|
37
|
+
option:(JS::NativeRNReactNativePing::SpecStartOption &)option
|
|
38
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
39
|
+
reject:(RCTPromiseRejectBlock)reject
|
|
40
|
+
{
|
|
41
|
+
__block GBPing *ping = [[GBPing alloc] init];
|
|
42
|
+
ping.timeout = 1.0;
|
|
43
|
+
ping.payloadSize = 56;
|
|
44
|
+
ping.pingPeriod = 0.9;
|
|
45
|
+
ping.host = ipAddress;
|
|
46
|
+
|
|
47
|
+
unsigned long long timeout = 1000;
|
|
48
|
+
if (option.timeout().has_value()) {
|
|
49
|
+
timeout = (unsigned long long)option.timeout().value();
|
|
50
|
+
ping.timeout = (NSTimeInterval)timeout;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (option.payloadSize().has_value()) {
|
|
54
|
+
unsigned long long payloadSize = (unsigned long long)option.payloadSize().value();
|
|
55
|
+
ping.payloadSize = payloadSize;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
dispatch_queue_t capturedQueue = _queue;
|
|
59
|
+
|
|
60
|
+
[ping setupWithBlock:^(BOOL success, NSError *_Nullable err) {
|
|
61
|
+
if (!success) {
|
|
62
|
+
reject(@(err.code).stringValue, err.domain, err);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
[ping startPingingWithBlock:^(GBPingSummary *summary) {
|
|
66
|
+
if (!ping) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
resolve(@(@(summary.rtt * 1000).intValue));
|
|
70
|
+
[ping stop];
|
|
71
|
+
ping = nil;
|
|
72
|
+
} fail:^(NSError *_Nonnull error) {
|
|
73
|
+
if (!ping) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
reject(@(error.code).stringValue, error.domain, error);
|
|
77
|
+
[ping stop];
|
|
78
|
+
ping = nil;
|
|
79
|
+
}];
|
|
80
|
+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(timeout * NSEC_PER_MSEC)), capturedQueue, ^{
|
|
81
|
+
if (!ping) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
ping = nil;
|
|
85
|
+
DEFINE_NSError(timeoutError, PingUtil_Message_Timeout)
|
|
86
|
+
reject(@(timeoutError.code).stringValue, timeoutError.domain, timeoutError);
|
|
87
|
+
});
|
|
88
|
+
}];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
@end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../src","sources":["NativePing.ts"],"mappings":";;AAAA,SAASA,mBAAmB,QAAQ,cAAc;AAOlD,eAAeA,mBAAmB,CAACC,YAAY,CAAO,mBAAmB,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["NativePing","Ping"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,OAAOA,UAAU,MAAM,iBAAc;AAErC,OAAO,MAAMC,IAAI,GAAGD,UAAU","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { TurboModule } from 'react-native';
|
|
2
|
+
export interface Spec extends TurboModule {
|
|
3
|
+
start(ipAddress: string, option: {
|
|
4
|
+
timeout?: number;
|
|
5
|
+
payloadSize?: number;
|
|
6
|
+
}): Promise<number>;
|
|
7
|
+
}
|
|
8
|
+
declare const _default: Spec;
|
|
9
|
+
export default _default;
|
|
10
|
+
//# sourceMappingURL=NativePing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NativePing.d.ts","sourceRoot":"","sources":["../../../src/NativePing.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAC/F;;AAED,wBAA2E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAEA,eAAO,MAAM,IAAI,6BAAa,CAAC;AAC/B,YAAY,EAAE,IAAI,IAAI,QAAQ,EAAE,MAAM,cAAc,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@onekeyfe/react-native-ping",
|
|
3
|
+
"version": "1.1.57",
|
|
4
|
+
"description": "react-native-ping TurboModule for OneKey",
|
|
5
|
+
"main": "./lib/module/index.js",
|
|
6
|
+
"types": "./lib/typescript/src/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"source": "./src/index.tsx",
|
|
10
|
+
"types": "./lib/typescript/src/index.d.ts",
|
|
11
|
+
"default": "./lib/module/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"src",
|
|
17
|
+
"lib",
|
|
18
|
+
"ios",
|
|
19
|
+
"*.podspec",
|
|
20
|
+
"!ios/build",
|
|
21
|
+
"!**/__tests__",
|
|
22
|
+
"!**/__fixtures__",
|
|
23
|
+
"!**/__mocks__",
|
|
24
|
+
"!**/.*",
|
|
25
|
+
"android"
|
|
26
|
+
],
|
|
27
|
+
"scripts": {
|
|
28
|
+
"prepare": "bob build",
|
|
29
|
+
"typecheck": "tsc",
|
|
30
|
+
"release": "yarn prepare && npm whoami && npm publish --access public"
|
|
31
|
+
},
|
|
32
|
+
"keywords": [
|
|
33
|
+
"react-native",
|
|
34
|
+
"ios",
|
|
35
|
+
"android"
|
|
36
|
+
],
|
|
37
|
+
"repository": {
|
|
38
|
+
"type": "git",
|
|
39
|
+
"url": "git+https://github.com/OneKeyHQ/app-modules/react-native-ping.git"
|
|
40
|
+
},
|
|
41
|
+
"author": "@onekeyhq <huanming@onekey.so> (https://github.com/OneKeyHQ/app-modules)",
|
|
42
|
+
"license": "MIT",
|
|
43
|
+
"bugs": {
|
|
44
|
+
"url": "https://github.com/OneKeyHQ/app-modules/react-native-ping/issues"
|
|
45
|
+
},
|
|
46
|
+
"homepage": "https://github.com/OneKeyHQ/app-modules/react-native-ping#readme",
|
|
47
|
+
"publishConfig": {
|
|
48
|
+
"registry": "https://registry.npmjs.org/"
|
|
49
|
+
},
|
|
50
|
+
"peerDependencies": {
|
|
51
|
+
"react": "*",
|
|
52
|
+
"react-native": "*"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@react-native/babel-preset": "0.83.0",
|
|
56
|
+
"react": "19.2.0",
|
|
57
|
+
"react-native": "0.83.0",
|
|
58
|
+
"react-native-builder-bob": "^0.40.17",
|
|
59
|
+
"typescript": "^5.9.2"
|
|
60
|
+
},
|
|
61
|
+
"react-native-builder-bob": {
|
|
62
|
+
"source": "src",
|
|
63
|
+
"output": "lib",
|
|
64
|
+
"targets": [
|
|
65
|
+
[
|
|
66
|
+
"module",
|
|
67
|
+
{
|
|
68
|
+
"esm": true
|
|
69
|
+
}
|
|
70
|
+
],
|
|
71
|
+
[
|
|
72
|
+
"typescript",
|
|
73
|
+
{
|
|
74
|
+
"project": "tsconfig.build.json"
|
|
75
|
+
}
|
|
76
|
+
]
|
|
77
|
+
]
|
|
78
|
+
},
|
|
79
|
+
"codegenConfig": {
|
|
80
|
+
"name": "RNPingSpec",
|
|
81
|
+
"type": "modules",
|
|
82
|
+
"jsSrcsDir": "src",
|
|
83
|
+
"android": {
|
|
84
|
+
"javaPackageName": "com.rnping"
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|