Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


The akioma.SocketConnection class is used to encapsulate every socket communication. The class provides methods, for connect, disconnect, seting global listeners and functionalities like showMessage, openContainer and others.

SocketConnection Helper class

A helper class is provided by the SWAT framework in order to easily emit events, add event listeners or to check if connection was established successfully.

Code Block
titleExample using isConnected and emit Helper methods
const isConnected:boolean = akioma.SocketConnectionHelper.isConnected();

if(isConnected) {
	akioma.SocketConnectionHelper.emit('openScreen', { name: 'offerw' });
}


Code Block
titleSocketConnection Helper Listener
akioma.SocketConnectionHelper.on('openScreen', (payload:any) => {
	if(payload.name) {
		akioma.swat.App.loadScreen({ containerName: payload.name });
	}
});



Ui-connector routes:

Code Block
languagejs
var controller = require('../controllers/ui-connector');
router.get('*', controller.all);

The * is getting all the requests and call the "all" method from ui-connector controller. In the controller, socket emit an "openContainer" event to the user specified in URL.

Example:

http://localhost:8844/uiConnector/axadmin/offerNewG/launch/?customer=11010&opportunity=12345&akIntegrationToken=0

This URL will emit an "openContainer" event for the user axadmin and open the offerNewG container. The crm.messaging.SocketConnection have a method called "setUpGlobalListeners" which set various listeners on akioma.socket, inclusive openContainer listener.


Treegrid socket functionality:

When opening an offer, first of all, it sets an event listener on "treeRefresh" which perform an externalRefresh if the selfhdl is the same with the id from who opened the tree. In order to notify that a user has connected to the room, the akioma.SocketConnection.emitJoinRoom() method is called.

Example: 

Code Block
languagejs
akioma.SocketConnection.emitJoinRoom({name: selfhdl, user: app.sessionData.userDesc});

this will call an akioma.socket.emit("room", data);

The data object contains the following properties:

  • name: id
  • user: the authenticated user ( can be set to key+user, key+tenant+user, tenant+user)
  • action = can be set to "join" or "leave"
  • cleanUser: the authenticated user

The node.js will listen on the room event and check the action. If it's "join", perform an socket.join room and emit an event "room_{data.name}" with the action and the coresponding user. Swat-webui listen to that event and call a treeRoomNotification saying that someone joined or leaved. The notification will be visible only if 2 different users work on the same treegrid.


Image Added