Normal 5 years ago
parent
commit
4777785ad4
1 changed files with 94 additions and 16 deletions
  1. 94
    16
      src/model/VoIP.java

+ 94
- 16
src/model/VoIP.java View File

@@ -55,12 +55,12 @@ public class VoIP implements SipListenerExt
private ContactHeader contactHeader;

public VoIP()
public VoIP() //Konstruktor für eigene Daten
{
try
{
//wird an sich erstmal nicht gebraucht aber später sinnvoll um in die unteren Daten zu ergänzen
//wird an sich erstmal nicht gebraucht aber später sinnvoll um eigene Daten zu initialisieren
String abc = InetAddress.getLocalHost().getHostAddress();
this.myIPAddress = InetAddress.getLocalHost().getHostAddress();
this.sipFactory = SipFactory.getInstance();
@@ -131,19 +131,101 @@ public class VoIP implements SipListenerExt
@Override
public void processRequest(RequestEvent requestEvent)
{
System.out.println("RequestEvent " + requestEvent.getServerTransaction().getDialog());
System.out.println("----Bekomme Anfrage----");
if ((Request.OPTIONS).equals(requestEvent.getRequest().getMethod()))
{
System.out.println("200 OK zu Server");
try
{
Response response = this.messageFactory.createResponse(200,requestEvent.getRequest());
response.addHeader((ViaHeader)requestEvent.getRequest().getHeader("Via"));
response.addHeader((FromHeader)requestEvent.getRequest().getHeader("From"));
response.addHeader((ToHeader)requestEvent.getRequest().getHeader("To"));
response.addHeader((CallIdHeader)requestEvent.getRequest().getHeader("Call-ID"));
response.addHeader((CSeqHeader)requestEvent.getRequest().getHeader("Cseq"));
//Kontakt Header
response.addHeader(contactHeader);
//Accept Header für application/sdp
AllowHeader allow = this.headerFactory.createAllowHeader("NOTIFY,INVITE,ACK,CANCEL,BYE,REFER,INFO,OPTIONS,MESSAGE");
AllowEventsHeader allowevents = this.headerFactory.createAllowEventsHeader("talk,hold,refer,call-info");
response.addHeader((CallIdHeader)requestEvent.getRequest().getHeader("Call-ID"));
response.addHeader(allow);
response.addHeader(allowevents);
this.sipProvider.sendResponse(response);
}
catch (ParseException | SipException ex)
{
Logger.getLogger(VoIP.class.getName()).log(Level.SEVERE, null, ex);
}
}
else if ((Request.INVITE).equals(requestEvent.getRequest().getMethod()))
{
System.out.println("Hab invitation bekommen");
System.out.println("Gleich antworte ich");
try
{
//Trying
Response responsetry = this.messageFactory.createResponse(100,requestEvent.getRequest());
responsetry.addHeader((ViaHeader)requestEvent.getRequest().getHeader("Via"));
responsetry.addHeader((FromHeader)requestEvent.getRequest().getHeader("From"));
responsetry.addHeader((ToHeader)requestEvent.getRequest().getHeader("To"));
responsetry.addHeader((CallIdHeader)requestEvent.getRequest().getHeader("Call-ID"));
responsetry.addHeader((CSeqHeader)requestEvent.getRequest().getHeader("Cseq"));
SupportedHeader supp = this.headerFactory.createSupportedHeader("replace,path,timer"); //nachschauen
AllowHeader allow = this.headerFactory.createAllowHeader("NOTIFY,INVITE,ACK,CANCEL,BYE,REFER,INFO,OPTIONS,MESSAGE");
responsetry.addHeader(supp);
responsetry.addHeader(allow);
this.sipProvider.sendResponse(responsetry);
System.out.println("Trying ist raus");
//Ringing
Response responsering = this.messageFactory.createResponse(180,requestEvent.getRequest());
responsering.addHeader((ViaHeader)requestEvent.getRequest().getHeader("Via"));
responsering.addHeader((FromHeader)requestEvent.getRequest().getHeader("From"));
ToHeader temptoring = (ToHeader)requestEvent.getRequest().getHeader("To");
temptoring.setTag(String.valueOf(this.tag+Math.random())); //evtl. besseren Tag
responsering.addHeader(temptoring);
responsering.addHeader((CSeqHeader)requestEvent.getRequest().getHeader("Cseq"));
responsering.addHeader(contactHeader);
responsering.addHeader(supp);
responsering.addHeader(allow);
AllowEventsHeader allowevent = this.headerFactory.createAllowEventsHeader("talk,hold");// für was gebraucht
responsering.addHeader(allowevent);
this.sipProvider.sendResponse(responsering);
System.out.println("Response ist raus");
//Jetzt kommt 200 Ok SIP Header + SDP (SIP/SDP)
//Sdp Header erstellen nächster Schritt
ContentTypeHeader content = headerFactory.createContentTypeHeader("application", "sdp");
}
catch (ParseException | SipException ex)
{
Logger.getLogger(VoIP.class.getName()).log(Level.SEVERE, null, ex);
}
}
else if ((Request.ACK).equals(requestEvent.getRequest().getMethod()))
{
}
}

@Override
public void processResponse(ResponseEvent responseEvent)
{
System.out.println("---Response---");
System.out.println(responseEvent.getResponse());
//System.out.println(responseEvent.getResponse());
if (responseEvent.getResponse().getStatusCode() == Response.UNAUTHORIZED && counter ==0)
if (responseEvent.getResponse().getStatusCode() == Response.UNAUTHORIZED)
{
counter++;
try {
Address addresstob = this.addressFactory.createAddress("sip:129@192.168.100.11"); //"sip:Jan@192.168.100.11"
@@ -163,15 +245,10 @@ public class VoIP implements SipListenerExt
auth.setRealm(abc.getRealm());
auth.setNonce(abc.getNonce());
Address addresstest = this.addressFactory.createAddress("sip:"+myName+"@192.168.100.11"); //vielleicht passwort setzen "sip:"+myName+":\"\"@192.168.100.11"
Address addresstest = this.addressFactory.createAddress("sip:"+myName+"@192.168.100.11"); //vielleicht passwort setzen "sip:"+myName+":\"\"@192.168.100.11"
auth.setURI(addresstest.getURI());
//System.out.println("Test");
//auth.setQop(abc.getQop());
System.out.println("Test");
//auth.setOpaque(abc.getOpaque());
auth.setUsername(myName);
System.out.println("-----auth------");
System.out.println(auth);

ArrayList via = new ArrayList(); //Via needs a List as input
@@ -192,7 +269,7 @@ public class VoIP implements SipListenerExt
request.addHeader(allow);
request.addHeader(expire);
request.addHeader(auth);
System.out.println(request);
//System.out.println(request);
this.sipProvider.sendRequest(request);
}
catch (ParseException | SipException |InvalidArgumentException ex) {
@@ -202,7 +279,8 @@ public class VoIP implements SipListenerExt
}
else if (responseEvent.getResponse().getStatusCode() == Response.OK)
{
System.out.println("responseEvent.getResponse()" + responseEvent.getResponse());
//System.out.println("responseEvent.getResponse()" + responseEvent.getResponse());
System.out.println("Server hat Registrierung akzeptiert");

}


Loading…
Cancel
Save