Download PSIptt - Push-To-Talk

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
PSIptt - Push-To-Talk
Client API Documentation
Version 1.4.5
Stand 22.06.2009
© PSI Transcom GmbH 2009
Content
1 INTRODUCTION...................................................................................3
1.1 REQUIREMENTS.......................................................................................................3
2 CONCEPT.............................................................................................4
2.1 ONLINE RESOURCES:............................................................................................... 4
3 EXAMPLES...........................................................................................5
3.1 J2SE CLIENT API INTEGRATION................................................................................5
3.2 WEB BASED JAVA APPLET EXAMPLE.........................................................................6
3.2.1 Applet example HTML code..................................................................................................9
Seite 2 von 10
1 Introduction
In this document the PSIptt JAVA Client API will be introduced and explained by
example.
This document only describes the current Version of the API wich may change at
any time. So there will be some handworks nessecary to upgrade to a newer
version.
1.1 Requirements
To use this API you need to have a JAVA RuntimeEnvironment version 1.5 or
greater. For integration projects the JAVA version of the project application needs to
be at least version 1.5.
2 Concept
The PSIptt Client API consists of one jar-file, JavaDoc and Examples. At the
moment the jar-file being used is the same file as the pttclient.jar from the PC
desktop client. It will be separated to a smaller file (not containing the GUI code) to
reduce space and netload on web-based applications.
2.1 Online Resources:
The current JavaDocs and other manuals and guides can be found at
http://ptt.psi.de/docs .
Furthermore there are some examples wich show how to use the API. Location:
http://ptt.psi.de/docs .
The current version of the API itself is contained in the restricted area on
http://ptt.psi.de/download or can be requested directly from PSI Transcom GmbH via
mail to mailto://[email protected] .
3 Examples
Following this examples show the possibility to integrate PSIptt into nearly any JAVA
application.
The examples shown here are very basic and cover only simple features such as
connection establishment. To See a complete List of possible API functions and
listeners see online JavaDoc.
3.1 J2SE Client API Integration
In this example we show a simple setup to connect with the API to a PSIptt server.
The only thing it does is printing successful connection to stdout. Groupcalls are also
being played so you are able to listen already, if your VM supports the Java MM API.
package de.psi.telco.voip.clientapi.examples;
import
import
import
import
import
de.psi.telco.voip.clientapi.PTTAbstractClientListener;
de.psi.telco.voip.clientapi.PTTClientImpl;
de.psi.telco.voip.clientapi.PTTClientInterface;
de.psi.telco.voip.clientapi.PTTClientListener;
de.psi.telco.voip.protocol.descriptors.ClientDescriptor;
/**
* This example shows how to create a PTTClient connection using the PTT
Client API.
* @author will
*
*/
public class PTTClientApiExample {
public static void main(String[] args) {
// create client instance
PTTClientInterface client = new PTTClientImpl();
// create some example listeners
// see PTTClientListener for useabel functions
PTTClientListener exampleListener = new
PTTAbstractClientListener(){
@Override
public void onPTTConnected(ClientDescriptor arg0) {
System.out.println("PTTClient conenction
established");
}
@Override
public void onPTTDisconnected(int arg0) {
System.out.println("PTTClient disconnected");
}
};
// register listener
client.addListener(exampleListener);
// do some connection config
client.setHost("ptt.psi.de");
client.setPort(4374);
client.setCredentials("customer", "username", "password");
}
}
// and connect
client.startPTTClient();
3.2 Web Based JAVA Applet Example
This Example is a PSIptt client via Java Applet in a brwoser.
package de.psi.telco.voip.clientapi.examples;
import java.awt.Dimension;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import
import
import
import
javax.swing.JApplet;
javax.swing.JButton;
javax.swing.JLabel;
javax.swing.JPanel;
import
import
import
import
org.apache.log4j.Appender;
org.apache.log4j.ConsoleAppender;
org.apache.log4j.Logger;
org.apache.log4j.PatternLayout;
import de.psi.telco.util.NoObfuscate;
import de.psi.telco.voip.clientapi.PTTAbstractClientListener;
import
import
import
import
de.psi.telco.voip.clientapi.PTTClientImpl;
de.psi.telco.voip.clientapi.PTTClientInterface;
de.psi.telco.voip.clientapi.PTTClientListener;
de.psi.telco.voip.protocol.descriptors.ClientDescriptor;
/**
* This example demonstrate how to integrate PSIptt client into an Web
Application using a JavaApplet.
* @author will
*
*/
public class PTTClientAppletExample extends JApplet implements NoObfuscate{
// config
public static
public static
public static
public static
public static
String HOST = "ptt.psi.de";
int PORT = 4374;
String CUSTOMER = "customer";
String USER = "username";
String PASSWORD = "password";
// controller
PTTClientInterface client;
PTTClientListener clientListener;
// view
JPanel mainPanel;
JButton sendButton;
JLabel label;
public void init(){
// reassign log4j
Appender appender = new ConsoleAppender(new PatternLayout(),
"System.out");
Logger.getRootLogger().removeAllAppenders();
Logger.getRootLogger().addAppender(appender);
/*
* Init Applet GUI
*/
mainPanel = new JPanel();
mainPanel.setPreferredSize(new Dimension(200,100));
label = new JLabel("PTTClient: conencting");
mainPanel.add(label);
sendButton = new JButton();
sendButton.setText("Send");
sendButton.setEnabled(false); // not connected at first
mainPanel.add(sendButton);
addButtonListener();
/*
* Now PTT stuff
*/
client = new PTTClientImpl();
addClientListener();
// see funtion below
// load applet config (given via HTML)
loadParams();
}
this.add(mainPanel);
private void loadParams() {
if (getParameter("host") != null){
HOST = getParameter("host");
}
if (getParameter("port") != null){
PORT = Integer.parseInt(getParameter("port"));
}
if (getParameter("customer") != null){
CUSTOMER = getParameter("customer");
}
if (getParameter("username") != null){
USER = getParameter("username");
}
if (getParameter("password") != null){
PASSWORD = getParameter("password");
}
}
// and tell client to use values
client.setHost(HOST);
client.setPort(PORT);
client.setCredentials(CUSTOMER, USER, PASSWORD);
public void start(){
client.startPTTClient();
mainPanel.setVisible(true);
}
public void stop(){
client.stopPTTClient();
mainPanel.setVisible(false);
}
/**
* This method defines and binds our example client listener that
enables and disables the button.
*
*/
private void addClientListener(){
clientListener = new PTTAbstractClientListener(){
@Override
public void onPTTConnected(ClientDescriptor arg0) {
sendButton.setEnabled(true);
label.setText("PTTClient: connected");
}
};
@Override
public void onPTTDisconnected(int arg0) {
sendButton.setEnabled(false);
label.setText("PTTClient: disconnected");
}
}
}
client.addListener(clientListener);
private void addButtonListener(){
sendButton.addMouseListener(new MouseListener(){
public void mouseClicked(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mousePressed(MouseEvent e) {
client.startGroupCall();
}
public void mouseReleased(MouseEvent e) {
client.stopGroupCall();
}
});
}
3.1.1 Applet example HTML code
Following HTML code loads the applet using credentials parameters from HTML.
This is useful for external user management from calling Web-Applications.
So, make sure you edit the parameters custmer, username, password (XXX,
YYY, ZZZ in code below) accordingly to match your PSIptt account!
<html>
<head>
<title>PTTClientApplet Example</title>
</head>
<body>
<h1>PTTClientApplet Example</h1>
<!-- Applet Code -->
<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
width="200px" height="100px" codebase="http://java.sun.com/products/plugin/
1.2.2/jinstall-1_2_2-win.cab#Version=1,2,2,0">
<PARAM name="java_code"
value="de.psi.telco.voip.clientapi.examples.PTTClientAppletExample.class">
<PARAM name="java_archive" value="pttclient.jar">
<PARAM name="type" value="application/x-javaapplet;version=1.5">
<PARAM name="customer" value="XXX">
<PARAM name="username" value="YYY">
<PARAM name="password" value="ZZZ">
<COMMENT>
<EMBED type="application/x-java-applet;version=1.5"
width="200px" height="100px"
pluginspage="http://java.sun.com/products/plugin/"
java_code="de.psi.telco.voip.clientapi.examples.PTTClientAppletExample.clas
s" java_archive="pttclient.jar" customer="XXX" username="YYY"
password="ZZZ" />
<NOEMBED>Your browser does not support this JAVA
applet.</NOEMBED>
</COMMENT>
</OBJECT>
</body>
</html>
Related documents