topnic-https 0.2.12 → 0.2.13
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/package.json +2 -1
- package/src/sharing/shareManager.js +26 -8
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "topnic-https",
|
3
|
-
"version": "0.2.
|
3
|
+
"version": "0.2.13",
|
4
4
|
"main": "./src/main/index.js",
|
5
5
|
"type": "commonjs",
|
6
6
|
"scripts": {
|
@@ -96,6 +96,7 @@
|
|
96
96
|
"https": "^1.0.0",
|
97
97
|
"localtunnel": "^2.0.2",
|
98
98
|
"nanoid": "^5.0.8",
|
99
|
+
"ngrok": "^5.0.0-beta.2",
|
99
100
|
"os": "^0.1.2",
|
100
101
|
"path": "^0.12.7",
|
101
102
|
"uuid": "^11.0.3",
|
@@ -1,4 +1,4 @@
|
|
1
|
-
const
|
1
|
+
const ngrok = require('ngrok');
|
2
2
|
const { nanoid } = require('nanoid/non-secure');
|
3
3
|
|
4
4
|
class ShareManager {
|
@@ -6,14 +6,32 @@ class ShareManager {
|
|
6
6
|
this.activeShares = new Map();
|
7
7
|
}
|
8
8
|
|
9
|
-
async
|
9
|
+
async createTunnel(port) {
|
10
10
|
try {
|
11
|
-
const
|
12
|
-
port,
|
13
|
-
|
11
|
+
const url = await ngrok.connect({
|
12
|
+
addr: port,
|
13
|
+
onStatusChange: status => {
|
14
|
+
if (status === 'closed') {
|
15
|
+
console.log('🔄 تم إغلاق النفق');
|
16
|
+
}
|
17
|
+
},
|
18
|
+
onLogEvent: data => {
|
19
|
+
if (data.err) {
|
20
|
+
console.error('❌ خطأ في النفق:', data.err);
|
21
|
+
}
|
22
|
+
}
|
14
23
|
});
|
15
|
-
|
16
|
-
|
24
|
+
|
25
|
+
return { url, disconnect: ngrok.disconnect };
|
26
|
+
} catch (error) {
|
27
|
+
throw new Error(`فشل إنشاء النفق: ${error.message}`);
|
28
|
+
}
|
29
|
+
}
|
30
|
+
|
31
|
+
async createShare(port, duration) {
|
32
|
+
try {
|
33
|
+
const tunnel = await this.createTunnel(port);
|
34
|
+
const shareId = nanoid(6);
|
17
35
|
|
18
36
|
const share = {
|
19
37
|
id: shareId,
|
@@ -44,7 +62,7 @@ class ShareManager {
|
|
44
62
|
throw new Error('لم يتم العثور على المشاركة');
|
45
63
|
}
|
46
64
|
|
47
|
-
await share.tunnel.
|
65
|
+
await share.tunnel.disconnect();
|
48
66
|
this.activeShares.delete(shareId);
|
49
67
|
}
|
50
68
|
|