prettier reformat for merge (and remove jpeg-turbo Again)
This commit is contained in:
@@ -1,55 +1,55 @@
|
||||
import EventEmitter from "events";
|
||||
import NetworkClient from "../NetworkClient.js";
|
||||
import { Socket } from "net";
|
||||
import EventEmitter from 'events';
|
||||
import NetworkClient from '../NetworkClient.js';
|
||||
import { Socket } from 'net';
|
||||
|
||||
export default class TCPClient extends EventEmitter implements NetworkClient {
|
||||
private socket: Socket;
|
||||
private cache: string;
|
||||
|
||||
constructor(socket: Socket) {
|
||||
super();
|
||||
this.socket = socket;
|
||||
this.cache = '';
|
||||
this.socket.on('end', () => {
|
||||
this.emit('disconnect');
|
||||
})
|
||||
this.socket.on('data', (data) => {
|
||||
var msg = data.toString('utf-8');
|
||||
if (msg[msg.length - 1] === '\n') msg = msg.slice(0, -1);
|
||||
this.cache += msg;
|
||||
this.readCache();
|
||||
});
|
||||
}
|
||||
private socket: Socket;
|
||||
private cache: string;
|
||||
|
||||
private readCache() {
|
||||
for (var index = this.cache.indexOf(';'); index !== -1; index = this.cache.indexOf(';')) {
|
||||
this.emit('msg', this.cache.slice(0, index + 1));
|
||||
this.cache = this.cache.slice(index + 1);
|
||||
}
|
||||
}
|
||||
constructor(socket: Socket) {
|
||||
super();
|
||||
this.socket = socket;
|
||||
this.cache = '';
|
||||
this.socket.on('end', () => {
|
||||
this.emit('disconnect');
|
||||
});
|
||||
this.socket.on('data', (data) => {
|
||||
var msg = data.toString('utf-8');
|
||||
if (msg[msg.length - 1] === '\n') msg = msg.slice(0, -1);
|
||||
this.cache += msg;
|
||||
this.readCache();
|
||||
});
|
||||
}
|
||||
|
||||
getIP(): string {
|
||||
return this.socket.remoteAddress!;
|
||||
}
|
||||
private readCache() {
|
||||
for (var index = this.cache.indexOf(';'); index !== -1; index = this.cache.indexOf(';')) {
|
||||
this.emit('msg', this.cache.slice(0, index + 1));
|
||||
this.cache = this.cache.slice(index + 1);
|
||||
}
|
||||
}
|
||||
|
||||
send(msg: string): Promise<void> {
|
||||
return new Promise((res, rej) => {
|
||||
this.socket.write(msg, (err) => {
|
||||
if (err) {
|
||||
rej(err);
|
||||
return;
|
||||
}
|
||||
res();
|
||||
});
|
||||
});
|
||||
}
|
||||
getIP(): string {
|
||||
return this.socket.remoteAddress!;
|
||||
}
|
||||
|
||||
close(): void {
|
||||
this.emit('disconnect');
|
||||
this.socket.end();
|
||||
}
|
||||
send(msg: string): Promise<void> {
|
||||
return new Promise((res, rej) => {
|
||||
this.socket.write(msg, (err) => {
|
||||
if (err) {
|
||||
rej(err);
|
||||
return;
|
||||
}
|
||||
res();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
isOpen(): boolean {
|
||||
return this.socket.writable;
|
||||
}
|
||||
}
|
||||
close(): void {
|
||||
this.emit('disconnect');
|
||||
this.socket.end();
|
||||
}
|
||||
|
||||
isOpen(): boolean {
|
||||
return this.socket.writable;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user