Monday, August 08, 2016

xockets.io ...last few enhancements

download
The purpose of this post is to cover all the enhancements that have been added to the xockets.io xpages websocket plugin since version 2.0.2.  A good number of enhancements have been added, and up until now I've been a bit lazy when it comes to blogging about it.  This post will cover the following:
  • Addition of scriptable event observers (covers onOpen, onMessage, onClose, onError)
  • Multiple websocket connections per user based on URI  
  • Multiple targets in a SocketMessage
  • Send a collection of messages with one call

 

Event Observers:  

Event observers are scripts that fire after the main events of the xockets.io server (e.g. onOpen, onMessage, onClose, onError).  Unlike the Rhino client based event listeners, these event observer scripts fire against ALL connected client events.  Because these scripts fire for every event generated by all the connected clients it is very important to write high performance code so the script doesn't tie up the executing thread for too long.  A sample script that logs all the events is below, along with a link to a simple xockets logger application.  Using event observers is a two step process, build then register the script.

1)  Build your event observer script using the XPages SSJS design element.  Be sure your methods are named onOpen, onClose, onMessage, or onError, and that they accept the correct number of parameters (see sample script).


2) Call the websocketBean.addEventObserver method directly or register via console command



OR

If a change is made to an event observer, reload the script using the command line call (tell http osgi xockets reload-scripts)



Multiple websocket connections per user based on URI:

This enhancement allows for a single user session to have multiple websocket connections open across multiple pages / applications on the same server.


Multiple targets in a SocketMessage

This enhancement provides a way to send the same message to multiple people in a single send operation as opposed to sending a message to each websocket connection individually.  Should increase performance and bandwidth by reducing the total payload across the wire (see below sample):



Send a collection of messages with one call 

This enhancement makes it easy to send batches / collections of messages to one or more people in one call across the wire.  Note, the batch message will be interpreted as a single message when validating sizeHandy if storing messages when disconnected, and batch uploading them periodically.

No comments: