/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package controller.commands;

import controller.CommandInterface;
import gui.Hauptfenster;
import static java.lang.Thread.sleep;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.sip.SipException;
import model.SoundSenderDemo;
//import jlibrtpDemos.SoundSenderDemo;
import logger.OhmLogger;
import model.SIPmodel;
import java.lang.String;
import java.net.UnknownHostException;
import model.RTPSendSingleString;

/**
 *
 * @author Jan Fehlende Ergänzungen(timer nach 10 sec für abbruchbedingung +
 * bedingung falls angenommen wurde -> Boolean)
 */
public class CommandInvite implements CommandInterface {

    private static final Logger lginvite = OhmLogger.getLogger();
    private SIPmodel model;
    private Hauptfenster view;

    public CommandInvite(SIPmodel model, Hauptfenster view) {
        this.model = model;
        this.view = view;
    }

    @Override
    public void execute() {
        try {
            view.getTxtArea().append("Einladung an " + view.getTxtcallIP().getText() + " gesendet\n");
            model.sendInvitation(view.getTxtcallIP().getText(), view.getTxtServerIP().getText(), 5078);
        } catch (SipException ex) {
            view.getTxtArea().append("Einladung fehlgeschlagen\n");
            lginvite.getLogger(CommandInvite.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            sleep(5000);
        } catch (InterruptedException ex) {
            Logger.getLogger(CommandInvite.class.getName()).log(Level.SEVERE, null, ex);
        }
        callDemo();
    }

    @Override
    public void undo() {

    }

    @Override
    public Boolean isundoable() {
        return false;
    }
    
    public void callDemo(){
        System.out.println("Starte RTP Session");
        String[] s = null;
        SoundSenderDemo aDemo = new SoundSenderDemo();
      
        try {
            aDemo.SendDemo(s);
        } catch (UnknownHostException | InterruptedException ex) {
            Logger.getLogger(CommandInvite.class.getName()).log(Level.SEVERE, null, ex);
        }
        System.out.println("Beende RTP Session");
    }
    
    public void callUnicastDemo(){
        System.out.println("Starte RTP Unicast Session");
        String[] s = null;
        RTPSendSingleString aDemo = new RTPSendSingleString();
        aDemo.main(s);
        System.out.println("Beende RTP Unicast Session");
    }
}
