Liferay Chat Portlet

Exclusive offer: get 50% off this eBook here
Liferay Portal Enterprise Intranets

Liferay Portal Enterprise Intranets — Save 50%

A practical guide to building a complete corporate intranet with Liferay

A$35.99    A$18.00
by Jonas X. Yuan | February 2009 | Content Management Java Open Source

As an administrator of an intranet website, you are required to provide an environment for employees to enjoy chatting, instant messaging and others. This article by Jonas X. Yuan will introduce to us, how to enjoy instant messaging.

In this article we will learn how to:

  • Add a participant for chatting.
  • Manage (view and delete) participants in the chat portlet.
  • Start chatting.
  • Set up chat portlet.

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.

Liferay Portal Enterprise Intranets A practical guide to building a complete corporate intranet with Liferay
Published: April 2008
eBook Price: A$35.99
Book Price: A$59.99
See more
Select your format and quantity:

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.

Liferay Portal Enterprise Intranets A practical guide to building a complete corporate intranet with Liferay
Published: April 2008
eBook Price: A$35.99
Book Price: A$59.99
See more
Select your format and quantity:

About the Author :


Jonas X. Yuan

Jonas X. Yuan is a Chief Architect of ForgeLife LLC and an expert on Liferay Portal, e-commerce, and Content Management Systems (CMS). As an open source community contributor, he has published five Liferay books from 2008 to 2012. He is also an expert on Liferay integration with Ad Server OpenX, different search engines, enterprise content including videos, audio, images, documents, and web contents, and other technologies, such as BPM Intalio and Business Intelligence Pentaho, LDAP, and SSO. He holds a Ph.D. in Computer Science from the University of Zurich, where he focused on Integrity Control in federated database systems.

He earned his M.S. and B.S. degrees from China, where he conducted research on expert systems for predicting landslides. Previously, he worked as a Project Manager and a Technical Architect in Web GIS (Geographic Information System).
He is experienced in Systems Development Lifecycle (SDLC) and has deep, hands-on skills in J2EE technologies. He developed a BPEL (Business Process Execution Language) engine called BPELPower from scratch at the NASA data center. As the chief architect, Dr. Yuan successfully led and launched several large-scale Liferay/Alfresco e-commerce projects for millions of users each month.

He has worked on the following books: Liferay Portal Enterprise Intranets, 2008; Liferay Portal 5.2 Systems Development, 2009; Liferay Portal 6 Enterprise Intranets, 2010; Liferay User Interface Development, 2010; Liferay Portal Systems Development, 2012.

Books From Packt

Drupal 6 Social Networking
Drupal 6 Social Networking

Alfresco Developer Guide
Alfresco Developer Guide

Learning Joomla! 1.5 Extension Development
Learning Joomla! 1.5 Extension Development

Joomla! Web Security
Joomla! Web Security

OpenCms 7 Development
OpenCms 7 Development

WordPress Plug-in Development (Beginner's Guide)
WordPress Plug-in Development (Beginner's Guide)

Apache OFBiz Development: The Beginner's Tutorial
Apache OFBiz Development: The Beginner's Tutorial

Drupal for Education and E-Learning
Drupal for Education and E-Learning

Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software