|
|
@@ -35,7 +35,8 @@ import logger.OhmLogger; |
|
|
|
|
|
|
|
/** |
|
|
|
* |
|
|
|
* @author Normal |
|
|
|
* @author Jan |
|
|
|
* komplettes Model für VoIP |
|
|
|
*/ |
|
|
|
public class VoIP implements SipListenerExt |
|
|
|
{ |
|
|
@@ -50,15 +51,16 @@ public class VoIP implements SipListenerExt |
|
|
|
ListeningPoint listeningPoint; // SIP listening IP address/port. |
|
|
|
Properties properties; // Other properties. |
|
|
|
|
|
|
|
private int counter; |
|
|
|
private int counter = 10; |
|
|
|
|
|
|
|
private int myPort = 5060; |
|
|
|
|
|
|
|
private String myName = "129"; |
|
|
|
private String protocolTyp = "UDP"; |
|
|
|
private String myIPAddress; |
|
|
|
private String proxyAddress; |
|
|
|
|
|
|
|
|
|
|
|
Boolean invite; |
|
|
|
RequestEvent evtWerdeAngerufen; |
|
|
|
|
|
|
|
int tag = (new Random()).nextInt(); |
|
|
|
private int branch = hashCode(); |
|
|
@@ -73,6 +75,9 @@ public class VoIP implements SipListenerExt |
|
|
|
//wird an sich erstmal nicht gebraucht aber später sinnvoll um eigene Daten zu initialisieren |
|
|
|
String abc = InetAddress.getLocalHost().getHostAddress(); |
|
|
|
invite = true; |
|
|
|
proxyAddress = ""; |
|
|
|
evtWerdeAngerufen = null; |
|
|
|
|
|
|
|
this.myIPAddress = InetAddress.getLocalHost().getHostAddress(); |
|
|
|
|
|
|
|
this.sipFactory = SipFactory.getInstance(); |
|
|
@@ -89,7 +94,6 @@ public class VoIP implements SipListenerExt |
|
|
|
this.contactAddress = this.addressFactory.createAddress("sip:129@" + this.myIPAddress + ":" + this.myPort); //+ ":" + this.myPort |
|
|
|
this.contactHeader = this.headerFactory.createContactHeader(contactAddress); |
|
|
|
|
|
|
|
//proxyAddress = ""; |
|
|
|
} |
|
|
|
catch (Exception e) |
|
|
|
{ |
|
|
@@ -108,8 +112,8 @@ public class VoIP implements SipListenerExt |
|
|
|
public void sendRegister(String serverIP, int serverPort) throws ParseException, InvalidArgumentException, SipException |
|
|
|
{ |
|
|
|
lg.info("Vorbereiten des Registrierungs Headers"); |
|
|
|
proxyAddress = serverIP + ":"+ serverPort; |
|
|
|
Address addressto = this.addressFactory.createAddress("sip:"+proxyAddress); //evtl. mit Port: sip:192.168.100.11:5060 |
|
|
|
proxyAddress = serverIP + ":" + serverPort; |
|
|
|
Address addressto = this.addressFactory.createAddress("sip:" + proxyAddress); //evtl. mit Port: sip:192.168.100.11:5060 |
|
|
|
//Address addressto = this.addressFactory.createAddress("sip:192.168.100.11"); |
|
|
|
ToHeader to = this.headerFactory.createToHeader(addressto, null); // Integer.toString(tag) address + tag |
|
|
|
URI requestURI = addressto.getURI(); |
|
|
@@ -130,10 +134,14 @@ public class VoIP implements SipListenerExt |
|
|
|
lg.info("Erfolgreiches Senden der Registrierung"); |
|
|
|
} |
|
|
|
|
|
|
|
public void sendInvitation(String sipaddresse, String proxyaddresse, int serverPort) throws ParseException, InvalidArgumentException, SipException, SdpException |
|
|
|
public void sendInvitation(String sipaddresse, String proxyaddresse, |
|
|
|
int serverPort) throws ParseException, InvalidArgumentException, SipException, SdpException |
|
|
|
{ |
|
|
|
invite = true; |
|
|
|
Address addressto = this.addressFactory.createAddress("sip:"+sipaddresse+"@"+proxyaddresse); //evtl. mit Port: sip:192.168.100.11:5060 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Address addressto = this.addressFactory.createAddress("sip:" + sipaddresse + "@" + proxyaddresse); //evtl. mit Port: sip:192.168.100.11:5060 |
|
|
|
//Address addressto = this.addressFactory.createAddress("sip:121@192.168.100.11"); |
|
|
|
ToHeader to = this.headerFactory.createToHeader(addressto, null); // Integer.toString(tag) address + tag |
|
|
|
URI requestURI = addressto.getURI(); |
|
|
@@ -155,10 +163,9 @@ public class VoIP implements SipListenerExt |
|
|
|
request.addHeader(content); |
|
|
|
|
|
|
|
request.setContent(createSDPHeader(), content); |
|
|
|
System.out.println("---Invitation Header---"); |
|
|
|
System.out.println(request); |
|
|
|
this.sipProvider.sendRequest(request); |
|
|
|
//lg.info("Erfolgreiches Senden der Invitation"); |
|
|
|
|
|
|
|
lg.info("Erfolgreiches Senden der Invitation"); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
@@ -203,82 +210,15 @@ public class VoIP implements SipListenerExt |
|
|
|
else if ((Request.INVITE).equals(requestEvent.getRequest().getMethod())) // Invite von anderem Benutzer |
|
|
|
{ |
|
|
|
FromHeader abc = (FromHeader) requestEvent.getRequest().getHeader("From"); |
|
|
|
String name = abc.getName(); |
|
|
|
view.getTxtArea().append("Werde von "+name+" angerufen\n"); |
|
|
|
view.getTxtArea().append("Werde von " + abc.getAddress() + " angerufen\n"); |
|
|
|
evtWerdeAngerufen = requestEvent; |
|
|
|
lg.info("Hab Invitation bekommen"); |
|
|
|
try |
|
|
|
{ |
|
|
|
//Trying Message to Server (Response 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); |
|
|
|
view.getTxtArea().append("Trying geschickt\n"); |
|
|
|
lg.info("Trying ist raus"); |
|
|
|
|
|
|
|
//Ringing Message to Server (Responste 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"); |
|
|
|
String tempTag = String.valueOf(this.tag + Math.random()); |
|
|
|
temptoring.setTag(tempTag); //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); |
|
|
|
view.getTxtArea().append("Ringing geschickt\n"); |
|
|
|
|
|
|
|
//Jetzt kommt 200 Ok SIP Header + SDP (SIP/SDP) |
|
|
|
//Sdp Header erstellen nächster Schritt |
|
|
|
invite = false; |
|
|
|
System.out.println(requestEvent.getDialog()); |
|
|
|
Response okandSDP = this.messageFactory.createResponse(Response.OK, requestEvent.getRequest()); |
|
|
|
//okandSDP.addHeader((ViaHeader) requestEvent.getRequest().getHeader("Via")); |
|
|
|
okandSDP.addHeader((FromHeader) requestEvent.getRequest().getHeader("From")); |
|
|
|
|
|
|
|
okandSDP.addHeader(temptoring); //evtl noch Ergänzungen |
|
|
|
|
|
|
|
okandSDP.addHeader((CSeqHeader) requestEvent.getRequest().getHeader("Cseq")); |
|
|
|
okandSDP.addHeader(contactHeader); |
|
|
|
okandSDP.addHeader(supp); |
|
|
|
okandSDP.addHeader(allow); |
|
|
|
okandSDP.addHeader(allowevent); |
|
|
|
ContentTypeHeader content = headerFactory.createContentTypeHeader("application", "sdp"); |
|
|
|
okandSDP.addHeader(content); |
|
|
|
okandSDP.setContent(createSDPHeader(), content); |
|
|
|
System.out.println(okandSDP); |
|
|
|
this.sipProvider.sendResponse(okandSDP); |
|
|
|
} |
|
|
|
catch (ParseException | SipException | SdpException ex) |
|
|
|
{ |
|
|
|
Logger.getLogger(VoIP.class.getName()).log(Level.SEVERE, null, ex); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
else if ((Request.ACK).equals(requestEvent.getRequest().getMethod())) |
|
|
|
{ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
@@ -384,11 +324,89 @@ public class VoIP implements SipListenerExt |
|
|
|
return sessionDescription; |
|
|
|
} |
|
|
|
|
|
|
|
public void annehmen() //Fehlende Bedingung |
|
|
|
{ |
|
|
|
RequestEvent requestEvent; |
|
|
|
if ((requestEvent=evtWerdeAngerufen) != null) |
|
|
|
{ |
|
|
|
|
|
|
|
try |
|
|
|
{ |
|
|
|
//Trying Message to Server (Response 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); |
|
|
|
view.getTxtArea().append("Trying geschickt\n"); |
|
|
|
lg.info("Trying ist raus"); |
|
|
|
|
|
|
|
//Ringing Message to Server (Responste 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"); |
|
|
|
String tempTag = String.valueOf(this.tag + Math.random()); |
|
|
|
temptoring.setTag(tempTag); //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); |
|
|
|
view.getTxtArea().append("Ringing geschickt\n"); |
|
|
|
|
|
|
|
//Jetzt kommt 200 Ok SIP Header + SDP (SIP/SDP) |
|
|
|
//Sdp Header erstellen nächster Schritt |
|
|
|
invite = false; |
|
|
|
System.out.println(requestEvent.getDialog()); |
|
|
|
Response okandSDP = this.messageFactory.createResponse(Response.OK, requestEvent.getRequest()); |
|
|
|
//okandSDP.addHeader((ViaHeader) requestEvent.getRequest().getHeader("Via")); |
|
|
|
okandSDP.addHeader((FromHeader) requestEvent.getRequest().getHeader("From")); |
|
|
|
|
|
|
|
okandSDP.addHeader(temptoring); //evtl noch Ergänzungen |
|
|
|
|
|
|
|
okandSDP.addHeader((CSeqHeader) requestEvent.getRequest().getHeader("Cseq")); |
|
|
|
okandSDP.addHeader(contactHeader); |
|
|
|
okandSDP.addHeader(supp); |
|
|
|
okandSDP.addHeader(allow); |
|
|
|
okandSDP.addHeader(allowevent); |
|
|
|
ContentTypeHeader content = headerFactory.createContentTypeHeader("application", "sdp"); |
|
|
|
okandSDP.addHeader(content); |
|
|
|
okandSDP.setContent(createSDPHeader(), content); |
|
|
|
System.out.println(okandSDP); |
|
|
|
this.sipProvider.sendResponse(okandSDP); |
|
|
|
|
|
|
|
evtWerdeAngerufen =null; |
|
|
|
} |
|
|
|
catch (ParseException | SipException | SdpException ex) |
|
|
|
{ |
|
|
|
Logger.getLogger(VoIP.class.getName()).log(Level.SEVERE, null, ex); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//Get Methoden falls man mal die Parameter braucht |
|
|
|
public void cancelcall() |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public String getmyName() |
|
|
|
{ |
|
|
|
return myName; |