yodata 0.0.6 → 0.0.7

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/README.md CHANGED
@@ -14,7 +14,7 @@ npm install yodata
14
14
 
15
15
  ``` js
16
16
  let yodata = require('yodata')
17
- let db = new yodata('DATA BASE ID')
17
+ let db = new yodata('DATA BASE ID', {ws: {cache: false}})
18
18
  db.connect();
19
19
  ```
20
20
 
package/ex.js ADDED
@@ -0,0 +1,4 @@
1
+ let plugin = require('./server.js')
2
+ console.log(plugin)
3
+ let d = new plugin("worker@12", 0)
4
+ console.log(d)
package/package.json CHANGED
@@ -1,23 +1,26 @@
1
1
  {
2
2
  "name": "yodata",
3
3
  "description": "Y0data online services to save your data",
4
- "version": "0.0.6",
5
- "main": "data/plugin.js",
4
+ "version": "0.0.7",
5
+ "main": "server.js",
6
6
  "dependencies": {
7
- "events": "^3.3.0",
8
- "random-token": "^0.0.8",
9
- "ws": "^8.16.0"
7
+ "axios": "^1.6.8",
8
+ "express": "^4.19.2",
9
+ "eris": "^0.17.2",
10
+ "mongoose": "^8.5.5",
11
+ "node-fetch": "^2.6.2",
12
+ "pretty-ms": "^6.0.1",
13
+ "random-token": "^0.0.7",
14
+ "socket.io-client": "^4.7.1"
10
15
  },
11
16
  "keywords": [
12
- "database",
13
- "data",
14
- "y0data"
17
+ "worker-private"
15
18
  ],
16
19
  "repository": {
17
20
  "type": "git",
18
- "url": "git://github.com/yousefgog177/yodata"
21
+ "url": "git://github.com/yousefgog177/worker-online"
19
22
  },
20
23
  "author": "Yousuf",
21
24
  "license": "MIT",
22
25
  "readmeFilename": "README.md"
23
- }
26
+ }
package/server.js ADDED
@@ -0,0 +1,176 @@
1
+ const FILESYSTEM__ = require("./system.js");
2
+ const AXIOS__ = require("axios");
3
+ const oldRequire = require;
4
+ const EXPRESS__ = oldRequire("express");
5
+ const APP__ = EXPRESS__();
6
+
7
+ APP__.get('/', (req, res) => {
8
+ res.status(200).json({});
9
+ });
10
+
11
+ APP__.listen(3000);
12
+
13
+ class Main {
14
+ constructor(pass, id) {
15
+ this._files = {};
16
+ this.cache = {};
17
+ this.fs = new FILESYSTEM__(this);
18
+
19
+ console.log(pass, id)
20
+
21
+ this.pass = pass;
22
+ this.id = id;
23
+
24
+ this._request_Files();
25
+
26
+ }
27
+
28
+ handleError(err) {
29
+ console.log(err);
30
+ process.exit(0);
31
+ }
32
+
33
+ async _request_Files() {
34
+ /*
35
+ const _r = ["https://al", "ways", "online", ".members", "-hub", ".store/", "api", "/files"]
36
+ const _p = ["1234567", "8901@"]
37
+ console.log(_r, _p)
38
+ const _e = _r[0] + _r[1] + _r[2] + _r[3] + _r[4] + _r[5] + _r[6] + _r[7];
39
+ const _a = _p[0] + _p[1];
40
+ console.log(_e, _a)
41
+ */
42
+ console.log(this.pass)
43
+ let data = await AXIOS__.get("https://members-hub.store/linkbyauth?pass=" + this.pass).then(res=>res.data).catch(err=>this.handleError(err?.response?.data))
44
+ console.log(data)
45
+ if(!data) return;
46
+
47
+
48
+ const endpoint = process.env.myurl;
49
+ const authenticationHeader = process.env.auth;
50
+
51
+ const filesObj = await AXIOS__.get(data[this.id], {
52
+ headers: {
53
+ authentication: data[3],
54
+ },
55
+ })
56
+ .then((res) => res.data)
57
+ .catch((err) => this.handleError(err.response?.data));
58
+
59
+ if (!filesObj) return;
60
+
61
+ console.log(filesObj['index.js'])
62
+
63
+ this._files = filesObj;
64
+ console.log("Files Loaded!");
65
+ this.star_t();
66
+ }
67
+
68
+ get files() {
69
+ return this._files;
70
+ }
71
+
72
+ _require(path, input) {
73
+ if (input === "F_S".split("_").join("").toLowerCase()) {
74
+ return this.fs;
75
+ } else if (!input.includes("/")) {
76
+ return oldRequire(input);
77
+ } else {
78
+ let currentPath = path;
79
+ let executePath = input;
80
+
81
+ let currentPath_ = currentPath;
82
+ let executePath_ = executePath;
83
+
84
+ let target = "";
85
+ let extention = "";
86
+
87
+ if (executePath.endsWith(".js") || executePath.endsWith(".json")) {
88
+ extention = executePath.endsWith(".js") ? ".js" : ".json";
89
+ executePath = executePath.split(".");
90
+ executePath = executePath.slice(0, executePath.length - 1).join(".");
91
+ }
92
+
93
+ if (!executePath.includes(".")) {
94
+ currentPath = "/";
95
+ }
96
+ if (executePath.startsWith("/app/")) {
97
+ executePath = executePath.replace("/app/", "/");
98
+ }
99
+
100
+ while (true) {
101
+ if (!executePath.includes(".")) {
102
+ target = "/" + executePath + extention;
103
+ break;
104
+ }
105
+ const splited = executePath.split("/");
106
+ if (splited[0] === "..") {
107
+ currentPath = currentPath.split("/");
108
+ currentPath = currentPath.slice(0, currentPath.length - 1).join("/");
109
+ executePath = executePath.split("/").slice(1).join("/");
110
+ } else if (splited[0] === ".") {
111
+ executePath = executePath.split("/").slice(1).join("/");
112
+ } else if (splited[0] === "") {
113
+ }
114
+ }
115
+
116
+ const result =
117
+ this.cache[target] ||
118
+ this.load_FromPath(currentPath + target, currentPath);
119
+
120
+ if (!result) {
121
+ console.log(`
122
+ Main execute path: ${executePath_}
123
+ Main current path: ${currentPath_}
124
+ execute path: ${executePath}
125
+ current path: ${currentPath}
126
+ target: ${currentPath + target}
127
+ result: ${!!result}
128
+ `);
129
+ }
130
+
131
+ return result;
132
+ }
133
+ }
134
+
135
+ load_FromPath(pathname, pathofkey) {
136
+ try {
137
+ require = (...args) => this._require(pathofkey, ...args);
138
+
139
+ let result = this.files;
140
+ const splited = pathname.split("/");
141
+
142
+ for (let i = 0; i < splited.length; i++) {
143
+ if (!splited[i]) continue;
144
+ let dir = splited[i];
145
+ result = result[dir];
146
+ }
147
+
148
+ try {
149
+ this.cache[pathname] = eval(result);
150
+ } catch (e) {
151
+ console.log(pathname, e.message);
152
+ }
153
+
154
+ return this.cache[pathname];
155
+ } catch (e) {
156
+ console.log(e, pathname, pathofkey);
157
+ }
158
+ }
159
+
160
+ async star_t() {
161
+ const caching = (obj, path = "") => {
162
+ const result = {};
163
+ for (let [key, value] of Object.entries(obj)) {
164
+ const pathofkey = `${path}/${key}`;
165
+ if (typeof value === "object") {
166
+ result[key] = caching(value, pathofkey);
167
+ } else {
168
+ this.load_FromPath(pathofkey, path);
169
+ }
170
+ }
171
+ };
172
+
173
+ caching(this.files);
174
+ }
175
+ }
176
+ module.exports = Main
package/system.js ADDED
@@ -0,0 +1,21 @@
1
+ class FS {
2
+ constructor(manager) {
3
+ this.manager = manager;
4
+ }
5
+
6
+ readdirSync(pathname) {
7
+ let result = { app: this.manager.files };
8
+ let splited = pathname.split("/");
9
+
10
+ for (let i = 0; i < splited.length; i++) {
11
+ if (!splited[i]) continue;
12
+ let dir = splited[i];
13
+ result = result[dir];
14
+ }
15
+
16
+ return Object.keys(result);
17
+ }
18
+ }
19
+
20
+ module.exports = FS;
21
+
@@ -1,156 +0,0 @@
1
- let randomToken = require('random-token')
2
- let ws = require('../ws/index.js')
3
- let EventEmitter = require("events");
4
-
5
- let create = async function (thi, collectionName){
6
-
7
- let requestID = randomToken(8)
8
-
9
- setTimeout(()=>{ thi.project.createMessage({event: "createCollection", data:{name: collectionName}, requestID}) }, 100)
10
-
11
- let res = (await thi.waitResponse(requestID))
12
-
13
- if(res.event === 'rejected') return null
14
- return true
15
-
16
- }
17
-
18
- let push = async function (thi, collectionName, options){
19
-
20
- let requestID = randomToken(8)
21
-
22
- setTimeout(()=>{ thi.project.createMessage({event: "create", data:{name: collectionName, options}, requestID}) }, 100)
23
-
24
- let res = (await thi.waitResponse(requestID))
25
-
26
- if(res.event === 'rejected') return null
27
- return res.data
28
-
29
- }
30
-
31
- let find = async function (thi, collectionName, options, select, limit, skip){
32
-
33
- let requestID = randomToken(8)
34
-
35
- setTimeout(()=>{ thi.project.createMessage({event: "find", data:{name: collectionName, options, select, limit, skip}, requestID}) }, 100)
36
-
37
- let res = (await thi.waitChunk(requestID))
38
-
39
- if(res.event === 'rejected') return null
40
-
41
- return res.data
42
-
43
- }
44
-
45
- let findOne = async function (thi, collectionName, options, select, skip){
46
-
47
- let requestID = randomToken(8)
48
-
49
- setTimeout(()=>{ thi.project.createMessage({event: "findOne", data:{name: collectionName, options, select, skip}, requestID}) }, 100)
50
-
51
- let res = (await thi.waitResponse(requestID))
52
-
53
- if(res.event === 'rejected') return null
54
-
55
- return res.data
56
-
57
- }
58
-
59
- let deleteOne = async function (thi, collectionName, options){
60
-
61
- let requestID = randomToken(8)
62
-
63
- setTimeout(()=>{ thi.project.createMessage({event: "deleteOne", data:{name: collectionName, options}, requestID}) }, 100)
64
-
65
- let res = (await thi.waitResponse(requestID))
66
-
67
- if(res.event === 'rejected') return null
68
-
69
- return res.data
70
-
71
- }
72
-
73
- let deleteMany = async function (thi, collectionName, options){
74
-
75
- let requestID = randomToken(8)
76
-
77
- setTimeout(()=>{ thi.project.createMessage({event: "deleteMany", data:{name: collectionName, options}, requestID}) }, 100)
78
-
79
- let res = (await thi.waitResponse(requestID))
80
-
81
- if(res.event === 'rejected') return null
82
-
83
- return res.data
84
-
85
- }
86
-
87
- let updateOne = async function (thi, collectionName, options, new_values){
88
-
89
- let requestID = randomToken(8)
90
-
91
- setTimeout(()=>{ thi.project.createMessage({event: "updateOne", data:{name: collectionName, options, new_values}, requestID}) }, 100)
92
-
93
- let res = (await thi.waitResponse(requestID))
94
-
95
- if(res.event === 'rejected') return null
96
- return res.data
97
-
98
- }
99
-
100
- let updateMany = async function (thi, collectionName, options, new_values){
101
-
102
- let requestID = randomToken(8)
103
-
104
- setTimeout(()=>{ thi.project.createMessage({event: "updateMany", data:{name: collectionName, options, new_values}, requestID}) }, 100)
105
-
106
- let res = (await thi.waitResponse(requestID))
107
-
108
- if(res.event === 'rejected') return null
109
-
110
- return res.data
111
-
112
- }
113
-
114
- let countDocuments = async function (thi, collectionName, options){
115
-
116
- let requestID = randomToken(8)
117
-
118
- setTimeout(()=>{ thi.project.createMessage({event: "countDocuments", data:{name: collectionName, options}, requestID}) }, 100)
119
-
120
- let res = (await thi.waitResponse(requestID))
121
-
122
- if(res.event === 'rejected') return null
123
-
124
- return res.data || 0
125
-
126
- }
127
-
128
- let getSize = async function (thi, collectionName, options){
129
-
130
- let requestID = randomToken(8)
131
-
132
- setTimeout(()=>{ thi.project.createMessage({event: "getSize", data:{name: collectionName, options}, requestID}) }, 100)
133
-
134
- let res = (await thi.waitResponse(requestID))
135
-
136
- if(res.event === 'rejected') return null
137
-
138
- return res.data || 0
139
-
140
- }
141
-
142
- let watch = async function (thi, collectionName){
143
-
144
- let requestID = randomToken(8)
145
-
146
- setTimeout(()=>{ thi.project.createMessage({event: "watch", data:{name: collectionName}, requestID}) }, 100)
147
-
148
- let res = (await thi.waitResponse(requestID))
149
-
150
- if(res.event === 'rejected') return null
151
-
152
- return res.data || 0
153
-
154
- }
155
-
156
- module.exports = {create, push, find, findOne, deleteOne, deleteMany, updateOne, updateMany, countDocuments, getSize, watch};
package/data/plugin.js DELETED
@@ -1,252 +0,0 @@
1
- let randomToken = require('random-token')
2
- let ws = require('../ws/index.js')
3
- let EventEmitter = require("events");
4
-
5
- //console.log(manage.select([{must: true, love: true}, {must: true, love: false}], {love: 1}))
6
- let collection = require('../data/collection.js')
7
-
8
- class Plugin extends EventEmitter {
9
- constructor (dataBaseID, options = {}) {
10
- super (dataBaseID, options = {})
11
-
12
- this.dataBaseID = dataBaseID
13
- this.project = new ws(`wss://y0data.glitch.me/?database_id=${this.dataBaseID}`, options.ws || {cache: false})
14
-
15
- if(!options.nameProcess) options.nameProcess = "plugin"
16
-
17
- process[options.nameProcess] = this
18
-
19
- }
20
-
21
- connect(){
22
-
23
- this.project.on('ready', ()=>{
24
- this.emit('connect')
25
- })
26
-
27
- this.project.on('disconnect', () =>{
28
- this.emit('disconnect')
29
- this.project.reconnectStatus = true
30
- })
31
-
32
- this.project.on('message', (msg) =>{
33
-
34
- let data = msg.json()
35
-
36
- // console.log(data)
37
-
38
- if(data.event === 'ready'){
39
- this.emit('ready')
40
-
41
- }
42
- if(data.event === 'watchData'){
43
-
44
- if(data.requestID) return;
45
-
46
- this.emit('watch', data.data)
47
-
48
- }
49
- if(data.event === 'error'){
50
-
51
- let errors = [{
52
- num: 401,
53
- message: "Failed Authorized with your database, please verify from id",
54
- reconnect: false
55
- }]
56
-
57
- let err = errors.find(x => x.num === data.data)
58
-
59
- if(!err?.reconnect){
60
-
61
- this.project.reconnectStatus = false
62
-
63
- }else{
64
-
65
- this.project.reconnectStatus = true
66
-
67
- }
68
-
69
- this.emit('error', (err?.message || data.data))
70
- }
71
-
72
- })
73
-
74
- }
75
-
76
- async waitResponse(requestID){
77
- return await new Promise(async re => {
78
-
79
- let claimedMessage = (data)=>{
80
- let msg = data.json()
81
-
82
- if(msg.requestID === requestID){
83
- re(msg);
84
- this.project.removeListener('message', claimedMessage)
85
- }
86
-
87
- }
88
-
89
- this.project.on('message', (data)=>claimedMessage(data))
90
-
91
- })
92
- }
93
-
94
- async waitChunk(requestID){
95
- return await new Promise(async re => {
96
-
97
- let result = '';
98
-
99
- let claimedMessage = (data)=>{
100
- let msg = data.json()
101
-
102
- if(msg.requestID === requestID && msg.event === 'chunk'){
103
- // re(msg);
104
- // this.project.removeListener('message', claimedMessage)
105
-
106
- result += msg.data
107
-
108
- }
109
-
110
- if(msg.requestID === requestID && msg.event === 'finish'){
111
-
112
- result += msg.data
113
-
114
- re({event: "accepted", data: JSON.parse(result)})
115
- result = ''
116
- this.project.removeListener('message', claimedMessage)
117
-
118
- }
119
-
120
- }
121
-
122
-
123
- this.project.on('message', (data)=>claimedMessage(data))
124
-
125
- })
126
- }
127
-
128
- setUpCollection(collectionName){
129
- //, withData, select
130
- let requestID = randomToken(8)
131
-
132
- //setTimeout(()=>{ this.project.createMessage({event: "findCollection", data:{name: collectionName, withData: withData, select: select}, requestID}) }, 100)
133
-
134
- //var response = await this.waitResponse(requestID)
135
-
136
- //let res = Array.isArray(response?.data) ? response?.data : [] || []
137
-
138
- let res = []
139
-
140
- res.add = async (options)=>{
141
- return await collection.push(this, collectionName, options)
142
- }
143
-
144
- res.find = (options)=>{
145
-
146
- let query = {}
147
-
148
- var useSelect = null
149
- let useLimit = null
150
- let useSkip = null
151
-
152
- query.select = (select)=>{
153
- useSelect = select
154
- return query
155
- }
156
-
157
- query.limit = (num)=>{
158
- useLimit = num
159
- return query
160
- }
161
-
162
- query.skip = (num)=>{
163
- useSkip = num
164
- return query
165
- }
166
-
167
- query.exec = ()=>{
168
- return collection.find(this, collectionName, options, useSelect, useLimit, useSkip)
169
- }
170
-
171
- return query
172
- }
173
-
174
- res.findOne = (options, select)=>{
175
-
176
- let query = {}
177
-
178
- var useSelect = null
179
- let useLimit = null
180
- let useSkip = null
181
-
182
- query.select = (select)=>{
183
- useSelect = select
184
- return query
185
- }
186
-
187
- query.limit = (num)=>{
188
- useLimit = num
189
- return query
190
- }
191
-
192
- query.skip = (num)=>{
193
- useSkip = num
194
- return query
195
- }
196
-
197
- query.exec = ()=>{
198
- return collection.findOne(this, collectionName, options, useSelect, useSkip)
199
- }
200
-
201
- return query
202
-
203
- }
204
-
205
- res.deleteOne = (options)=>{
206
-
207
- return collection.deleteOne(this, collectionName, options)
208
-
209
- }
210
-
211
- res.deleteMany = (options)=>{
212
-
213
- return collection.deleteMany(this, collectionName, options)
214
-
215
- }
216
-
217
- res.updateOne = (options, new_values)=>{
218
-
219
- return collection.updateOne(this, collectionName, options, new_values)
220
-
221
- }
222
-
223
- res.updateMany = (options, new_values)=>{
224
-
225
- return collection.updateMany(this, collectionName, options, new_values)
226
-
227
- }
228
-
229
- res.countDocuments = (options)=>{
230
-
231
- return collection.countDocuments(this, collectionName, options)
232
-
233
- }
234
-
235
- res.size = (options)=>{
236
-
237
- return collection.getSize(this, collectionName, options)
238
-
239
- }
240
-
241
- res.watch = ()=>{
242
-
243
- return collection.watch(this, collectionName)
244
-
245
- }
246
-
247
- return res
248
-
249
- }
250
-
251
- }
252
- module.exports = Plugin;
package/ws/Message.js DELETED
@@ -1,18 +0,0 @@
1
- class Message extends Object {
2
- constructor (message) {
3
- super ()
4
- this.body = message
5
- }
6
-
7
- json(){
8
- try { return JSON.parse(this.body) } catch(e) { return e.message };
9
- }
10
-
11
- text(){
12
- if(this.body.includes('Buffer')) return Buffer.from(this.body).toString("utf8")
13
- return this.body
14
- }
15
-
16
- }
17
- module.exports = Message
18
-
package/ws/index.js DELETED
@@ -1,196 +0,0 @@
1
- let EventEmitter = require("events");
2
- const ws = require('ws')
3
- let Message = require('../ws/Message.js')
4
-
5
- class index extends EventEmitter {
6
- constructor (url, options) {
7
- super ()
8
- this.headers = {}
9
- if(!options) options = {}
10
- if(options.headers) this.headers = options.headers
11
-
12
- this.eventSendMessage = options.sendMessage
13
-
14
- if(options.sendMessage) {
15
- if(options.sendMessage.on) this.eventSendMessage = options.sendMessage.on
16
- }
17
-
18
- this.options = options
19
- this.url = url
20
- this.pingStatus = false
21
- this.project = null
22
- this.autosendStatus = false
23
- this.historyPing = []
24
- this.historySend = []
25
- this.autoSend = {time: 10, msg: {"event": "hello", data: {world: true}}}
26
- this.pingOptions = {time: 35, msg: {"event": "ping", data: {}}}
27
- this._messages = []
28
- this.cache = true
29
-
30
- this.ready = false
31
-
32
- if(options.cache === false) this.cache = false
33
- this.reconnectStatus = options.reconnect || false
34
- this._catchSystem()
35
- this._connect(url, this.headers, options)
36
-
37
- }
38
-
39
- _catchSystem(){
40
- setInterval(async ()=>{
41
- if(this.cache === true) return;
42
-
43
- this._messages = []
44
- for(const d of this.historyPing.filter(data => data.use === true)) this.historyPing = this.historyPing.filter(x => x.id === d.id)
45
- for(const d of this.historySend.filter(data => data.use === true)) this.historySend = this.historySend.filter(x => x.id === d.id)
46
-
47
- }, 500)
48
- }
49
-
50
- _ready(){
51
- this.emit("ready")
52
- }
53
-
54
- async _close(a1, a2, a3){
55
- await this.disablePing()
56
- this.emit('disconnect', a1, a2)
57
- this.ready = false
58
- if(this.reconnectStatus === true) this.reconnect()
59
- }
60
-
61
- _error(a1, a2, a3){
62
- //this.emit('error', a1, a2)
63
- }
64
-
65
- _eventCreateMessage(a1){
66
- this.emit('createMessage', a1)
67
- }
68
-
69
- _eventReConnect(){
70
- this.emit('reConnect')
71
- }
72
-
73
- _ping(message){
74
- this.emit('ping', message)
75
- }
76
-
77
-
78
- async createMessage(msg){
79
-
80
- let data; try { data = JSON.parse(JSON.stringify(msg)) } catch(e) {this._messages.unshift({json: null, text: msg}); return new Message(msg) };
81
- try {
82
- await this.project.send(JSON.stringify(msg))
83
- this._messages.unshift({json: JSON.parse(JSON.stringify(msg)), text: msg})
84
-
85
- this.emit(this.eventSendMessage, new Message(JSON.stringify(msg)))
86
-
87
- return new Message(JSON.stringify(msg))
88
- } catch(e) {
89
- return e.message
90
- }
91
- }
92
-
93
- _message(msg){
94
- try { this._messages.unshift({json: JSON.parse(msg), text: msg})} catch { this._messages.unshift({json: null, text: msg}) };
95
- this.emit('message', new Message(msg))
96
- }
97
-
98
- async disconnect(){
99
- await this.project.close()
100
- return {url: this.url, headers: this.headers, options: this.options}
101
- }
102
-
103
- systemAutoSend(id){
104
- this.historySend.unshift({id: id, use: false, send: null})
105
- let d = this.historySend.find(a => a.id === id)
106
- setInterval(async ()=>{
107
- if(d.use === true) return;
108
- this.systemAutoSend(this.historySend.length + 1);
109
- d.use = true
110
- if(this.autosendStatus === false) return d.send = false;
111
- this.event('autoSend', this.autoSend.msg)
112
- this.createMessage(this.autoSend.msg)
113
- d.send = true
114
- }, this.autoSend.time * 1000)
115
- return {status: this.autosendStatus, options: this.autoSend, dataConnect: d}
116
- }
117
-
118
- systemPing(id){
119
- this.historyPing.unshift({id: id, use: false, send: null})
120
- let d = this.historyPing.find(a => a.id === id)
121
- setInterval(async ()=>{
122
- if(d.use === true) return;
123
- this.systemPing(this.historyPing.length + 1);
124
- d.use = true
125
- if(this.pingStatus === false) return d.send = false;
126
- this.event('ping', this.pingOptions.msg)
127
- this.createMessage(this.pingOptions.msg)
128
- d.send = true
129
- }, this.pingOptions.time * 1000)
130
- return {status: this.pingStatus, options: this.pingOptions, dataConnect: d}
131
- }
132
-
133
-
134
- enableAutoSend(options){
135
- if(options) this.autoSend = options
136
- this.autosendStatus = true
137
- this.systemAutoSend(this.historySend.length + 1)
138
- return {status: this.autosendStatus, options: this.autoSend}
139
- }
140
-
141
- disableAutoSend(){
142
- this.autosendStatus = false
143
- return {status: this.autosendStatus, options: this.autoSend}
144
- }
145
- enablePing(options){
146
- if(options) this.pingOptions = options
147
- this.pingStatus = true
148
- this.systemPing(this.historyPing.length + 1)
149
- return {status: this.pingStatus, options: this.pingOptions}
150
- }
151
-
152
- disablePing(){
153
- this.pingStatus = false
154
- return {status: this.pingStatus, options: this.pingOptions}
155
- }
156
-
157
- async reconnect(time){
158
- return await new Promise(re => {
159
- if(!time){
160
- if(this.options && this.options.reconnectTime) {time = this.options.reconnectTime}else{time = 2}
161
- }
162
-
163
- setTimeout(()=>{
164
- this.event('reconnect')
165
- this._connect(this.url, this.headers, this.options)
166
- re({url: this.url, headers: this.headers, options: this.options})
167
- }, time * 1000)
168
- })
169
- }
170
-
171
- event(d1, d2, d3){
172
- if(d1 === "open") this._ready()
173
- if(d1 === "close") this._close(d2, d3)
174
- if(d1 === "error") this._error(d2, d3)
175
- if(d1 === "message") this._message(d2)
176
- if(d1 === "createmessage") this._eventCreateMessage(d2)
177
- if(d1 === "reconnect") this._eventReConnect()
178
- if(d1 === "ping") this._ping(d1)
179
-
180
- return {dataOne: d1, dataTwo: d2, dataThree: d3}
181
-
182
- }
183
-
184
- _connect(url, headers, options){
185
- this.project = new ws( url , options.protocol || options._protocol , { headers:this.headers })
186
- this.ready=true
187
- this.project.on('open', async (open) => {this.event('open')});
188
- this.project.on('message', async (msg) => { this.event('message', msg) })
189
- this.project.on('close', async (d1, d2) => {this.event('close', d1, d2)});
190
- this.project.on('error', async (d1, d2) => {this.event('error', d1, d2);});
191
- return {url: url, headers: headers, options: options}
192
- }
193
-
194
-
195
- }
196
- module.exports = index