decline & accept devices and protocol connection issues fixed

This commit is contained in:
RoyceDa
2026-01-31 04:55:00 +02:00
parent 22a1fd3a1a
commit a95db0d24b
6 changed files with 129 additions and 9 deletions

View File

@@ -0,0 +1,54 @@
import Packet from "../packet";
import Stream from "../stream";
/**
* Решение по устройству при верификации
* Отклонить или принять
*/
export enum Solution {
DECLINE,
ACCEPT
}
/**
* Отправляется клиентом при решении по устройству
*/
export class PacketDeviceResolve extends Packet {
private deviceId: string = "";
private solution: Solution = Solution.DECLINE;
public getPacketId(): number {
return 0x18;
}
public _receive(stream: Stream): void {
this.deviceId = stream.readString();
this.solution = stream.readInt8();
}
public _send(): Promise<Stream> | Stream {
const stream = new Stream();
stream.writeInt16(this.getPacketId());
stream.writeString(this.deviceId);
stream.writeInt8(this.solution);
return stream;
}
public getDeviceId(): string {
return this.deviceId;
}
public getSolution(): Solution {
return this.solution;
}
public setDeviceId(deviceId: string): void {
this.deviceId = deviceId;
}
public setSolution(solution: Solution): void {
this.solution = solution;
}
}

View File

@@ -26,6 +26,7 @@ import { PacketGroupLeave } from "./packets/packet.group.leave";
import { PacketGroupBan } from "./packets/packet.group.ban";
import { PacketDeviceNew } from "./packets/packet.device.new";
import { PacketDeviceList } from "./packets/packet.device.list";
import { PacketDeviceResolve } from "./packets/packet.device.resolve";
export default class Protocol extends EventEmitter {
private serverAddress: string;
@@ -122,6 +123,7 @@ export default class Protocol extends EventEmitter {
this._supportedPackets.set(0x15, new PacketGroupLeave());
this._supportedPackets.set(0x16, new PacketGroupBan());
this._supportedPackets.set(0x17, new PacketDeviceList());
this._supportedPackets.set(0x18, new PacketDeviceResolve());
}
private _findWaiters(packetId: number): ((packet: Packet) => void)[] {
@@ -133,6 +135,11 @@ export default class Protocol extends EventEmitter {
public connect() {
this.socket = new WebSocket(this.serverAddress);
/**
* Сбрасываем флаг ручного закрытия соединения
* при подключении
*/
this.isManuallyClosed = false;
this.socket.addEventListener('open', () => {
//this.reconnectTryings = 0;