style: format code

This commit is contained in:
2026-07-13 22:41:32 +03:00
parent b24c71678e
commit 0b24c03068
207 changed files with 7639 additions and 7816 deletions

View File

@@ -14,76 +14,75 @@ import protohx.Message;
import ru.m.connect.IConnection;
class FlashConnection<O:Message, I:Message> extends BaseConnection<O, I> {
private var host:String;
private var port:Int;
private var socket:Socket;
private var host:String;
private var port:Int;
private var socket:Socket;
public function new(host:String, port:Int, inputFactory:Class<I>) {
super(inputFactory);
this.host = host;
this.port = port;
connected = false;
socket = new Socket();
socket.addEventListener(IOErrorEvent.IO_ERROR, onError);
socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onError);
socket.addEventListener(Event.CLOSE, onClose);
socket.addEventListener(Event.CONNECT, onConnect);
socket.addEventListener(ProgressEvent.SOCKET_DATA, onSocketData);
socket.endian = Endian.LITTLE_ENDIAN;
sendHandler.connect(_send);
}
public function new(host:String, port:Int, inputFactory:Class<I>) {
super(inputFactory);
this.host = host;
this.port = port;
connected = false;
socket = new Socket();
socket.addEventListener(IOErrorEvent.IO_ERROR, onError);
socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onError);
socket.addEventListener(Event.CLOSE, onClose);
socket.addEventListener(Event.CONNECT, onConnect);
socket.addEventListener(ProgressEvent.SOCKET_DATA, onSocketData);
socket.endian = Endian.LITTLE_ENDIAN;
sendHandler.connect(_send);
override public function connect():Promise<IConnection<O, I>> {
socket.connect(host, port);
connectDeferred = new Deferred();
return connectDeferred.promise();
}
override public function disconnect():Void {
if (socket.connected) {
socket.close();
connected = false;
handler.emit(ConnectionEvent.DISCONNECTED);
}
}
override public function connect():Promise<IConnection<O, I>> {
socket.connect(host, port);
connectDeferred = new Deferred();
return connectDeferred.promise();
private function onError(event:ErrorEvent):Void {
socket.close();
connected = false;
handler.emit(ConnectionEvent.ERROR(event));
if (connectDeferred != null) {
connectDeferred.throwError(event);
connectDeferred = null;
}
}
override public function disconnect():Void {
if (socket.connected) {
socket.close();
connected = false;
handler.emit(ConnectionEvent.DISCONNECTED);
}
private function onConnect(_):Void {
connected = true;
handler.emit(ConnectionEvent.CONNECTED);
if (connectDeferred != null) {
connectDeferred.resolve(this);
connectDeferred = null;
}
}
private function onError(event:ErrorEvent):Void {
socket.close();
connected = false;
handler.emit(ConnectionEvent.ERROR(event));
if (connectDeferred != null) {
connectDeferred.throwError(event);
connectDeferred = null;
}
}
private function onClose(_):Void {
socket.close();
connected = false;
handler.emit(ConnectionEvent.DISCONNECTED);
}
private function onConnect(_):Void {
connected = true;
handler.emit(ConnectionEvent.CONNECTED);
if (connectDeferred != null) {
connectDeferred.resolve(this);
connectDeferred = null;
}
}
private function onSocketData(_):Void {
var data = new flash.utils.ByteArray();
socket.readBytes(data);
var bytes = Bytes.ofData(data);
pushData(bytes);
}
private function onClose(_):Void {
socket.close();
connected = false;
handler.emit(ConnectionEvent.DISCONNECTED);
}
private function onSocketData(_):Void {
var data = new flash.utils.ByteArray();
socket.readBytes(data);
var bytes = Bytes.ofData(data);
pushData(bytes);
}
private function _send(packet:O):Void {
var bytes = PacketUtil.toBytes(packet);
socket.writeShort(bytes.length);
socket.writeBytes(bytes.getData());
socket.flush();
}
private function _send(packet:O):Void {
var bytes = PacketUtil.toBytes(packet);
socket.writeShort(bytes.length);
socket.writeBytes(bytes.getData());
socket.flush();
}
}