83 lines
1.9 KiB
TypeScript
83 lines
1.9 KiB
TypeScript
import Packet from "../packet";
|
|
import Stream from "../stream";
|
|
|
|
export enum SignalType {
|
|
CALL = 0,
|
|
KEY_EXCHANGE = 1,
|
|
ACTIVE_CALL = 2,
|
|
END_CALL = 3
|
|
}
|
|
|
|
export class PacketSignal extends Packet {
|
|
|
|
private src: string = "";
|
|
/**
|
|
* Назначение
|
|
*/
|
|
private dst: string = "";
|
|
/**
|
|
* Используется если SignalType == KEY_EXCHANGE, для идентификации сессии обмена ключами
|
|
*/
|
|
private sharedPublic: string = "";
|
|
|
|
private signalType: SignalType = SignalType.CALL;
|
|
|
|
|
|
public getPacketId(): number {
|
|
return 26;
|
|
}
|
|
|
|
public _receive(stream: Stream): void {
|
|
this.signalType = stream.readInt8();
|
|
this.src = stream.readString();
|
|
this.dst = stream.readString();
|
|
if(this.signalType == SignalType.KEY_EXCHANGE){
|
|
this.sharedPublic = stream.readString();
|
|
}
|
|
}
|
|
|
|
public _send(): Promise<Stream> | Stream {
|
|
const stream = new Stream();
|
|
stream.writeInt16(this.getPacketId());
|
|
stream.writeInt8(this.signalType);
|
|
stream.writeString(this.src);
|
|
stream.writeString(this.dst);
|
|
if(this.signalType == SignalType.KEY_EXCHANGE){
|
|
stream.writeString(this.sharedPublic);
|
|
}
|
|
return stream;
|
|
}
|
|
|
|
public setDst(dst: string) {
|
|
this.dst = dst;
|
|
}
|
|
|
|
public setSharedPublic(sharedPublic: string) {
|
|
this.sharedPublic = sharedPublic;
|
|
}
|
|
|
|
public setSignalType(signalType: SignalType) {
|
|
this.signalType = signalType;
|
|
}
|
|
|
|
public getDst(): string {
|
|
return this.dst;
|
|
}
|
|
|
|
public getSharedPublic(): string {
|
|
return this.sharedPublic;
|
|
}
|
|
|
|
public getSignalType(): SignalType {
|
|
return this.signalType;
|
|
}
|
|
|
|
public getSrc(): string {
|
|
return this.src;
|
|
}
|
|
|
|
public setSrc(src: string) {
|
|
this.src = src;
|
|
}
|
|
|
|
} |