Thursday Jun 17, 2010

SailFin-CAFE GreetingService Demo

SailFin-CAFE provides functionality to create conversation between User and MediaGroup. For instance, a simple snippet for playing an announcement to a user would look like:

   Player p = session.createParticipant(Player.class, "myPlayer");
   Conversation conv = session.createConversation(p);
   conv.addParticipant("alice@example.com");

CommunicationBeans can be used to listen media events, DTMF signals and many other events, based on which application logic can be decided.

Listener for media event when a player(announcement) is finished would be:

    @CommunicationEvent(type = CommunicationEvent.Type.MEDIAENDED)
    public void mediaEnded() {
        ----- application logic ------
    }

DTMF Signal is intercepted through CommunicationEvent type MessageArrived:

    @CommunicationEvent(type=CommunicationEvent.Type.MESSAGEARRIVED)
    void handleMessage() {
        DtmfSignal ds = (DtmfSignal) ctx.getMessage();
        String signal = ds.getSignal();
    }

At the same time Communication API makes it very handy to replace participants in a conversation. eg. Replacing a user with media group or vice-versa.

All this makes it quite simple to write applications like GreetingService. The basic idea of a GreetingService is to allow users to record messages to be played to their friends at a particular date and time.

Following image illustrates the above:

Greeting Service Example

In the above scenario Alice wants to wish Bob, so she logs in and schedules a greeting for Bob. GreetingService calls Alice for recording the message, CommunicationBean is used to play initial announcement and receive DTMF signals to start/stop recording the message. 

Once the recording is finished, an agent(GreetingAgent) is invoked to schedule the Greeting. GreetingAgent calls recepient at scheduled time and plays announcement informing about the Greeting.

Based on the DTMF response of the recepient, greeting is either played or rejected. Sender is informed about the status of the Greeting through an InstantMessage.


  • The sample can be checked out at : http://svn-mirror.glassfish.org/sailfin-cafe/trunk/cafe-samples/GreetingService/
  • Useful Links : http://weblogs.java.net/blog/binod/archive/2009/12/31/sailfin-cafe-fundamentals-communicationbeans-and-agents
  • http://weblogs.java.net/blog/binod/archive/2010/05/14/sailfin-cafe-using-presence-and-conversation-together

Sunday Nov 22, 2009

Developing Sailfin CAFE Applications using Netbeans

Developing Sailfin CAFE Application with Netbeans is easier then ever. Resolve dependencies and build the project without any hassles.

Here's a quick guide to it:

- Create a new Netbeans project : File --> New Project
- In maven category, choose Maven Web Application, you will get the following window:


click finish to create a project.
- Right click on mavenproject1 - Source Packages and select new -> Java Class, to create a new Java Class.
- Make the class as CAFE CommunicationBean, by adding the following annotation:

@CommunicationBean
public class NewClass {
}

- For resolving the missing dependency, select the tooltip next to @CommunicationBean annotation and click on Search Dependency at maven repositories.

searching maven dependency

- the following suggestion box will appear, select cafe-communication-api and select Add.

select cafe-communication-api

- Save the project, click on the tooltip next to @CommunicatioBean and select import org.glassfish.cafe.api.bean.CommunicationBean

- Build the project and your CAFE Application is ready !!

- Steps to install and run the App:

  • Download and install latest SailFin V2 promoted build.
  • Download and install latest SailFin CAFE build.
  • Start SailFin and deploy the application. (eg: asadmin deploy mavenproject1.war)
  • Register two SIP phones with the help of steps mentioned here.
  • Click on Alice's phone and type "bob@example.com". Then click on green dial button. The bob's phone is ringing !!
  • Thursday Nov 05, 2009

    Sailfin CAFE - Click to Call using JSP

    Now your JSP is capable of establishing SIP calls. Thanks to Sailfin CAFE, no SIP Servlets needed !!!

    Here is the code you need to write:

    <%
        CommunicationSession commSession = (CommunicationSession) session.getAttribute("org.glassfish.cafe.communicationsession");
        String party1 = request.getParameter("party1");
        String party2 = request.getParameter("party2");
        try {
           Conversation conv = commSession.createConversation(party1);
           conv.addParticipant(party2);
           out.println("Call started between " + party1 + "and" + party2);
        } catch (Exception e) {
           e.printStackTrace();
        }
    %>


    Next, you would need to add a CAFE CommunicationBean to the Application.
    A simple CommunicationBean looks like:

    import org.glassfish.cafe.api.bean.CommunicationBean;

    @CommunicationBean
    public class CafeCommsBean {
    }


    Your Click to Call Application is ready !!

    Steps to install and run the App:

  • Download and install latest SailFin V2 promoted build.
  • Download and install latest SailFin CAFE build.
  • Package the application as a normal web application. For compilation, please use SAILFIN_HOME/lib/communication-api.jar.
  • Start/Restart SailFin and deploy the application (eg: asadmin deploy CafeApp.war).
  • Register two SIP phones by following the steps mentioned here.
  • Access http://localhost:8080/CafeApp
  • Enter the two user id's and click on call.
  • Click on the Answer button of the SIP Phones. The Call is established !!
  • About

    Mohit Gupta

    Search

    Categories
    Archives
    « April 2014
    SunMonTueWedThuFriSat
      
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
       
           
    Today