Liferay Chat Portlet

A practical guide to building a complete corporate intranet with Liferay

Working with Chat Portlet

For the purpose of this article, we will use an intranet website called book.com  which is created  for a fictions company named "Palm Tree Publications".

In order to let employees enjoy chatting and instant messaging with others, we should use the Liferay Chat portlet. Let's experience how to enjoy chatting and instant messaging first.

As an administrator of "Palm Tree Publications", you need to create a Page called "Instant Messaging" under the Page, "Community", at the Book Lovers Community and also add the Chat portlet in the Page, "Instant Messaging".

Adding a Participant

First of all, log in as "Palm Tree" and do the following:

  1. Add a Page called "Instant Messaging" under the Page, "Community" at the Book Lovers Community Public Pages, if the Page is not already present.
  2. Add the Chat portlet in the Page, "Instant Messaging" of the Book Lovers Community where you want to set up chatting and an instant messaging environment, if Chat portlet is not already present.

After adding the Chat portlet, you can view it as shown in the following figure.

Then, we need to add a participant in the Chat portlet. As an editor at the Editorial department, "Lotti Stein" wants to ping the manager, "David Berger", online and further share some comments about Liferay books. Let's do it as follows:

  1. Login as "Lotti Stein" first.
  2. Go to the Page, "Instant Messaging", " under the Page, "Community", at the Book Lovers Community Public Pages.
  3. Click on the Add icon.
  4. Input a participant's email address, such as "david@book.com".
  5. Press the Enter key.

You will see the participant's full name appear, such as "David Berger". After adding more participants, such as "John Stuckia" and "Rolf Hess", you can view all participants as shown in the following figure.

Managing Participants

All the Users you've invited will appear as a list of participants. If the User "David Berger" is online ,then the icon to the left of the User name becomes light blue. Otherwise, it remains light gray; for example, User "John Stuckia". As shown in the following figure, only two Users ("David Berger" and "Lotti Stein") are online in the server. For details about OpenFire, refer to the forthcoming section.

The participants are removable. For example, "Lotti Stein" wants to remove a participant "Rolf Hess", from the list of participants. Let's do it as follows:

  1. Locate the participant, such as "Rolf Hess".
  2. Click on the icon to the left of the User name, such as "Rolf Hess". You will see that the participant "Rolf Hess" is highlighted.
  3. Click the Remove icon. This participant will be removed from the list of participants.

In short, to remove a User from the list of participants, simply locate the User you want to remove by clicking on the icon to the left of the User name. Then, click the Remove icon. The selected User name will be removed from the list of participants.

Starting Chatting

Irrespective of whether the participants are online or not, you can begin to Chat with them. For example, as an editor of editorial department, "Lotti Stein" wants to start chatting with the manager, "David Berger". Let's do it as follows:

  1. Locate the participant, "David Berger".
  2. Click the User name, "David Berger".
  3. A Chat box will appear.
  4. Input the message, "David, how are you?"
  5. Press the Enter key. Your messages will appear starting with the keyword, Me, in the message box (as shown in the following figure).

As a manager of the editorial department, "David Berger" will have to do the following, to receive the messages from "Lotti Stein":

  1. Login as "David Berger" in new browser.
  2. Go to the Page, "Instant Messaging" under the Page, "Community" at the Book Lovers Community Public Pages.
  3. Locate the participant, "Lotti Stein".
  4. Click the User name, "Lotti Stein".
  5. A chat box will appear with the messages from "Lotti Stein".
  6. Input the message, "I am fine, and you?"
  7. Press the Enter key. Your messages will appear starting with the keyword "Me:" in the message box and the messages sent by the other User, "Lotti Stein" here, will appear starting with the User's name as shown in the following figure:

Generally, to start chat, locate the User you want to chat with, by the User name first. Click on the User name link. A Chat box will appear. You can chat with many Users at the same time. To do this, just click on the Users' name link. Each Chat box is only for one unique User.

The Chat box contains the User's name on the upper left. You can close the current Chat box by clicking on the mark X to the upper right.

Note that the Chat box is hidden in your current Page initiatively. Whenever a new message comes from the User, you are chatting with, the Chat box will pop up with the new message and possible previous messages.

To send messages, simply input your messages in the message input box first, and then press the Enter key. Your messages will appear starting with the keyword, Me, in the message box, and the messages sent by the other Users will appear starting with their User names.

How Does It Work?

Liferay Chat portlet (AJAX Instant Messaging) allows Users to automatically chat over XMPP (Jabber) protocol with other Users. Instant Messaging lets members interact with other members in real time. A private room may exists for customers which could give them access to others.

Liferay Chat portlet integrates with a Jabber server, that is, OpenFire. This session will introduce Instant Messaging, AJAX, and Jabber (OpenFire).

OpenFire (previously known as Wildfire Server) is a real-time collaboration (RTC) server, adopted open protocol for instant messaging, XMPP (also called Jabber). URL: http://www.jivesoftware.com/products/openfire/.

Use Instant Messaging

Instant messaging (IM) acts as a form of real-time communication among Users, based on typed text. It allows easy collaboration. In contrast to email, the participants know whether the peer is available. Conversations by instant messaging can be saved for later reference.

One of the Instant Messaging protocols is Extensible Messaging and Presence Protocol (XMPP).

XMPP is an open, XML-inspired protocol for near-real-time, extensible instant messaging (IM) and presence information. It is the core protocol of the Jabber Instant Messaging and Presence technology. URL: http://www.xmpp.org/.

On the one hand, XMPP is based on open standards, different from other instant messaging protocols. Similar to email, XMPP is an open system where a User having a domain name and a suitable Internet connection can run a Jabber server, and talk to others on other servers.

On the other hand, another useful feature of the XMPP system is, transports, also called gateways. Through this, Users can access networks using other protocols. These protocols can be other instant messaging protocols, such as SMS or Email. The case is different from multi-protocol clients, as Users can access XMPP server at the server level. That is, it communicates with other servers through gateway services, which are running on a remote server.

Another interesting feature of XMPP is the HTTP binding behind restricted firewalls.

For instance, Community A User wants to chat with Community B User. Community A User and Community B User have accounts on the Jabber Server and the Third Part Server respectively. When Community A User types in and sends his/her message, a sequence of events is set in action, as shown in the following figure:

  • Community A User's client sends his/her message to the Jabber Server.
    • If Third Part Server is blocked on Jabber Server, the message is dropped.
  • The Jabber Server opens a connection to the Third Part Server.
  • The Jabber server delivers the message to Community B User.
    • If Jabber Server is blocked on Third Part Server, the message is dropped.
  • If Community B User is not currently connected, the message is stored for later delivery.

Jabber is the Linux of instant messaging—an open, secure, ad-free alternative to consumer IM services. URL: http://www.jabber.org/

Employ AJAX

AJAX is Asynchronous JavaScript and XML. In short, AJAX makes portal Pages feel more responsive, by exchanging minimum amounts of data with the server. Thus, the entire portal Page does not have to be reloaded, when the User requests a change. You can use AJAX to increase the portal Page's interactivity, usability, functionality and speed.

In other words, AJAX acts as an asynchronous data transfer mechanism, that is, HTTP requests, between the browser and the portal server, allowing portal Pages to request a few bits of information from the server, instead of whole portal Pages. The AJAX makes portal applications smaller, faster and more user-friendly as shown in the following figure:

In general, AJAX is based on the following standards:

  • JavaScript—Scripting language of the Web
  • XML—Extensible Markup Language
  • XHTML (or HTML)—Extensible Hypertext Markup Language
  • CSS—Cascading Style Sheets

AJAX follows web standards supported by all major browsers. Thus, AJAX applications are browser and platform independent. The main advantage of AJAX is the separation of data, format, style, and function.

Using Chat Portlet Effectively

The Chat portlet allows Users to chat over XMPP protocol with other logged-in Users automatically. In order to use the Chat portlet effectively, let's set up an XMPP server and configure Liferay.

Set up XMPP Server

First, we have to set up a XMPP (Jabber) server. Suppose that we use OpenFire as an XMPP (Jabber) server. Here are the steps to set up OpenFire as follows:

  1. Create a folder, and name it OpenFire.
  2. Download the OpenFire.
  3. Extract the file to the OpenFire folder.
  4. Open the OpenFire folder and furthermore, bin.
  5. Click on openfire_x_x_x.exe or unzip openfire_x_x_x.tar.gz.
  6. Click Launch Admin.
  7. Proceed with configuring OpenFire based on your requirements, as shown in the following figure.

Configure Liferay

Then, you need to configure the XMPP server (such as OpenFire) with Liferay. You can simply open portal-ext.properties at $LIFERAY_ROOT/webapps/Root/WEB-INF/classes.

You just enter the following lines (Suppose that OpenFire and Liferay are on the same server):

jabber.xmpp.server.enabled=true
reverse.ajax.enabled=true

If you want to configure the integration by default settings, here are some options. The following is the complete set of properties related to the setup of XMPP server.

jabber.xmpp.server.enabled=false
jabber.xmpp.server.address=localhost
jabber.xmpp.server.name=localhost
jabber.xmpp.server.port=5222
jabber.xmpp.user.password=admin

You can also configure the Chat portlet when XMPP server is on a separate server. The following lines are a real example.

jabber.xmpp.server.enabled=true
reverse.ajax.enabled=true
jabber.xmpp.server.address=liferay.cignex.com
jabber.xmpp.server.name=liferay-cignex
jabber.xmpp.server.port=5222
jabber.xmpp.user.password=admin

Note that you have to turn firewall off in Windows for the Chat Portlet to run properly.

Summary

In this article we discussed how to add a participant for chatting, how to manage (view and delete) participants in the Chat portlet, how to start chatting, and how to set up the Chat portlet.

Books to Consider

Liferay Portal Enterprise Intranets
$ 35.99
Liferay Portal 6 Enterprise Intranets
$ 23.40
Instant Liferay Portal 6 Starter
$ 19.99
comments powered by Disqus
X

An Introduction to 3D Printing

Explore the future of manufacturing and design  - read our guide to 3d printing for free