Files
desktop/app/providers/ProtocolProvider/protocol/packets/packet.device.new.ts
2026-01-31 03:01:25 +02:00

64 lines
1.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import Packet from "../packet";
import Stream from "../stream";
export interface Device {
deviceId: string;
deviceName: string;
deviceOs: string;
}
/**
* Приходит всегда с сервера,
* когда к аккаунту пользователя подключается новое устройство.
* Приходит на все девайсы.
*/
export class PacketDeviceNew extends Packet {
private ipAddress: string = "";
private device: Device = {
deviceId: "",
deviceName: "",
deviceOs: ""
}
public getPacketId(): number {
return 0x09;
}
public _receive(stream: Stream): void {
this.ipAddress = stream.readString();
this.device = {
deviceId: stream.readString(),
deviceName: stream.readString(),
deviceOs: stream.readString()
};
}
public _send(): Promise<Stream> | Stream {
const stream = new Stream();
stream.writeInt16(this.getPacketId());
stream.writeString(this.ipAddress);
stream.writeString(this.device.deviceId);
stream.writeString(this.device.deviceName);
stream.writeString(this.device.deviceOs);
return stream;
}
public getIpAddress(): string {
return this.ipAddress;
}
public setIpAddress(ipAddress: string): void {
this.ipAddress = ipAddress;
}
public getDevice(): Device {
return this.device;
}
public setDevice(device: Device): void {
this.device = device;
}
}