Categories

MSG-Moodle Block - how it works

A brief video shows how the MSG-Moodle authentication works.

When a user logs in to Moodle (and they are enrolled on a course with MSG-Moodle configured), the javascript added to the Moodle theme header and footer is triggered to communicate with the MSG server. Firstly a call is made to check whether the user is already logged in to MSG (they may have the client open in another browser window), if they are logged in their presence icon is updated and another call is made to get the presences of their contacts who also have their presence icon showing on the current page (e.g. in a forum posting page).

If the user is not logged in, they are automatically logged in to MSG. This happens by sending the MSG server the users current Moodle cookie. The MSG server then validates this cookie (by calling the validate.php service in MSG-Moodle block) and creates for the user an MSG session ID. A background process then starts on the MSG server to update the user and group membership information using the users.php and groups.php services in MSG-Moodle block.

The javascript also triggers processes to run on the users’ browser to keep the number of online contacts up to date and to check for contacts presence changes, new messages etc. These processes are called repeatedly by making use of javascripts setTimeout() function. The processes running are:

  • GetGlobalContacts - updates the number of users on and offline from a service on MSG-Moodle block
  • GetPersonalContacts - updates the number of users personal contacts who are on and offline from a service on MSG-Moodle block
  • Peek - This connects to the BuddyXML service on the MSG server to monitor for notifications of presence state changes and for new messages received. The peek process opens a connection to the BuddyXML server, this connection is held open while waiting for a response from BuddyXML. BuddyXML will repond either after 45 seconds (timeout setting) or if a presence state change occurs or is a new message is received, which ever is sooner. If a presence state change notification is received then the presence icon is updated for the relevant user. If a new message is recvied for the currently logged in user then the users presence icon is updated with an exclamation mark. The reason for holding the connection open in this way is so that the BuddyXML doesn’t need to return all the users contacts presences, which could be quite a large data set if the user had a lot of contacts, so instead only changes to presences are returned.

The timeouts for all these processes can be adjusted using the MSG-Moodle block settings.

Although BuddyXML provides a service for logging a user out of MSG (disconnecting), this is not made use of in the MSG-Moodle block implementation. The users connection is maintained through the presence icon in the Moodle header and the javascript process requests described above. If the user doesn’t have MSG client running (or MSG Alert) and navigates away from Moodle, they are automatically logged out of MSG after 2 minutes.

MSG-Moodle uses JSON style (see: http://en.wikipedia.org/wiki/JSON) services to communicate with an MSG server. MSG-Moodle also provides services to the MSG server to populate the user and group memberships in Openfire. Users groups are automatically created based on their enrolments to Moodle courses.