SIP Servlet Engine© Documentations
 
  Top >   SIP Servlet Programming >    Basic Components >   SIP Signaling Component >   Chat Function
 
 

Chat Function

The chat functionality controls the chat function (IM) of OKISoftphone on the server side. The SIP servlet that implements the functionality (OkiChatServlet) provides the following functions:

  • Receives a chat message from OKISoftphone and redirect it to one or more destinations. Note that this is implemented as B2BUA, not a proxying.
  • Sends a chat message to multiple Softphones based on a message sending request from a Web screen.
  • Issues a message redirected by this servlet as an event for logging.
In the latest version (SIP Servlet Engine 3.0), only OKISoftphone is supported as a chat client.

OkiChatServlet supports the following two types of groups:

AdHoc Group
This group is generated upon starting a chat and its members are dynamically set.
Static Group
This group has members set in advance.

OkiChatServlet can be used as a SIP application without being processed, in which case it supports only the AdHoc group. The Static group becomes available by creating an application that inherits this class. Manage member information of the Static group using database, etc. in this application.

The specification overview of the chat function with OKISoftphone is as follows: For more information, see the OKI Softphone specification.

  • It uses the MESSAGE method to send a chat message, but works in the pager-mode that realizes a chat outside the SIP session.
  • It uses its own header, X-Chat-Id to hold the sessions between the SIP messages because SIP transactions are discarded every time and it can not use the transaction ID to relate the messages each other in the pager-mode.
  • There are three types of chat messages for different uses: These types can be identified by analyzing the message body.
Establishment of Chat Session
At the beginning of a chat, the sender side sends the MESSAGE with its empty body to establish the chat session. The receiver terminal responds to this with a 302 and the sender side sends the message with its body to the Contact.
End of Chat Session
At the end of a chat, the sender side sends the MESSAGE containing only the SIP URI of the sender.
Chat Message Sending
In normal message sending, the sender sends the MESSAGE containing the SIP URI of the sender on the first line, followed by the message body on the subsequent lines and : at the end.

The chat function consists of the following classes:

OkiChatServlet Class

package com.oki.sip.equips.signal;

public class OkiChatServlet extends BasicSipServlet {

    public String sendAdHocMessage(String sender, String receiver, String message, boolean echo);

    public String sendMessage(SipRequestParams params) throws Exception;

    protected  void addAdHocMember(String groupID, SipURI uri);
    protected  void removeAdHocMember(String groupID, SipURI uri);

    protected  void addGroup(ChatGroup group);
    protected  ChatGroup removeGroup(String groupID);

    protected  void setChatMessageListener(ChatMessageListener listener);
    protected  void removeChatMessageListener();

    protected  String sendAdHocMessage(SipURI sender, SipURI receiver, String message, boolean echo);

    protected  void sendMessage(SipURI sender, String groupID, String message, boolean echo);
    protected  void sendMessage(String sender, String groupID, String message, boolean echo);
}

The OkiChatServlet class is created as a servlet and defines two methods to request message sending as public methods.

sendAdHocMessage is a method that sends a message to the user specified in the receiver argument. It creates a new AdHoc group at the same time. The first argument sender specifies string representation of the SIP URI of the sender, the second argument receiver specifies string representation of the SIP URI of the receiver, and the third argument message specifies the message body string. The fourth argument echo is a flag to determine whether a message is also sent to the sender itself. If true, the message is also sent to the sender. If false, the message is not sent to the sender. It returns groupID of the destination chat group as a return value.

sendMessage is a method used to send a message from an HTTP servlet through SipRequestDispatcher.invoke. The following information can be set in SipRequestParams as application-specific arguments.

Parameter Name Specified Class Description
msg.groupID String Contains the destination group name. Specifies null if the target group does not exist (the message is sent to a new AdHoc group).
msg.receiver String Contains the SipURI (String representation) of the destination user. Creates a new AdHoc group if it is set to msg.receiver. Specifies null if the message is sent to a Static group or an existing AdHoc group.
msg.sender String Contains SipURI (String representation) of the destination user. This is a required attribute.
msg.message String Contains the message to be sent. This is a required attribute.

Like sendAdHocMessage, this method returns groupID of the destination chat group.

Other methods are protected methods that are invoked from an application that inherits this class.

addAdHocMember is a method that adds a member to the specified AdHoc group. The first argument groupID specifies a group ID of an existing AdHoc group. If the specified group does not exist, it creates a new AdHoc group with groupID.

removeAdHocMember is a method that deletes a member from the specified AdHoc group. If the AdHoc group specified in the first argument groupID does not exist, IllegalArgumentException is thrown. If the AdHoc group exists but the target member does not exist, no exception is thrown.

addGroup is a method to register a Static group. If you specify null or attempt to register a group already registered, IllegalArgumentException is thrown.

removeGroup is a method to delete a Static group. It returns the deleted group. If you attempt to delete a non-existing group, it returns null.

setChatMessageListener and removeChatMessageListener are methods that set or delete an event listener that receives all message logs via OkiChatServlet as an event. Only one event listener can be registered. If setChatMessageListener is invoked multiple times, only the last invocation is valid. The listener set with setChatMessageListener sends all messages including AdHoc groups as events. If you want to receive only messages within the specific group, use the event listening function of ChatGroup class.

The second sendAdHocMessage method provides the same function as the sendAdHocMessage method except that sendAdHocMessage uses the SipURI class to specify the sender and receiver.

sendMessage is a method to send a message to an existing group. The first argument sender specifies string representation of the SIP URI of the sender, the second argument groupID specifies ID information about the destination chat group. For an AdHoc group, the return value of the sendAdHocMessage method can be used as groupID. For a Static group, the return value of the getGroupID method of the ChatGroup interface can be used as groupID. The third argument message specifies the message body string. The fourth argument echo is a flag to determine whether a message is also sent to the sender itself. If true, the message is also sent to the sender. If false, the message is not sent to the sender.

ChatMessageListener Interface

com.oki.sip.equips.signal;

public interface ChatMessageListener {
    void messageLog(String groupID, ChatMember sender, Date time, String message); 
}

ChatMessageListener is an interface to receive an event of message logging. This interface only defines the messageLog method that delivers an event.

The first argument of messageLog represents ID information about the destination chat group. The second represents the sender of the message. The third represents sending time of the message. The forth represents the message body.

ChatGroup Interface

com.oki.sip.equips.signal;

public interface ChatGroup extends ChatMessageListener {
    String getGroupID();

    Collection getAllMemberList();
}

ChatGroup is an interface implemented by a class that represents a Static group.

getGroupID is a method that returns ID information for identifying a group. It must return a unique group ID in the system.

The AdHoc group uses a name beginning with "adhoc-" as a group ID. Do not use an overlapping group ID.

getAllMemberList is a method that returns a list of all the members who belong to the Static group. This method must return Cllection that contains the ChatMember object. This method is called each time a message is delivered. Therefore, change of a member that belongs to the Static group does not need to be sent to OkiChatServlet. The message is sent to members contained in the return value of this method .

ChatMember Class

com.oki.sip.equips.signal;

public class ChatMember {
    public ChatMember(SipURI uri, Address contact, String displayName);

    Address getContact();
    String getDisplayName();
    SipURI getURI();
}

ChatMember is a class that stores information about members joining in a chat group. It is used as the return value of getAllMemberList of the ChatGroup interface.

Last Modified:Thu Mar 25 12:29:15 AM JST 2004