Back

Topic

[KB1277]Close a WebVue session from PcVue

Tags: Logoff, Scada Basic, Webvue

16 hours ago
By LM
Options
Print
Applies to:
PcVue 15.2.14 onwards (uses the new LIST syntax of the WEBVUE Scada Basic instruction)
Summary:
This project shows how to remotely close one or all the WebVue sessions currently connected to the PcVue server, directly from a PcVue mimic, using the `WEBVUE` Scada Basic instruction and a set of variables that carry the request from the PcVue engine down to the targeted browser.
Details:
Principle

A WebVue client is a browser tab connected to the PcVue backend server. To force it to log out, the WEBVUE("HYPERLINK", ...) instruction must be executed in the context of that specific browser session, it cannot be triggered directly from an operator working on PcVue.

The sample project solves this by relaying an operator action through three variable scopes, until it reaches the right client:

  1. Shared scope – the operator’s action (button click) is visible to the whole system.
  2. Session context scope – each connected WebVue session evaluates the request and decides whether it is concerned.
  3. Client context scope – the targeted browser executes the actual disconnection.

Two use cases are covered:

  • Closing one specific session, selected from a list of the currently connected clients.
  • Closing all the WebVue sessions at once.
Displaying the list of connected clients

At project startup, the main function of the WebVue.SCB program is executed to initialize some variables and tell which function to launch when the user is selecting a row in the grid (AIgrid1):

Sub Main()
	sWindow = "Mimic 01";
	sBranch = "";
	Identity = "AIgrid1";
	Selector("SELPROG", sWindow, sBranch, Identity, "WebVue.SCB", "", "UpdateSessionToClose");
End Sub

The list itself is retrieved with the new LIST mode (syntax 6) of the WEBVUE instruction, which returns an XML fragment describing every active session:

Sub ListSyntax6()
	Webvue("LIST"); ' Retrieve the list of sessions
	iSessionCount = XMLPATH("COUNT", "webvue/list", "list/session");
	...
	For (i = 1; i <= iSessionCount; i++)
		sPath = FORMAT("list.session[%d].id", i);
		hBuff = XMLPATH("GET", "webvue/list", sPath);
		id = CGET_BUFFER(hBuff, 0, 255);
		...
	Next
End Sub

For each session, the idcreationtimeusername and clienttype are extracted with XMLPATH and displayed in the grid. This program can be run once or on a cyclic basis (StartRefreshList / StopRefreshList) to keep the list up to date.

Selecting a row in the grid stores the corresponding session id in a shared variable:

Sub UpdateSessionToClose()
	@WEBVUE.IdToClose = DVAL(Selector("GETCELL", sWindow, sBranch, Identity, Selector("SELECTLINE", sWindow, sBranch, Identity), 0));
End Sub
Mimic 01
Mimic 01
The WEBVUE branch variables

All the variables used to relay the close request are grouped in a dedicated branch, WEBVUE. Their scope and role are documented directly in their description field:

VariableTypeDescription (scope / usage)
WEBVUE.IdToCloseIntegerScope Shared (set by a Scada Basic) – id of the session selected in the grid
WEBVUE.CloseMainCommandScope Shared (set by an animation) – “close this session” button
WEBVUE.CloseAllMainCommandScope Shared (set by an animation) – “close all sessions” button
WEBVUE.CloseSessionBitScope Session context (updated by expression) – mirrors CloseMain in every session context
WEBVUE.CloseAllSessionsBitScope Session context (updated by expression) – mirrors CloseAllMain in every session context
WEBVUE.CloseClientContextCommandScope Session context (set by a Scada Basic) – tells the targeted session to act
WEBVUE.OpenMimicCommandScope Client context (updated by expression) – tells the targeted browser to act

Two “on variable” expressions bridge the Shared scope to the Session context scope, so that the click on a button is instantly visible to every connected session:

EXPRESSIONONVAR,"CloseWebVueSession",...,"WEBVUE.CloseSession","","@WEBVUE.CloseMain"
EXPRESSIONONVAR,"CloseAllSessions",...,"WEBVUE.CloseAllSessions","","@WEBVUE.CloseAllMain"
EXPRESSIONONVAR,"OpenMimicOnWebVue",...,"WEBVUE.OpenMimic","","@WEBVUE.CloseClientContext"

A last expression bridges the Session context scope to the Client context scope (WEBVUE.OpenMimic from @WEBVUE.CloseClientContext), so that the request finally reaches the individual browser tab.

The WebVue.SCB program – reacting in each context

At logon, every WebVue session dynamically registers three programs to react to the variables above:

Sub CreateDynamicEvent()
	Event("ADDPROG", "@WEBVUE.CloseSession", "ALL>1", "WebVue.SCB", "", "CloseWebVueSession");	
	Event("ADDPROG", "@WEBVUE.CloseAllSessions", "ALL>1", "WebVue.SCB", "", "CloseAllWebVueSession");	
	Event("ADDPROG", "@WEBVUE.OpenMimic", "ALL>1", "WebVue.SCB", "", "OpenMimic");
End Sub
  • Closing one session – when CloseSession becomes 1 in a given session context, that session compares its own id (GetArg("WEB")) with the id selected by the operator (@WEBVUE.IdToClose). Only the matching session switches CloseClientContext to 1:
Sub CloseWebVueSession()
	If (TOLL(GetArg("WEB")) == TOLL(@WEBVUE.IdToClose)) Then
		@WEBVUE.CloseClientContext = 1;	
	End If
End Sub
  • Closing all sessions – every WebVue session unconditionally switches CloseClientContext to 1:
Sub CloseAllWebVueSession()
	If (GetArg("WEB") != 0) Then
		@WEBVUE.CloseClientContext = 1;			
	End If
End Sub
  • Reaching the browser – setting CloseClientContext triggers, through the expression above, WEBVUE.OpenMimic in the client context. This opens a dedicated mimic in that browser tab, so that the following instruction is finally executed by the targeted browser itself:
Sub OpenMimic()
	Window("OPEN", "CloseWebVue", ""); ' Opens a mimic to execute the Hyperlink mode of WEBVUE in the client context
End Sub

Sub CloseSession()
	WEBVUE("HYPERLINK", "WebClient/Authentication/Logout?useraction=true");
End Sub

The CloseSession sub above runs when mimic “CloseWebVue” opens, and performs the actual logout of that browser.

Note: The same WEBVUE("HYPERLINK", ...) instruction can also be used to redirect a client to any URL, or to force it to reload the web client:

  • Redirect: WEBVUE("HYPERLINK", "https://your-web-site")
  • Reload (F5): WEBVUE("HYPERLINK", "WebClient")
  • Logout: WEBVUE("HYPERLINK", "WebClient/Authentication/Logout?useraction=true")
Profile configuration

The CreateDynamicEvent sub must be executed by every WebVue session as soon as it logs on, so that the dynamic events described above are registered in its own context. This is configured on the WebVue user profile (p_WebVue): the “Execute Scada Basic script at logon” property is set to call WebVue.SCB / CreateDynamicEvent.

Usage
  1. Open “Mimic 01”: the grid displays the currently connected WebVue sessions (id, creation time, username, client type).
  2. Select the row corresponding to the session to disconnect: this stores its id in @WEBVUE.IdToClose.
  3. Press the “Close this session” button (sets @WEBVUE.CloseMain) to disconnect only the selected session, or press “Close all sessions” (sets @WEBVUE.CloseAllMain) to disconnect every connected WebVue client.

 

Sample project: See the attached PcVue project WebVueCloseSession.

Created on: 02 Sep 2026