Kick out the connected users from the vision client

good afternoon and happy halloween :mage: :jack_o_lantern:,

I have to say, is there any way to terminate the process of a Vision client? i.e. to see the list of those who are connected from the vision and with a button to kick them out?

Yes, go to the gateway webpage/Status/Vision clients, there you will see a list of them an an option to terminate

1 Like

If you want to have some kind of "management" screen, you can set up client message handlers that call system.util.exit, and then use system.util.sendMessage to broadcast a message to those other clients requesting that they close.

4 Likes

that's exactly what I want to do but with a button from the vision/designer.

Should I put as a parameter the user's name? e.g. system.util.exit('Miguel')?

No. You need to go from your local client where this window resides to the other client. You do that using system.util.sendMessage[1] to broadcast out, and a client message handler[2] to receive that broadcast. system.util.exit[3] takes only one argument, a 'force' option to bypass a shutdown intercept script that might exist on the client.

You can use system.util.getSessionInfo[4] to get the list of possible client session IDs to broadcast your message to, to pass to system.util.sendMessage.


  1. system.util.sendMessage - Ignition User Manual 8.1 - Ignition Documentation ↩︎

  2. Client Event Scripts - Ignition User Manual 8.1 - Ignition Documentation ↩︎

  3. system.util.exit - Ignition User Manual 8.1 - Ignition Documentation ↩︎

  4. system.util.getSessionInfo - Ignition User Manual 8.1 - Ignition Documentation ↩︎

2 Likes

ok I think I have it clear, but first I would like to see first the list of connected users in a table, could I do that using the power Table component?

then having that list in the power table for example, I would like to add a button to unlogin a user that is in the Vision, can I do it with the Table or better with power table?

I would use a template repeater, in dataset mode: Using the Template Repeater - Ignition User Manual 8.1 - Ignition Documentation

Make a simple template with parameters corresponding the columns returned by system.util.getSessionInfo. Add a button that broadcasts your "kill yourself" message using the clientId parameter.

sorry for the late reply, in this case I have already made some progress making a script initialized in a Power Table, I get the result of the users connected in the Vision, now I just need to make a Terminate button on the user id obtained.

image

using this script:

	sessionInfoList = system.util.getSessionInfo()
	
	# Crear una lista para almacenar los datos de los usuarios activos con el cuarto parámetro en True
	usuariosActivos = []
	
	# Iterar a través de las sublistas y obtener los datos deseados (primer y segundo campo)
	for sublista in sessionInfoList:
	    # Obtener el primer y cuarto campo (índices 0 y 3)
	    primer_campo = sublista[0]
	    cuarto_campo = sublista[3]
	
	    # Verificar si el cuarto campo es True antes de agregarlo a la lista
	    if cuarto_campo == False:
	        usuariosActivos.append([primer_campo])
	

	table = self

	# Crear un dataset con las columnas adecuadas
	header = ['Connected in vision']
	data = []  # Aquí almacenaremos los datos
	
	for usuario in usuariosActivos:
	    data.append(usuario)
	
	# Establecer el dataset en la tabla
	table.data = system.dataset.toDataSet(header, data)

Adding a clickable button to the power table is a lot harder than setting up a template repeater. You're welcome to search out some techniques on how to do it here on the forums.

1 Like

Maybe have double clicking a row open a popup as confirmation "Disconnect user X?" and there have the button that has the logic to send messages to really disconnect them in lieu of a button in the table.

2 Likes

ok, I see your point... since I have never used a Template repater, I will have to do my own research on it.

Hi Paul, I'm kind of close to finishing this task.

So far I get the list of users connected in Vision by a Templeate Repeater, just as you mentioned above. In addition I added a "terminate" column precisely to terminate the session of that user by ID.

all ok for now..

What I have not been able to do and is already giving me a bit of a headache hehe. is to use the system.util.sendMessage method to end the user's session.

this is the onClick code of the power table

and this is the Gateway event where I will use the system.util.sendMessage to end the session.

Am I using the wrong method? I would really appreciate your opinion on this.

Where are you getting system.util.closeSession from? I don't see that anywhere here system.util - Ignition User Manual 8.1 - Ignition Documentation

Are you seeing anything in your gateway logs? Your client sending a message looks fine. I imagine the issue may be on your gateway message handling side. See if any errors are coming up there when you try to run it. Add some logging if you want to check the values at different steps.

EDIT: Look at what message handler you are sending to - terminateUser but you named the message handler terminateSession - these should match.

1 Like

Uploading: image.png…

when I click on the Terminate button it prints the ID message correctly

image

is system.util.exit, not closeSession what i using

You are calling system.util.exit from your gateway scope but it only works in the vision scope - system.util.exit - Ignition User Manual 8.1 - Ignition Documentation

It is not doing anything in your gateway or throwing an error because the function is not available. It also does not take an argument of clientId, just a boolean about whether or not to force exit (the vision client it was called on).

If you want to go the Client -> Gateway message route, I think from the gateway, it should be sending another message to the appropriate client (you have the id so you can do it with that and the clientSessionId argument). You'll need a client message handler to handle this message, and there is where you would call system.util.exit().

Perhaps there's a different command in the Ignition library you can use from the gateway to kill a client remotely, but I don't see one at least under system.util. Maybe someone else knows.

2 Likes

Client message is the way I've done this in the past. When the user clicks exit send a message to the proper hostname and then on the client side execute the system.util.exit().

Also OP... consider adding a secret UUID or something in the payload when you send the message and check on the client side that the UUID is correct. Just a simple test to make sure that the message came from the gateway and not something else rogue.

Edit: I'll see if I can dig this up from the customer I did it for.

2 Likes

mm ok, putting a little bit in context of what I have understood:

  1. Vision scope: system.util.exit works only within the scope of the Vision client, not within the scope of the server (gateway). This means that you should directly close a Vision client from a script running on the server.

  2. Argument of system.util.exit: This method only takes a boolean argument indicating whether to force close the Vision client. It does not take a client ID as an argument.

  3. Client-Gateway-Client Communication:

    Client to Gateway: should use system.util.sendMessage to send a message from the client to the gateway.
    Gateway to Client: The gateway should forward this message to the specific client you want to close, using the client session ID you obtained previously.
    Client to Client: On the client that receives this message from the gateway, you need to have a message handler configured that calls system.util.exit to close that client.

in conclusion:

# This code is executed when the user clicks on a row to end the session.
id = self.data.getValueAt(row, 'Id')
system.util.sendMessage(project='BALEN', messageHandler='sendShutdownCommand', payload={'sessionId': id})`
# This is an example of how the message handler in the gateway could look like
def sendShutdownCommand(payload):
    sessionId = payload['sessionId']
    system.util.sendMessage(project='BALEN', messageHandler='shutdownClient', payload={}, clientSessionId=sessionId)
# This is an example of what the message handler could look like in the client que debe cerrar sesión
def shutdownClient(payload):
    system.util.exit(force=True)
2 Likes

That looks pretty close to what I've done in the past.

The only other thing that I mentioned above, is to add a secret or something to the payload that comes from the gateway and check it on the client to make sure that the message came from the gateway directly.

2 Likes

Looks about right to me! The documentation tells you what scopes any given function are available, definitely something to get used to looking at -
image

2 Likes