@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 ADDED
@@ -0,0 +1,19 @@
1
+ require "json"
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = "Ping"
7
+ s.version = package["version"]
8
+ s.summary = package["description"]
9
+ s.homepage = package["homepage"]
10
+ s.license = package["license"]
11
+ s.authors = package["author"]
12
+
13
+ s.platforms = { :ios => min_ios_version_supported }
14
+ s.source = { :git => "https://github.com/OneKeyHQ/app-modules/react-native-ping.git", :tag => "#{s.version}" }
15
+
16
+ s.source_files = "ios/**/*.{h,m,mm,c}"
17
+
18
+ install_modules_dependencies(s)
19
+ end
@@ -0,0 +1,77 @@
1
+ buildscript {
2
+ ext.getExtOrDefault = {name ->
3
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['RNPing_' + name]
4
+ }
5
+
6
+ repositories {
7
+ google()
8
+ mavenCentral()
9
+ }
10
+
11
+ dependencies {
12
+ classpath "com.android.tools.build:gradle:8.7.2"
13
+ // noinspection DifferentKotlinGradleVersion
14
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}"
15
+ }
16
+ }
17
+
18
+
19
+ apply plugin: "com.android.library"
20
+ apply plugin: "kotlin-android"
21
+
22
+ apply plugin: "com.facebook.react"
23
+
24
+ def getExtOrIntegerDefault(name) {
25
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["RNPing_" + name]).toInteger()
26
+ }
27
+
28
+ android {
29
+ namespace "com.rnping"
30
+
31
+ compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
32
+
33
+ defaultConfig {
34
+ minSdkVersion getExtOrIntegerDefault("minSdkVersion")
35
+ targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
36
+ }
37
+
38
+ buildFeatures {
39
+ buildConfig true
40
+ }
41
+
42
+ buildTypes {
43
+ release {
44
+ minifyEnabled false
45
+ }
46
+ }
47
+
48
+ lintOptions {
49
+ disable "GradleCompatible"
50
+ }
51
+
52
+ compileOptions {
53
+ sourceCompatibility JavaVersion.VERSION_1_8
54
+ targetCompatibility JavaVersion.VERSION_1_8
55
+ }
56
+
57
+ sourceSets {
58
+ main {
59
+ java.srcDirs += [
60
+ "generated/java",
61
+ "generated/jni"
62
+ ]
63
+ }
64
+ }
65
+ }
66
+
67
+ repositories {
68
+ mavenCentral()
69
+ google()
70
+ }
71
+
72
+ def kotlin_version = getExtOrDefault("kotlinVersion")
73
+
74
+ dependencies {
75
+ implementation "com.facebook.react:react-android"
76
+ implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
77
+ }
@@ -0,0 +1,37 @@
1
+ package com.rnping
2
+
3
+ import com.facebook.react.bridge.Promise
4
+ import com.facebook.react.bridge.ReactApplicationContext
5
+ import com.facebook.react.bridge.ReadableMap
6
+ import com.facebook.react.module.annotations.ReactModule
7
+ import java.net.InetAddress
8
+
9
+ @ReactModule(name = RNReactNativePingModule.NAME)
10
+ class RNReactNativePingModule(reactContext: ReactApplicationContext) :
11
+ NativeRNReactNativePingSpec(reactContext) {
12
+
13
+ companion object {
14
+ const val NAME = "RNReactNativePing"
15
+ private const val DEFAULT_TIMEOUT_MS = 3000
16
+ }
17
+
18
+ override fun getName(): String = NAME
19
+
20
+ override fun start(ipAddress: String, option: ReadableMap, promise: Promise) {
21
+ Thread {
22
+ try {
23
+ val timeout = if (option.hasKey("timeout")) option.getInt("timeout") else DEFAULT_TIMEOUT_MS
24
+ val startTime = System.currentTimeMillis()
25
+ val reachable = InetAddress.getByName(ipAddress).isReachable(timeout)
26
+ val elapsed = System.currentTimeMillis() - startTime
27
+ if (reachable) {
28
+ promise.resolve(elapsed.toDouble())
29
+ } else {
30
+ promise.reject("PING_TIMEOUT", "Host $ipAddress is not reachable within ${timeout}ms")
31
+ }
32
+ } catch (e: Exception) {
33
+ promise.reject("PING_ERROR", e.message, e)
34
+ }
35
+ }.start()
36
+ }
37
+ }
@@ -0,0 +1,33 @@
1
+ package com.rnping
2
+
3
+ import com.facebook.react.BaseReactPackage
4
+ import com.facebook.react.bridge.NativeModule
5
+ import com.facebook.react.bridge.ReactApplicationContext
6
+ import com.facebook.react.module.model.ReactModuleInfo
7
+ import com.facebook.react.module.model.ReactModuleInfoProvider
8
+ import java.util.HashMap
9
+
10
+ class RNReactNativePingPackage : BaseReactPackage() {
11
+ override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
12
+ return if (name == RNReactNativePingModule.NAME) {
13
+ RNReactNativePingModule(reactContext)
14
+ } else {
15
+ null
16
+ }
17
+ }
18
+
19
+ override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
20
+ return ReactModuleInfoProvider {
21
+ val moduleInfos: MutableMap<String, ReactModuleInfo> = HashMap()
22
+ moduleInfos[RNReactNativePingModule.NAME] = ReactModuleInfo(
23
+ RNReactNativePingModule.NAME,
24
+ RNReactNativePingModule.NAME,
25
+ false, // canOverrideExistingModule
26
+ false, // needsEagerInit
27
+ false, // isCxxModule
28
+ true // isTurboModule
29
+ )
30
+ moduleInfos
31
+ }
32
+ }
33
+ }
@@ -0,0 +1,50 @@
1
+ //
2
+ // GBPing.h
3
+ //
4
+
5
+ #import <Foundation/Foundation.h>
6
+
7
+ #import "GBPingSummary.h"
8
+
9
+ @class GBPingSummary;
10
+ @protocol GBPingDelegate;
11
+
12
+ NS_ASSUME_NONNULL_BEGIN
13
+
14
+ typedef void (^StartupCallback)(BOOL success, NSError *_Nullable error);
15
+
16
+ @interface GBPing : NSObject
17
+
18
+ @property (weak, nonatomic, nullable) id<GBPingDelegate> delegate;
19
+
20
+ @property (copy, nonatomic, nullable) NSString *host;
21
+ @property (assign, atomic) NSTimeInterval pingPeriod;
22
+ @property (assign, atomic) NSTimeInterval timeout;
23
+ @property (assign, atomic) NSUInteger payloadSize;
24
+ @property (assign, atomic) NSUInteger ttl;
25
+ @property (assign, atomic, readonly) BOOL isPinging;
26
+ @property (assign, atomic, readonly) BOOL isReady;
27
+
28
+ @property (assign, atomic) BOOL debug;
29
+
30
+ - (void)setupWithBlock:(StartupCallback)callback;
31
+ - (void)startPingingWithBlock:(void (^)(GBPingSummary *))successBlock fail:(void (^)(NSError *))failBlock;
32
+ - (void)stop;
33
+
34
+ @end
35
+
36
+ @protocol GBPingDelegate <NSObject>
37
+
38
+ @optional
39
+
40
+ - (void)ping:(GBPing *)pinger didFailWithError:(NSError *)error;
41
+
42
+ - (void)ping:(GBPing *)pinger didSendPingWithSummary:(GBPingSummary *)summary;
43
+ - (void)ping:(GBPing *)pinger didFailToSendPingWithSummary:(GBPingSummary *)summary error:(NSError *)error;
44
+ - (void)ping:(GBPing *)pinger didTimeoutWithSummary:(GBPingSummary *)summary;
45
+ - (void)ping:(GBPing *)pinger didReceiveReplyWithSummary:(GBPingSummary *)summary;
46
+ - (void)ping:(GBPing *)pinger didReceiveUnexpectedReplyWithSummary:(GBPingSummary *)summary;
47
+
48
+ @end
49
+
50
+ NS_ASSUME_NONNULL_END