module cleanup
This commit is contained in:
1 parent
e25d134cfa
commit
092e4176b0
2 files changed
+88
-53
No files matched your search
+41
-38
@@ -44,60 +44,51 @@ export default class Socket {
|
||||
|
||||
constructor(con) {
|
||||
this.con = con
|
||||
// throw new Error('test')
|
||||
// socket event register function modification (pass additional parameter)
|
||||
// this.socket.originalOn = this.socket.on;
|
||||
// this.socket.on = function (event, data, callback) {
|
||||
// return this.originalOn.call(this, event, (e) => callback(e, data));
|
||||
// };
|
||||
// newScript()
|
||||
// .then(() => {
|
||||
this.socket = io('/')
|
||||
this.hostname = '/'
|
||||
this.socket = io(`${this.hostname}`)
|
||||
|
||||
// socket connecting start event
|
||||
this.socket.on('connecting', (data) => con.log("Conecting...", "info", 2));
|
||||
this.socket.on("connect_error", (data) => con.log(data, "error"))
|
||||
this.waiting = {}
|
||||
|
||||
this.socket.on('auth', d => this.auth(d))
|
||||
this.socket.on('com', d => this._receive(d))
|
||||
this.socket.on('silent', d => this._silent(d))
|
||||
this.socket.on('auth', d => this.auth(d))
|
||||
this.socket.on('com', d => this._receive(d))
|
||||
this.socket.on('silent', d => this._silent(d))
|
||||
|
||||
// socket disconnected event
|
||||
this.socket.on("disconnect", (data) => {
|
||||
con.log(`Disconnected from server: ${data}`, "warning")
|
||||
this.socket.connect()
|
||||
})
|
||||
this.socket.on('connecting', data => con.log('Conecting...', 'info', 2));
|
||||
this.socket.on('connect_error', data => con.log(data, 'error'))
|
||||
|
||||
// socket succesfully connected event
|
||||
this.socket.on('connect', (data) => {
|
||||
|
||||
con.log("Conected to the server", "ok")
|
||||
if (!this.tryAuth()) this.motd()
|
||||
else con.log("Credentials detected, waiting for auth before motd", "info", 2)
|
||||
this.socket.on('disconnect', data => {
|
||||
con.log(`Disconnected from server: ${data}`, 'warning')
|
||||
})
|
||||
|
||||
});
|
||||
// })
|
||||
// .catch(err=>{
|
||||
// this.con.log(`socket.io.js download failed: ${err}`, 'error')
|
||||
// })
|
||||
this.socket.on('connect', data => {
|
||||
|
||||
con.log("Conected to the server", 'ok')
|
||||
if (!this.tryAuth()) this.motd()
|
||||
else con.log("Credentials detected, waiting for auth before motd", "info", 2)
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
motd() {
|
||||
if (this.con.first) return
|
||||
this.con.first = true
|
||||
this.con.executeCom("motd");
|
||||
this.con.commandlineParse('motd');
|
||||
if (location.hash != "") {
|
||||
this.con.log(`Executing command from URI (${location.hash.slice(1)})`, "info", 3)
|
||||
this.con.executeCom(decodeURIComponent(location.hash.slice(1)));
|
||||
}
|
||||
}
|
||||
|
||||
_silent(res){
|
||||
this.con.unpack(res)
|
||||
}
|
||||
|
||||
_receive(res) {
|
||||
this.con.getCom(res.res.id).update(res);
|
||||
getSilent(data){
|
||||
return new Promise((resolve, reject) => {
|
||||
var out = {
|
||||
query: data,
|
||||
id: makeID(5)
|
||||
}
|
||||
this.waiting[out.id] = {resolve: resolve, reject: reject}
|
||||
this.socket.emit('silent', out)
|
||||
})
|
||||
}
|
||||
|
||||
send(com) {
|
||||
@@ -125,7 +116,7 @@ export default class Socket {
|
||||
return this.con.udataExp
|
||||
}
|
||||
|
||||
auth(udata) {
|
||||
_auth(udata) {
|
||||
con.log("Auth data received", "ok", 2);
|
||||
this.con.udata = udata;
|
||||
this.con.uAuth(true)
|
||||
@@ -134,6 +125,18 @@ export default class Socket {
|
||||
this.con.motd()
|
||||
}
|
||||
|
||||
_receive(res) {
|
||||
this.con.getCom(res.res.id).update(res);
|
||||
}
|
||||
|
||||
_silent(res) {
|
||||
// this.con.unpack(res)
|
||||
this.waiting[res.id].resolve(res)
|
||||
delete this.waiting[res.id]
|
||||
}
|
||||
|
||||
_broadcast(data) {}
|
||||
|
||||
tryAuth() {
|
||||
if (con.credentials) {
|
||||
con.socket.emit("auth".credentials);
|
||||
|
||||
+47
-15
@@ -3,14 +3,31 @@ export var requires = {
|
||||
styles: [
|
||||
'tree.css'
|
||||
],
|
||||
modules: [
|
||||
// 'Fontello'
|
||||
]
|
||||
}
|
||||
|
||||
var colors = {
|
||||
'number': 'txred',
|
||||
'string': 'txgrn',
|
||||
'boolean': 'txyel',
|
||||
'function': 'txcya',
|
||||
'array': 'txyel',
|
||||
'object': 'txblu',
|
||||
'regex': 'txprp',
|
||||
'null': 'txxblk',
|
||||
'undefined': 'txxblk',
|
||||
'empty': 'txxprp',
|
||||
'last': 'txxprp',
|
||||
'fname': 'txxprp',
|
||||
'default': 'txxblk'
|
||||
}
|
||||
|
||||
export default class Tree {
|
||||
constructor(data) {
|
||||
this.data = data
|
||||
|
||||
// requiresStyle('tree.css')
|
||||
|
||||
if (this._typeOf(data) != "array" && this._typeOf(data) != "object")
|
||||
this.$ = $("<span></span>").append(this._contentType(data)).append(": ").append(`${data}`)
|
||||
else this.$ = $("<ul></ul>")
|
||||
@@ -24,6 +41,21 @@ export default class Tree {
|
||||
)
|
||||
)
|
||||
|
||||
// tree collapse subtree click handling
|
||||
this.$.on("click", ".collapse", function (e) {
|
||||
var c = $(this);
|
||||
|
||||
c.siblings("ul").toggle(200)
|
||||
if (c.children("i").hasClass("icon-minus-squared")) {
|
||||
c.children("i").removeClass();
|
||||
c.children("i").addClass("icon-plus-squared");
|
||||
} else {
|
||||
c.children("i").removeClass();
|
||||
c.children("i").addClass("icon-minus-squared");
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
get() {
|
||||
@@ -46,16 +78,16 @@ export default class Tree {
|
||||
|
||||
switch (type) {
|
||||
|
||||
case 'number': return $("<txred></txred>").append(name ? name : "number")
|
||||
case 'string': return $("<txgrn></txgrn>").append(name ? name : "string")
|
||||
case 'boolean': return $("<txyel></txyel>").append(name ? name : "boolean")
|
||||
case 'function': return $("<txcya></txcya>").append(name ? name : "function")
|
||||
case 'array': return $("<txyel></txyel>").append(name ? name : "array")
|
||||
case 'object': return $("<txblu></txblu>").append(name ? name : "object")
|
||||
case 'regex': return $("<txprp></txprp>").append(name ? name : "regex")
|
||||
case 'null': return $("<txxblk></txxblk>").append(name ? name : "null")
|
||||
case 'undefined': return $("<txxblk></txxblk>").append(name ? name : "undefined")
|
||||
default: return $("<txxblk></txxblk>").append(name ? name : "?")
|
||||
case 'number': return $(`<${colors.number}></${colors.number}>`).append(name ? name : 'number')
|
||||
case 'string': return $(`<${colors.string}></${colors.string}>`).append(name ? name : 'string')
|
||||
case 'boolean': return $(`<${colors.boolean}></${colors.boolean}>`).append(name ? name : 'boolean')
|
||||
case 'function': return $(`<${colors.function}></${colors.function}>`).append(name ? name : 'function')
|
||||
case 'array': return $(`<${colors.array}></${colors.array}>`).append(name ? name : 'array')
|
||||
case 'object': return $(`<${colors.object}></${colors.object}>`).append(name ? name : 'object')
|
||||
case 'regex': return $(`<${colors.regex}></${colors.regex}>`).append(name ? name : 'regex')
|
||||
case 'null': return $(`<${colors.null}></${colors.null}>`).append(name ? name : 'null')
|
||||
case 'undefined': return $(`<${colors.undefined}></${colors.undefined}>`).append(name ? name : 'undefined')
|
||||
default: return $(`<${colors.default}></${colors.default}>`).append(name ? name: '?')
|
||||
}
|
||||
|
||||
}
|
||||
@@ -107,7 +139,7 @@ export default class Tree {
|
||||
$("<li></li>")
|
||||
.append(this._contentType(content, key))
|
||||
.append(": ")
|
||||
.append(`<txxprp>[empty]</txxprp>`)
|
||||
.append(`<${colors.empty}>[empty]</${colors.empty}>`)
|
||||
)
|
||||
} else { // content not empty
|
||||
if (depth > maxd) { // is max depth reached
|
||||
@@ -115,7 +147,7 @@ export default class Tree {
|
||||
$("<li></li>")
|
||||
.append(this._contentType(content, key))
|
||||
.append(": ")
|
||||
.append(`<txxprp>${isWhat(content)}</txxprp>`)
|
||||
.append(`<${colors.last}>${isWhat(content)}</${colors.last}>`)
|
||||
)
|
||||
} else { // max depth not reached
|
||||
$list.append( // continue recursion
|
||||
@@ -137,7 +169,7 @@ export default class Tree {
|
||||
.append(this._contentType(content, key))
|
||||
.append(": ")
|
||||
.append(
|
||||
`<txxprp>${isWhat(content)}</txxprp>`
|
||||
`<${colors.fname}>${isWhat(content)}</${colors.fname}>`
|
||||
)
|
||||
)
|
||||
break;
|
||||
|
||||
Reference in new issue
Block a user