Ergänzungen
This commit is contained in:
+54
-34
@@ -40,7 +40,7 @@ import logger.OhmLogger;
|
||||
public class VoIP implements SipListenerExt
|
||||
{
|
||||
Hauptfenster view; //später entfernen wegen Zugriff
|
||||
private static final Logger lg = OhmLogger.getLogger();
|
||||
private static final Logger lg = OhmLogger.getLogger();
|
||||
SipFactory sipFactory; // Used to access the SIP API.
|
||||
SipStack sipStack; // The SIP stack.
|
||||
SipProvider sipProvider; // Used to send SIP messages.
|
||||
@@ -49,19 +49,21 @@ public class VoIP implements SipListenerExt
|
||||
AddressFactory addressFactory; // Used to create SIP URIs.
|
||||
ListeningPoint listeningPoint; // SIP listening IP address/port.
|
||||
Properties properties; // Other properties.
|
||||
|
||||
|
||||
private int counter;
|
||||
private int myPort = 5060;
|
||||
|
||||
private String myName = "129";
|
||||
private String protocolTyp = "UDP";
|
||||
private String myIPAddress;
|
||||
private String proxyAddress;
|
||||
|
||||
Boolean invite;
|
||||
|
||||
int tag = (new Random()).nextInt();
|
||||
private int branch = hashCode();
|
||||
Address contactAddress;
|
||||
private ContactHeader contactHeader;
|
||||
|
||||
|
||||
|
||||
public VoIP(Hauptfenster view) //Konstruktor für eigene Daten
|
||||
{
|
||||
@@ -70,7 +72,7 @@ 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;
|
||||
this.myIPAddress = InetAddress.getLocalHost().getHostAddress();
|
||||
|
||||
this.sipFactory = SipFactory.getInstance();
|
||||
@@ -86,11 +88,12 @@ public class VoIP implements SipListenerExt
|
||||
this.sipProvider.addSipListener(this);
|
||||
this.contactAddress = this.addressFactory.createAddress("sip:129@" + this.myIPAddress + ":" + this.myPort); //+ ":" + this.myPort
|
||||
this.contactHeader = this.headerFactory.createContactHeader(contactAddress);
|
||||
*/
|
||||
|
||||
//proxyAddress = "";
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println("Shit");
|
||||
System.out.println("Fehler bei Initialisierung eigener Addresse");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
@@ -104,12 +107,10 @@ public class VoIP implements SipListenerExt
|
||||
|
||||
public void sendRegister(String serverIP, int serverPort) throws ParseException, InvalidArgumentException, SipException
|
||||
{
|
||||
System.out.println("Test");
|
||||
System.out.println(serverIP);
|
||||
lg.info("Vorbereiten des Registrierungs Headers");
|
||||
//Address addressto = this.addressFactory.createAddress("sip:"+serverIP); //evtl. mit Port: sip:192.168.100.11:5060
|
||||
Address addressto = this.addressFactory.createAddress("sip:192.168.100.11");
|
||||
System.out.println("Warum" + addressto);
|
||||
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();
|
||||
CallIdHeader callId = this.sipProvider.getNewCallId();
|
||||
@@ -128,9 +129,12 @@ public class VoIP implements SipListenerExt
|
||||
this.sipProvider.sendRequest(request);
|
||||
lg.info("Erfolgreiches Senden der Registrierung");
|
||||
}
|
||||
public void sendInvitation(String sipaddresse, int serverPort)throws ParseException, InvalidArgumentException, SipException, SdpException
|
||||
|
||||
public void sendInvitation(String sipaddresse, String proxyaddresse, int serverPort) throws ParseException, InvalidArgumentException, SipException, SdpException
|
||||
{
|
||||
Address addressto = this.addressFactory.createAddress("sip:"+sipaddresse); //evtl. mit Port: sip:192.168.100.11:5060
|
||||
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:121@192.168.100.11");
|
||||
ToHeader to = this.headerFactory.createToHeader(addressto, null); // Integer.toString(tag) address + tag
|
||||
URI requestURI = addressto.getURI();
|
||||
CallIdHeader callId = this.sipProvider.getNewCallId();
|
||||
@@ -146,9 +150,10 @@ public class VoIP implements SipListenerExt
|
||||
request.addHeader(contactHeader);
|
||||
request.addHeader(allow);
|
||||
request.addHeader(expire);
|
||||
|
||||
|
||||
ContentTypeHeader content = headerFactory.createContentTypeHeader("application", "sdp");
|
||||
request.addHeader(content);
|
||||
|
||||
request.setContent(createSDPHeader(), content);
|
||||
System.out.println("---Invitation Header---");
|
||||
System.out.println(request);
|
||||
@@ -197,13 +202,14 @@ public class VoIP implements SipListenerExt
|
||||
//Aktive Kommunikation
|
||||
else if ((Request.INVITE).equals(requestEvent.getRequest().getMethod())) // Invite von anderem Benutzer
|
||||
{
|
||||
view.getTxtArea().append("Werde von xxx angerufen\n");
|
||||
FromHeader abc = (FromHeader) requestEvent.getRequest().getHeader("From");
|
||||
String name = abc.getName();
|
||||
view.getTxtArea().append("Werde von "+name+" angerufen\n");
|
||||
lg.info("Hab Invitation bekommen");
|
||||
try
|
||||
{
|
||||
//Trying Message to Server (Response Trying)
|
||||
|
||||
System.out.println("----REquest HEader----");
|
||||
|
||||
Response responsetry = this.messageFactory.createResponse(100, requestEvent.getRequest());
|
||||
responsetry.addHeader((ViaHeader) requestEvent.getRequest().getHeader("Via"));
|
||||
responsetry.addHeader((FromHeader) requestEvent.getRequest().getHeader("From"));
|
||||
@@ -217,7 +223,7 @@ public class VoIP implements SipListenerExt
|
||||
responsetry.addHeader(supp);
|
||||
responsetry.addHeader(allow);
|
||||
this.sipProvider.sendResponse(responsetry);
|
||||
view.getTxtArea().append("Trying geschickt");
|
||||
view.getTxtArea().append("Trying geschickt\n");
|
||||
lg.info("Trying ist raus");
|
||||
|
||||
//Ringing Message to Server (Responste Ringing)
|
||||
@@ -238,10 +244,11 @@ public class VoIP implements SipListenerExt
|
||||
AllowEventsHeader allowevent = this.headerFactory.createAllowEventsHeader("talk,hold");// für was gebraucht
|
||||
responsering.addHeader(allowevent);
|
||||
this.sipProvider.sendResponse(responsering);
|
||||
view.getTxtArea().append("Ringing geschickt");
|
||||
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"));
|
||||
@@ -316,14 +323,13 @@ public class VoIP implements SipListenerExt
|
||||
|
||||
//Zusätzliche Register Header nach Unauthorzied
|
||||
//Create Request Header
|
||||
System.out.println("----REQUEST HEADER2----");
|
||||
Request request = this.messageFactory.createRequest(requestURI, "REGISTER", callId, cSeq, from, to, via, maxForwards);
|
||||
request.addHeader(contactHeader);
|
||||
request.addHeader(allow);
|
||||
request.addHeader(expire);
|
||||
request.addHeader(auth);
|
||||
this.sipProvider.sendRequest(request);
|
||||
view.getTxtArea().append("Erfolgreich registriert");
|
||||
view.getTxtArea().append("Erfolgreich registriert\n");
|
||||
}
|
||||
catch (ParseException | SipException | InvalidArgumentException ex)
|
||||
{
|
||||
@@ -337,6 +343,7 @@ public class VoIP implements SipListenerExt
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public SessionDescription createSDPHeader() throws SdpException
|
||||
{
|
||||
/*
|
||||
@@ -352,33 +359,46 @@ public class VoIP implements SipListenerExt
|
||||
sessionDescription.setConnection(sdpFactory.createConnection("IN", "IP4", myIPAddress));
|
||||
|
||||
//Media Body
|
||||
String sdpformat[] =
|
||||
{
|
||||
"0", "4", "18",
|
||||
};
|
||||
Vector mediavec = new Vector();
|
||||
mediavec.add(sdpFactory.createMediaDescription("audio", 6022, 1, "RTP/AVP", sdpformat)); //(Übertragungstyp, Port, anzahl der Ports, Verbindungstyp,..)
|
||||
//Media Attribute
|
||||
mediavec.add(sdpFactory.createAttribute("sendrecv", null));
|
||||
mediavec.add(sdpFactory.createAttribute("rtpmap", "0 PCMU/8000"));
|
||||
mediavec.add(sdpFactory.createAttribute("rtpmap", "4 G723/8000"));
|
||||
mediavec.add(sdpFactory.createAttribute("rtpmap", "18 G729A/8000"));
|
||||
mediavec.add(sdpFactory.createAttribute("ptime", "20"));
|
||||
if (invite = true)
|
||||
{
|
||||
String sdpformat[] =
|
||||
{
|
||||
"0", "4", "8", "18",
|
||||
};
|
||||
mediavec.add(sdpFactory.createMediaDescription("audio", 6022, 1, "RTP/AVP", sdpformat)); //(Übertragungstyp, Port, anzahl der Ports, Verbindungstyp,..)
|
||||
//Media Attribute
|
||||
mediavec.add(sdpFactory.createAttribute("sendrecv", null));
|
||||
mediavec.add(sdpFactory.createAttribute("rtpmap", "0 PCMU/8000"));
|
||||
mediavec.add(sdpFactory.createAttribute("rtpmap", "4 G723/8000"));
|
||||
mediavec.add(sdpFactory.createAttribute("rtpmap", "8 PCMA/8000"));
|
||||
mediavec.add(sdpFactory.createAttribute("rtpmap", "18 G729/8000"));
|
||||
mediavec.add(sdpFactory.createAttribute("ptime", "20"));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
sessionDescription.setAttributes(mediavec);
|
||||
|
||||
return sessionDescription;
|
||||
}
|
||||
|
||||
|
||||
//Get Methoden falls man mal die Parameter braucht
|
||||
public void cancelcall()
|
||||
{
|
||||
|
||||
}
|
||||
public String getmyName()
|
||||
{
|
||||
return myName;
|
||||
}
|
||||
|
||||
public Integer getMyPort()
|
||||
{
|
||||
return myPort;
|
||||
}
|
||||
|
||||
public String getMyIPAdress()
|
||||
{
|
||||
return myIPAddress;
|
||||
|
||||
Reference in New Issue
Block a user