package voxo.client.actions;
import java.io.IOException;
import java.net.UnknownHostException;
import java.util.EnumSet;
import javax.swing.JOptionPane;
import voxo.client.controllers.ClientController;
import voxo.client.services.NetworkService;
import voxo.client.threads.VoiceReceiver;
import voxo.client.threads.VoiceSender;
import voxo.common.entities.Packet;
import voxo.common.enums.EnumPacket;
import voxo.common.enums.EnumVerbose;
import voxo.common.packets.VoiceConnexionPacket;
public class ConfirmVoiceAction {
public ConfirmVoiceAction(ClientController c, String contactIp, VoiceConnexionPacket p) {
if (c.getVoiceReceiver() != null && c.getVoiceReceiver().isGo()) {
// c.getVoiceReceiver().setGo(false);
JOptionPane.showMessageDialog(null, "You can only chat with 1 person at a time, please end your previous call", "Too many lines", JOptionPane.ERROR_MESSAGE);
} else {
if (c.getVoiceReceiver() != null) {
c.getVoiceReceiver().killSocket();
// c.setVoiceReceiver(null);
}
c.setVoiceReceiver(new VoiceReceiver());
Thread receiver = new Thread(c.getVoiceReceiver());
receiver.start();
if (c.getVoiceSender() != null) {
c.getVoiceSender().killSocket();
// c.setVoiceSender(null);
}
c.setVoiceSender(new VoiceSender(contactIp));
Thread sender = new Thread(c.getVoiceSender());
sender.start();
try {
NetworkService.sendPacket(contactIp, new Packet(EnumPacket.CLIENT_ConfirmVoice, p));
} catch (UnknownHostException e) {
c.getVerbose().addConsoleMsg(e, EnumSet.of(EnumVerbose.ToConsole, EnumVerbose.ToLog));
new ServerErrorAction(c);
} catch (IOException e) {
c.getVerbose().addConsoleMsg(e, EnumSet.of(EnumVerbose.ToConsole, EnumVerbose.ToLog));
new ServerErrorAction(c);
}
}
}
}