update protocol for devices system
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user