Add Client class.

This commit is contained in:
Tipx-L 2023-10-10 02:36:34 -07:00
parent f914a18137
commit 8cd11aff03
1 changed files with 17 additions and 21 deletions

View File

@ -10818,15 +10818,8 @@
} }
}, },
connection:function(ws){ connection:function(ws){
var client={ const client=new lib.element.Client(ws);
ws:ws,
id:ws.wsid||get.id(),
closed:false
};
lib.node.clients.push(client); lib.node.clients.push(client);
for(var i in lib.element.client){
client[i]=lib.element.client[i];
}
if(window.isNonameServer){ if(window.isNonameServer){
document.querySelector('#server_count').innerHTML=lib.node.clients.length; document.querySelector('#server_count').innerHTML=lib.node.clients.length;
} }
@ -31326,8 +31319,13 @@
return this; return this;
} }
}, },
client:{ Client:class{
send:function(){ constructor(ws){
this.ws=ws;
this.id=ws.wsid||get.id();
this.closed=false;
}
send(){
if(this.closed) return this; if(this.closed) return this;
var args=Array.from(arguments); var args=Array.from(arguments);
if(typeof args[0]=='function'){ if(typeof args[0]=='function'){
@ -31343,8 +31341,8 @@
this.ws.close(); this.ws.close();
} }
return this; return this;
}, }
close:function(){ close(){
lib.node.clients.remove(this); lib.node.clients.remove(this);
lib.node.observing.remove(this); lib.node.observing.remove(this);
if(ui.removeObserve&&!lib.node.observing.length){ if(ui.removeObserve&&!lib.node.observing.length){
@ -31487,6 +31485,12 @@
*/ */
get control(){ get control(){
return this.Control.prototype; return this.Control.prototype;
},
/**
* @legacy Use `lib.element.Client.prototype` instead.
*/
get client(){
return this.Client.prototype;
} }
}, },
card:{ card:{
@ -35791,15 +35795,7 @@
for(var i in lib.element.nodews){ for(var i in lib.element.nodews){
ws[i]=lib.element.nodews[i]; ws[i]=lib.element.nodews[i];
} }
var client={ new lib.element.Client(ws).send(message);
ws:ws,
id:ws.wsid,
closed:false
};
for(var i in lib.element.client){
client[i]=lib.element.client[i];
}
client.send(message);
}, },
createServer:function(){ createServer:function(){
lib.node.clients=[]; lib.node.clients=[];