function SocketIO() {
this.socket = null;
this.reconnect=null
}
SocketIO.prototype.start = (server)=> {
let self = this;
this.socket = so(server);
this.socket.on('connect', ()=> {
self.waitType()
});
this.socket.on('disconnect', ()=> {
self.socket = self.start(self.reconnect);
});
};
SocketIO.prototype.waitType = ()=> {
let self = this;
process.stdin.setEncoding('utf8');
process.stdin.on('readable', () => {
let chunk = process.stdin.read();
let cmds = chunk.trim().split(' ');
switch (cmds[0]) {
case 'connect':
self.reconnect = cmds[1];
break;
}
});
};
↧
js中成员函数如何调用自身
↧