@cappitolian/local-ip 0.0.9 → 0.0.11
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/{LocalIp.podspec → CappitolianLocalIp.podspec} +1 -1
- package/Package.swift +4 -4
- package/README.md +48 -14
- package/android/src/main/java/com/cappitolian/plugins/localip/LocalIp.java +37 -0
- package/android/src/main/java/com/cappitolian/plugins/localip/LocalIpPlugin.java +26 -18
- package/dist/docs.json +7 -2
- package/dist/esm/definitions.d.ts +4 -0
- package/dist/esm/definitions.js +3 -0
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +9 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/plugin.cjs.js +10 -16
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +12 -20
- package/dist/plugin.js.map +1 -1
- package/ios/Sources/LocalIpPlugin/LocalIp.swift +39 -0
- package/ios/Sources/LocalIpPlugin/LocalIpPlugin.swift +35 -27
- package/ios/Tests/LocalIpPluginPluginTests/LocalIpPluginTests.swift +2 -2
- package/package.json +3 -3
- package/dist/esm/web.d.ts +0 -7
- package/dist/esm/web.js +0 -7
- package/dist/esm/web.js.map +0 -1
package/Package.swift
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
import PackageDescription
|
|
3
3
|
|
|
4
4
|
let package = Package(
|
|
5
|
-
name: "
|
|
5
|
+
name: "CappitolianLocalIp",
|
|
6
6
|
platforms: [.iOS(.v14)],
|
|
7
7
|
products: [
|
|
8
8
|
.library(
|
|
9
|
-
name: "
|
|
9
|
+
name: "CappitolianLocalIp",
|
|
10
10
|
targets: ["LocalIpPlugin"])
|
|
11
11
|
],
|
|
12
12
|
dependencies: [
|
|
@@ -21,8 +21,8 @@ let package = Package(
|
|
|
21
21
|
],
|
|
22
22
|
path: "ios/Sources/LocalIpPlugin"),
|
|
23
23
|
.testTarget(
|
|
24
|
-
name: "
|
|
24
|
+
name: "LocalIpTests",
|
|
25
25
|
dependencies: ["LocalIpPlugin"],
|
|
26
|
-
path: "ios/Tests/
|
|
26
|
+
path: "ios/Tests/LocalIpTests")
|
|
27
27
|
]
|
|
28
28
|
)
|
package/README.md
CHANGED
|
@@ -1,33 +1,67 @@
|
|
|
1
1
|
# @cappitolian/local-ip
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A Capacitor plugin to retrieve the device's local IP address.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- Get the local IP address of your device on iOS, Android, and Web.
|
|
10
|
+
- Simple API, returns an object with the IP address.
|
|
11
|
+
- Tested with **Capacitor 7** and **Ionic 7**.
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
6
16
|
|
|
7
17
|
```bash
|
|
8
18
|
npm install @cappitolian/local-ip
|
|
9
19
|
npx cap sync
|
|
10
20
|
```
|
|
11
21
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
<docgen-index>
|
|
22
|
+
---
|
|
15
23
|
|
|
16
|
-
|
|
24
|
+
## Usage
|
|
17
25
|
|
|
18
|
-
|
|
26
|
+
### Import
|
|
19
27
|
|
|
20
|
-
|
|
21
|
-
|
|
28
|
+
```typescript
|
|
29
|
+
import LocalIp from '@cappitolian/local-ip';
|
|
30
|
+
```
|
|
22
31
|
|
|
23
|
-
###
|
|
32
|
+
### Get Local IP
|
|
24
33
|
|
|
25
34
|
```typescript
|
|
26
|
-
getLocalIp() =>
|
|
35
|
+
LocalIp.getLocalIp().then(result => {
|
|
36
|
+
console.log('Device Local IP:', result.ip);
|
|
37
|
+
});
|
|
27
38
|
```
|
|
28
39
|
|
|
29
|
-
|
|
40
|
+
- The plugin returns a Promise that resolves to an object like: `{ ip: string }`.
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## Platforms
|
|
45
|
+
|
|
46
|
+
- **iOS** (Swift)
|
|
47
|
+
- **Android** (Java)
|
|
48
|
+
- **Web** (returns `"0.0.0.0"` as placeholder)
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## Requirements
|
|
53
|
+
|
|
54
|
+
- [Capacitor 7](https://capacitorjs.com/)
|
|
55
|
+
- [Ionic 7](https://ionicframework.com/) (optional, but tested)
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## License
|
|
60
|
+
|
|
61
|
+
MIT
|
|
62
|
+
|
|
63
|
+
---
|
|
30
64
|
|
|
31
|
-
|
|
65
|
+
## Support
|
|
32
66
|
|
|
33
|
-
|
|
67
|
+
If you have any issues or feature requests, please open an issue on the repository.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// package com.cappitolian.plugins.localip;
|
|
2
|
+
|
|
3
|
+
// import android.util.Log;
|
|
4
|
+
|
|
5
|
+
// public class LocalIp {
|
|
6
|
+
|
|
7
|
+
// public String echo(String value) {
|
|
8
|
+
// Log.i("Echo", value);
|
|
9
|
+
// return value;
|
|
10
|
+
// }
|
|
11
|
+
// }
|
|
12
|
+
|
|
13
|
+
package com.cappitolian.plugins.localip;
|
|
14
|
+
|
|
15
|
+
import java.net.Inet4Address;
|
|
16
|
+
import java.net.NetworkInterface;
|
|
17
|
+
import java.util.Enumeration;
|
|
18
|
+
|
|
19
|
+
public class LocalIp {
|
|
20
|
+
public String getLocalIp() throws Exception {
|
|
21
|
+
String localIp = null;
|
|
22
|
+
Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
|
|
23
|
+
while (interfaces.hasMoreElements()) {
|
|
24
|
+
NetworkInterface intf = interfaces.nextElement();
|
|
25
|
+
Enumeration<java.net.InetAddress> addrs = intf.getInetAddresses();
|
|
26
|
+
while (addrs.hasMoreElements()) {
|
|
27
|
+
java.net.InetAddress addr = addrs.nextElement();
|
|
28
|
+
if (!addr.isLoopbackAddress() && addr instanceof Inet4Address) {
|
|
29
|
+
localIp = addr.getHostAddress();
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (localIp != null) break;
|
|
34
|
+
}
|
|
35
|
+
return localIp;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -1,3 +1,26 @@
|
|
|
1
|
+
// package com.cappitolian.plugins.localip;
|
|
2
|
+
|
|
3
|
+
// import com.getcapacitor.JSObject;
|
|
4
|
+
// import com.getcapacitor.Plugin;
|
|
5
|
+
// import com.getcapacitor.PluginCall;
|
|
6
|
+
// import com.getcapacitor.PluginMethod;
|
|
7
|
+
// import com.getcapacitor.annotation.CapacitorPlugin;
|
|
8
|
+
|
|
9
|
+
// @CapacitorPlugin(name = "LocalIp")
|
|
10
|
+
// public class LocalIpPlugin extends Plugin {
|
|
11
|
+
|
|
12
|
+
// private LocalIp implementation = new LocalIp();
|
|
13
|
+
|
|
14
|
+
// @PluginMethod
|
|
15
|
+
// public void echo(PluginCall call) {
|
|
16
|
+
// String value = call.getString("value");
|
|
17
|
+
|
|
18
|
+
// JSObject ret = new JSObject();
|
|
19
|
+
// ret.put("value", implementation.echo(value));
|
|
20
|
+
// call.resolve(ret);
|
|
21
|
+
// }
|
|
22
|
+
// }
|
|
23
|
+
|
|
1
24
|
package com.cappitolian.plugins.localip;
|
|
2
25
|
|
|
3
26
|
import com.getcapacitor.Plugin;
|
|
@@ -6,29 +29,14 @@ import com.getcapacitor.JSObject;
|
|
|
6
29
|
import com.getcapacitor.PluginMethod;
|
|
7
30
|
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
8
31
|
|
|
9
|
-
import java.net.Inet4Address;
|
|
10
|
-
import java.net.NetworkInterface;
|
|
11
|
-
import java.util.Enumeration;
|
|
12
|
-
|
|
13
32
|
@CapacitorPlugin(name = "LocalIp")
|
|
14
33
|
public class LocalIpPlugin extends Plugin {
|
|
34
|
+
private LocalIp implementation = new LocalIp();
|
|
35
|
+
|
|
15
36
|
@PluginMethod
|
|
16
37
|
public void getLocalIp(PluginCall call) {
|
|
17
38
|
try {
|
|
18
|
-
String localIp =
|
|
19
|
-
Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
|
|
20
|
-
while (interfaces.hasMoreElements()) {
|
|
21
|
-
NetworkInterface intf = interfaces.nextElement();
|
|
22
|
-
Enumeration<java.net.InetAddress> addrs = intf.getInetAddresses();
|
|
23
|
-
while (addrs.hasMoreElements()) {
|
|
24
|
-
java.net.InetAddress addr = addrs.nextElement();
|
|
25
|
-
if (!addr.isLoopbackAddress() && addr instanceof Inet4Address) {
|
|
26
|
-
localIp = addr.getHostAddress();
|
|
27
|
-
break;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
if (localIp != null) break;
|
|
31
|
-
}
|
|
39
|
+
String localIp = implementation.getLocalIp();
|
|
32
40
|
if (localIp != null) {
|
|
33
41
|
JSObject ret = new JSObject();
|
|
34
42
|
ret.put("ip", localIp);
|
package/dist/docs.json
CHANGED
|
@@ -10,8 +10,13 @@
|
|
|
10
10
|
"signature": "() => Promise<{ ip: string; }>",
|
|
11
11
|
"parameters": [],
|
|
12
12
|
"returns": "Promise<{ ip: string; }>",
|
|
13
|
-
"tags": [
|
|
14
|
-
|
|
13
|
+
"tags": [
|
|
14
|
+
{
|
|
15
|
+
"name": "returns",
|
|
16
|
+
"text": "A promise resolving with an object containing the IP address."
|
|
17
|
+
}
|
|
18
|
+
],
|
|
19
|
+
"docs": "Gets the local IP address of the device.",
|
|
15
20
|
"complexTypes": [],
|
|
16
21
|
"slug": "getlocalip"
|
|
17
22
|
}
|
package/dist/esm/definitions.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface LocalIpPlugin {\n getLocalIp(): Promise<{ ip: string }>;\n}"]}
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAAA,mCAAmC;AACnC,kEAAkE;AAClE,IAAI","sourcesContent":["// export interface LocalIpPlugin {\n// echo(options: { value: string }): Promise<{ value: string }>;\n// }\n\nexport interface LocalIpPlugin {\n /**\n * Gets the local IP address of the device.\n * @returns A promise resolving with an object containing the IP address.\n */\n getLocalIp(): Promise<{ ip: string }>;\n}"]}
|
package/dist/esm/index.d.ts
CHANGED
package/dist/esm/index.js
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
+
// import { registerPlugin } from '@capacitor/core';
|
|
2
|
+
// import type { LocalIpPlugin } from './definitions';
|
|
3
|
+
// const LocalIp = registerPlugin<LocalIpPlugin>('LocalIp', {
|
|
4
|
+
// web: () => import('./web').then((m) => new m.LocalIpWeb()),
|
|
5
|
+
// });
|
|
6
|
+
// export * from './definitions';
|
|
7
|
+
// export { LocalIp };
|
|
1
8
|
import { registerPlugin } from '@capacitor/core';
|
|
2
|
-
const LocalIp = registerPlugin('LocalIp'
|
|
3
|
-
web: () => import('./web').then(m => new m.LocalIpWeb()),
|
|
4
|
-
});
|
|
9
|
+
const LocalIp = registerPlugin('LocalIp');
|
|
5
10
|
export * from './definitions';
|
|
6
|
-
export
|
|
11
|
+
export default LocalIp;
|
|
7
12
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAGjD,MAAM,OAAO,GAAG,cAAc,CAAgB,SAAS,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,oDAAoD;AAEpD,sDAAsD;AAEtD,6DAA6D;AAC7D,gEAAgE;AAChE,MAAM;AAEN,iCAAiC;AACjC,sBAAsB;AAEtB,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAGjD,MAAM,OAAO,GAAG,cAAc,CAAgB,SAAS,CAAC,CAAC;AAEzD,cAAc,eAAe,CAAC;AAC9B,eAAe,OAAO,CAAC","sourcesContent":["// import { registerPlugin } from '@capacitor/core';\n\n// import type { LocalIpPlugin } from './definitions';\n\n// const LocalIp = registerPlugin<LocalIpPlugin>('LocalIp', {\n// web: () => import('./web').then((m) => new m.LocalIpWeb()),\n// });\n\n// export * from './definitions';\n// export { LocalIp };\n\nimport { registerPlugin } from '@capacitor/core';\nimport type { LocalIpPlugin } from './definitions';\n\nconst LocalIp = registerPlugin<LocalIpPlugin>('LocalIp');\n\nexport * from './definitions';\nexport default LocalIp;\n"]}
|
package/dist/plugin.cjs.js
CHANGED
|
@@ -2,20 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
var core = require('@capacitor/core');
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
var web = /*#__PURE__*/Object.freeze({
|
|
16
|
-
__proto__: null,
|
|
17
|
-
LocalIpWeb: LocalIpWeb
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
exports.LocalIp = LocalIp;
|
|
5
|
+
// import { registerPlugin } from '@capacitor/core';
|
|
6
|
+
// import type { LocalIpPlugin } from './definitions';
|
|
7
|
+
// const LocalIp = registerPlugin<LocalIpPlugin>('LocalIp', {
|
|
8
|
+
// web: () => import('./web').then((m) => new m.LocalIpWeb()),
|
|
9
|
+
// });
|
|
10
|
+
// export * from './definitions';
|
|
11
|
+
// export { LocalIp };
|
|
12
|
+
const LocalIp = core.registerPlugin('LocalIp');
|
|
13
|
+
|
|
14
|
+
module.exports = LocalIp;
|
|
21
15
|
//# sourceMappingURL=plugin.cjs.js.map
|
package/dist/plugin.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.cjs.js","sources":["esm/index.js"
|
|
1
|
+
{"version":3,"file":"plugin.cjs.js","sources":["esm/index.js"],"sourcesContent":["// import { registerPlugin } from '@capacitor/core';\n// import type { LocalIpPlugin } from './definitions';\n// const LocalIp = registerPlugin<LocalIpPlugin>('LocalIp', {\n// web: () => import('./web').then((m) => new m.LocalIpWeb()),\n// });\n// export * from './definitions';\n// export { LocalIp };\nimport { registerPlugin } from '@capacitor/core';\nconst LocalIp = registerPlugin('LocalIp');\nexport * from './definitions';\nexport default LocalIp;\n//# sourceMappingURL=index.js.map"],"names":["registerPlugin"],"mappings":";;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AAEK,MAAC,OAAO,GAAGA,mBAAc,CAAC,SAAS;;;;"}
|
package/dist/plugin.js
CHANGED
|
@@ -1,24 +1,16 @@
|
|
|
1
|
-
var capacitorLocalIpPlugin = (function (
|
|
2
|
-
|
|
1
|
+
var capacitorLocalIpPlugin = (function (core) {
|
|
2
|
+
'use strict';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
// import { registerPlugin } from '@capacitor/core';
|
|
5
|
+
// import type { LocalIpPlugin } from './definitions';
|
|
6
|
+
// const LocalIp = registerPlugin<LocalIpPlugin>('LocalIp', {
|
|
7
|
+
// web: () => import('./web').then((m) => new m.LocalIpWeb()),
|
|
8
|
+
// });
|
|
9
|
+
// export * from './definitions';
|
|
10
|
+
// export { LocalIp };
|
|
11
|
+
const LocalIp = core.registerPlugin('LocalIp');
|
|
7
12
|
|
|
8
|
-
|
|
9
|
-
async getLocalIp() {
|
|
10
|
-
return { ip: '' }; // Not implemented for web
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
+
return LocalIp;
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
__proto__: null,
|
|
16
|
-
LocalIpWeb: LocalIpWeb
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
exports.LocalIp = LocalIp;
|
|
20
|
-
|
|
21
|
-
return exports;
|
|
22
|
-
|
|
23
|
-
})({}, capacitorExports);
|
|
15
|
+
})(capacitorExports);
|
|
24
16
|
//# sourceMappingURL=plugin.js.map
|
package/dist/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sources":["esm/index.js"
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["esm/index.js"],"sourcesContent":["// import { registerPlugin } from '@capacitor/core';\n// import type { LocalIpPlugin } from './definitions';\n// const LocalIp = registerPlugin<LocalIpPlugin>('LocalIp', {\n// web: () => import('./web').then((m) => new m.LocalIpWeb()),\n// });\n// export * from './definitions';\n// export { LocalIp };\nimport { registerPlugin } from '@capacitor/core';\nconst LocalIp = registerPlugin('LocalIp');\nexport * from './definitions';\nexport default LocalIp;\n//# sourceMappingURL=index.js.map"],"names":["registerPlugin"],"mappings":";;;CAAA;CACA;CACA;CACA;CACA;CACA;CACA;AAEK,OAAC,OAAO,GAAGA,mBAAc,CAAC,SAAS;;;;;;;;"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// import Foundation
|
|
2
|
+
|
|
3
|
+
// @objc public class LocalIp: NSObject {
|
|
4
|
+
// @objc public func echo(_ value: String) -> String {
|
|
5
|
+
// print(value)
|
|
6
|
+
// return value
|
|
7
|
+
// }
|
|
8
|
+
// }
|
|
9
|
+
|
|
10
|
+
import Foundation
|
|
11
|
+
|
|
12
|
+
@objc public class LocalIp: NSObject {
|
|
13
|
+
@objc public func getLocalIp() -> String? {
|
|
14
|
+
var address: String?
|
|
15
|
+
|
|
16
|
+
var ifaddr: UnsafeMutablePointer<ifaddrs>?
|
|
17
|
+
if getifaddrs(&ifaddr) == 0 {
|
|
18
|
+
var ptr = ifaddr
|
|
19
|
+
while ptr != nil {
|
|
20
|
+
defer { ptr = ptr?.pointee.ifa_next }
|
|
21
|
+
guard let interface = ptr?.pointee else { continue }
|
|
22
|
+
let addrFamily = interface.ifa_addr.pointee.sa_family
|
|
23
|
+
if addrFamily == UInt8(AF_INET) {
|
|
24
|
+
if let name = String(validatingUTF8: interface.ifa_name),
|
|
25
|
+
name == "en0" { // WiFi interface
|
|
26
|
+
var hostname = [CChar](repeating: 0, count: Int(NI_MAXHOST))
|
|
27
|
+
getnameinfo(interface.ifa_addr, socklen_t(interface.ifa_addr.pointee.sa_len),
|
|
28
|
+
&hostname, socklen_t(hostname.count),
|
|
29
|
+
nil, socklen_t(0), NI_NUMERICHOST)
|
|
30
|
+
address = String(cString: hostname)
|
|
31
|
+
break
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
freeifaddrs(ifaddr)
|
|
36
|
+
}
|
|
37
|
+
return address
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -1,34 +1,42 @@
|
|
|
1
|
+
// import Foundation
|
|
2
|
+
// import Capacitor
|
|
3
|
+
|
|
4
|
+
// /**
|
|
5
|
+
// * Please read the Capacitor iOS Plugin Development Guide
|
|
6
|
+
// * here: https://capacitorjs.com/docs/plugins/ios
|
|
7
|
+
// */
|
|
8
|
+
// @objc(LocalIpPlugin)
|
|
9
|
+
// public class LocalIpPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
10
|
+
// public let identifier = "LocalIpPlugin"
|
|
11
|
+
// public let jsName = "LocalIp"
|
|
12
|
+
// public let pluginMethods: [CAPPluginMethod] = [
|
|
13
|
+
// CAPPluginMethod(name: "echo", returnType: CAPPluginReturnPromise)
|
|
14
|
+
// ]
|
|
15
|
+
// private let implementation = LocalIp()
|
|
16
|
+
|
|
17
|
+
// @objc func echo(_ call: CAPPluginCall) {
|
|
18
|
+
// let value = call.getString("value") ?? ""
|
|
19
|
+
// call.resolve([
|
|
20
|
+
// "value": implementation.echo(value)
|
|
21
|
+
// ])
|
|
22
|
+
// }
|
|
23
|
+
// }
|
|
24
|
+
|
|
1
25
|
import Foundation
|
|
2
26
|
import Capacitor
|
|
3
27
|
|
|
4
28
|
@objc(LocalIpPlugin)
|
|
5
|
-
public class LocalIpPlugin: CAPPlugin {
|
|
6
|
-
|
|
7
|
-
|
|
29
|
+
public class LocalIpPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
30
|
+
public let identifier = "LocalIpPlugin"
|
|
31
|
+
public let jsName = "LocalIp"
|
|
32
|
+
public let pluginMethods: [CAPPluginMethod] = [
|
|
33
|
+
CAPPluginMethod(name: "getLocalIp", returnType: CAPPluginReturnPromise)
|
|
34
|
+
]
|
|
35
|
+
private let implementation = LocalIp()
|
|
8
36
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
while ptr != nil {
|
|
13
|
-
defer { ptr = ptr?.pointee.ifa_next }
|
|
14
|
-
guard let interface = ptr?.pointee else { continue }
|
|
15
|
-
let addrFamily = interface.ifa_addr.pointee.sa_family
|
|
16
|
-
if addrFamily == UInt8(AF_INET) {
|
|
17
|
-
if let name = String(validatingUTF8: interface.ifa_name),
|
|
18
|
-
name == "en0" { // WiFi interface
|
|
19
|
-
var hostname = [CChar](repeating: 0, count: Int(NI_MAXHOST))
|
|
20
|
-
getnameinfo(interface.ifa_addr, socklen_t(interface.ifa_addr.pointee.sa_len),
|
|
21
|
-
&hostname, socklen_t(hostname.count),
|
|
22
|
-
nil, socklen_t(0), NI_NUMERICHOST)
|
|
23
|
-
address = String(cString: hostname)
|
|
24
|
-
break
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
freeifaddrs(ifaddr)
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if let ip = address {
|
|
37
|
+
@objc func getLocalIp(_ call: CAPPluginCall) {
|
|
38
|
+
print("LocalIpPlugin.getLocalIp called!")
|
|
39
|
+
if let ip = implementation.getLocalIp() {
|
|
32
40
|
call.resolve([
|
|
33
41
|
"ip": ip
|
|
34
42
|
])
|
|
@@ -36,4 +44,4 @@ public class LocalIpPlugin: CAPPlugin {
|
|
|
36
44
|
call.reject("Unable to determine local IP address")
|
|
37
45
|
}
|
|
38
46
|
}
|
|
39
|
-
}
|
|
47
|
+
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import XCTest
|
|
2
2
|
@testable import LocalIpPlugin
|
|
3
3
|
|
|
4
|
-
class
|
|
4
|
+
class LocalIpTests: XCTestCase {
|
|
5
5
|
func testEcho() {
|
|
6
6
|
// This is an example of a functional test case for a plugin.
|
|
7
7
|
// Use XCTAssert and related functions to verify your tests produce the correct results.
|
|
8
8
|
|
|
9
|
-
let implementation =
|
|
9
|
+
let implementation = LocalIp()
|
|
10
10
|
let value = "Hello, World!"
|
|
11
11
|
let result = implementation.echo(value)
|
|
12
12
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cappitolian/local-ip",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.11",
|
|
4
4
|
"description": "Retrieve local IP address from native device",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"ios/Sources",
|
|
14
14
|
"ios/Tests",
|
|
15
15
|
"Package.swift",
|
|
16
|
-
"
|
|
16
|
+
"CappitolianLocalIp.podspec"
|
|
17
17
|
],
|
|
18
18
|
"author": "Cappitolian",
|
|
19
19
|
"license": "MIT",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
],
|
|
32
32
|
"scripts": {
|
|
33
33
|
"verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
|
|
34
|
-
"verify:ios": "xcodebuild -scheme
|
|
34
|
+
"verify:ios": "xcodebuild -scheme CappitolianLocalIp -destination generic/platform=iOS",
|
|
35
35
|
"verify:android": "cd android && ./gradlew clean build test && cd ..",
|
|
36
36
|
"verify:web": "npm run build",
|
|
37
37
|
"lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
|
package/dist/esm/web.d.ts
DELETED
package/dist/esm/web.js
DELETED
package/dist/esm/web.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG5C,MAAM,OAAO,UAAW,SAAQ,SAAS;IACvC,KAAK,CAAC,UAAU;QACd,OAAO,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,0BAA0B;IAC/C,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\nimport type { LocalIpPlugin } from './definitions';\n\nexport class LocalIpWeb extends WebPlugin implements LocalIpPlugin {\n async getLocalIp(): Promise<{ ip: string }> {\n return { ip: '' }; // Not implemented for web\n }\n}"]}
|