40 lines
1.4 KiB
Java
40 lines
1.4 KiB
Java
package im.rosetta.executors;
|
||
|
||
import java.util.ArrayList;
|
||
|
||
import im.rosetta.Failures;
|
||
import im.rosetta.client.tags.ECIAuthentificate;
|
||
import im.rosetta.packet.Packet28IceServers;
|
||
import im.rosetta.service.services.ForwardUnitService;
|
||
import io.orprotocol.ProtocolException;
|
||
import io.orprotocol.client.Client;
|
||
import io.orprotocol.packet.PacketExecutor;
|
||
|
||
public class Executor28IceServers extends PacketExecutor<Packet28IceServers> {
|
||
|
||
private ForwardUnitService fus;
|
||
|
||
public Executor28IceServers(ForwardUnitService fus) {
|
||
this.fus = fus;
|
||
}
|
||
|
||
@Override
|
||
public void onPacketReceived(Packet28IceServers packet, Client client) throws Exception, ProtocolException {
|
||
ECIAuthentificate eciAuthentificate = client.getTag(ECIAuthentificate.class);
|
||
if(eciAuthentificate == null || !eciAuthentificate.hasAuthorized()) {
|
||
/**
|
||
* Если клиент не авторизован, то мы не будем обрабатывать его запрос на получение ICE серверов
|
||
* и просто отключим его от сервера.
|
||
*/
|
||
client.disconnect(Failures.HANDSHAKE_NOT_COMPLETED);
|
||
return;
|
||
}
|
||
/**
|
||
* Берем TURN сервера и отправляем их клиенту
|
||
*/
|
||
packet.setIceServers(new ArrayList<>(this.fus.getTurnServers()));
|
||
client.send(packet);
|
||
}
|
||
|
||
}
|