Files
desktop/app/providers/ProtocolProvider/protocol/packets/packet.ice.servers.ts

50 lines
1.4 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 class PacketIceServers extends Packet {
private iceServers: RTCIceServer[] = [];
public getPacketId(): number {
return 28;
}
public _receive(stream: Stream): void {
const serversCount = stream.readInt16();
this.iceServers = [];
for(let i = 0; i < serversCount; i++){
const urls = stream.readString();
const username = stream.readString();
const credential = stream.readString();
this.iceServers.push({
urls,
username,
credential
});
}
}
public _send(): Promise<Stream> | Stream {
const stream = new Stream();
stream.writeInt16(this.getPacketId());
stream.writeInt16(this.iceServers.length);
for(let i = 0; i < this.iceServers.length; i++){
const server = this.iceServers[i];
/**
* Не поддерживает массив urls!!!
*/
stream.writeString((server.urls as string));
stream.writeString(server.username || "");
stream.writeString(server.credential || "");
}
return stream;
}
public getIceServers(): RTCIceServer[] {
return this.iceServers;
}
public setIceServers(servers: RTCIceServer[]) {
this.iceServers = servers;
}
}