Skip to content

Commit 2c72dac

Browse files
committed
[webgui] update JSROOT-related documentation
1 parent 0f09383 commit 2c72dac

File tree

3 files changed

+302
-189
lines changed

3 files changed

+302
-189
lines changed

documentation/HttpServer/HttpServer.md

Lines changed: 53 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ One also can provide extra arguments for THttpServer itself:
4141
- readonly, ro - use server in read-only mode (default)
4242
- readwrite, rw - use server in read-write mode
4343
- global - let scan global directories for canvases and files (default)
44-
- noglobal - disable scan of global directories
44+
- noglobal - disable scan of global directories
4545

4646
Example:
4747

@@ -99,6 +99,33 @@ string to the icon name to let browser show command as extra button. In last cas
9999
One can find example of command interface usage in [tutorials/http/httpcontrol.C](https://github.com/root-project/root/blob/master/tutorials/http/httpcontrol.C) macro.
100100

101101

102+
## Customize user interface
103+
104+
JSROOT is used to implement UI for the THttpServer. Defualt webpage shows list of registered objects on the left side and drawing area on the right side - [see example](https://root.cern/js/latest/httpserver.C/). JSROOT allows to configure different parameters via URL - like monitoring interval or name of displayed items [item=Files/job1.root/hpxpy&opt=colz&monitoring=1000](https://root.cern/js/latest/httpserver.C/?item=Files/job1.root/hpxpy&opt=colz&monitoring=1000).
105+
106+
Some of such parameters can be configured already on the server:
107+
108+
serv->SetItemField("/", "_monitoring", "1000"); // monitoring interval in ms
109+
serv->SetItemField("/", "_drawitem", "Files/job1.root/hpxpy"); // item to draw
110+
serv->SetItemField("/", "_drawopt", "colz");
111+
112+
In such case URL parameters are not required - specified item will be displayed automatically when web page is opened.
113+
One also can configure to display several items at once. For that one also can configure layout of the drtawing area:
114+
115+
serv->SetItemField("/", "_layout", "grid2x2"); // layout for drawing area
116+
serv->SetItemField("/", "_drawitem", "[Files/job1.root/hpxpy,Files/job1.root/hpx]"); // items
117+
serv->SetItemField("/", "_drawopt", "[colz,hist]"); // options
118+
119+
One also can change appearance of hierarchy browser on the left side of the web page:
120+
121+
serv->SetItemField("/", "_browser", "off"); // allowed "fix" (default), "float", "no", "off"
122+
serv->SetItemField("/", "_toptitle", "Custom title"); // title of web page, shown when browser off
123+
124+
If necessary, one also can automatically open ROOT file when web page is opened:
125+
126+
serv->SetItemField("/", "_loadfile", "currentdir/hsimple.root"); // name of ROOT file to load
127+
128+
102129
## Configuring user access
103130

104131
By default, the http server is open for anonymous access. One could restrict the access to the server for authenticated users only. First of all, one should create a password file, using the **htdigest** utility.
@@ -152,6 +179,12 @@ One could specify a debug parameter to be able to adjust the FastCGI configurati
152179

153180
serv->CreateEngine("fastcgi:9000?debug=1");
154181

182+
By default 10 threads are used to process FastCGI requests. This number can be changed with "thrds" url parameter:
183+
184+
serv->CreateEngine("fastcgi:9000?thrds=20");
185+
186+
If "thrds=0" specified, the only thread will be use to received and process all requests.
187+
155188
All user access will be ruled by the main web server. Authorized account names could be used to configure access restriction in THttpServer.
156189

157190

@@ -254,7 +287,7 @@ Then, its representation will look like:
254287
{
255288
"_typename" : "TNamed",
256289
"fUniqueID" : 0,
257-
"fBits" : 50331656,
290+
"fBits" : 0,
258291
"fName" : "obj",
259292
"fTitle" : "title"
260293
}
@@ -419,21 +452,20 @@ such kind of requests, which themselvs require data from POST block.
419452

420453
To use `multi.json` request from the JavaScript, one should create special 'POST' HTTP request and properly parse it. JSROOT provides special method to do this:
421454

422-
var xhr = JSROOT.NewHttpRequest("your_server/multi.json?number=3", "multi", function(res) {
423-
if (!res) return;
424-
for (var n=0;n<res.length;++n) {
425-
console.log('Requested element ', res[n]._typename);
426-
// JSROOT.draw('drawid', res[n], 'hist');
427-
}
428-
});
429-
xhr.send("Files/job1.root/hpx/root.json\nFiles/job1.root/hpxpy/root.json\nFiles/job1.root/hprof/root.json\n");
455+
import { httpRequest, draw } from './jsrootsys/modules/core.mjs';
456+
let res = await httpRequest("your_server/multi.json?number=3", "multi",
457+
"Files/job1.root/hpx/root.json\nFiles/job1.root/hpxpy/root.json\nFiles/job1.root/hprof/root.json\n");
458+
for (let n=0; n < res.length; ++n) {
459+
console.log('Requested element ', res[n]._typename);
460+
// draw('drawid', res[n], 'hist');
461+
}
430462

431-
Here argument "multi" identifies, that server response should be parsed with `JSROOT.parse_multi()` function, which correctly interprets JSON code, produced by `multi.json` request. When sending such request to the server, one should provide list of objects names and not forget "?number=N" parameter in the request URL string.
463+
Here argument "multi" identifies, that server response should be parsed with `parseMulti()` function, which correctly interprets JSON code, produced by `multi.json` request. When sending such request to the server, one should provide list of objects names and not forget "?number=N" parameter in the request URL string.
432464

433465

434466
## Websockets supports
435467

436-
Websockets support available starting from ROOT v6.12.
468+
Websockets support available starting from ROOT v6.12.
437469
Minimal example provided in `$ROOTSYS/tutorials/http/ws.C` macro.
438470

439471
To work with websockets, subclass of THttpWSHandler should be created and registered to THttpServer:
@@ -444,18 +476,18 @@ To work with websockets, subclass of THttpWSHandler should be created and regist
444476
public:
445477
TUserHandler(const char *name, const char *title) : THttpWSHandler(name, title) {}
446478

447-
// provide custom HTML page when open correpondent address
479+
// provide custom HTML page when open correspondent address
448480
TString GetDefaultPageContent() { return ""; }
449481

450482
virtual Bool_t ProcessWS(THttpCallArg *arg);
451483
};
452-
484+
453485
Central method is `TUserHandler::ProcessWS(THttpCallArg *arg)`, where four kinds of websockets events should be handled:
454-
486+
455487
* WS_CONNECT - clients attempts to create websockets, return false when refusing connection
456-
* WS_READY - connection is ready to use, **wsid** can be obtained with `arg->GetWSId()` calls
457-
* WS_DATA - new portion of data received by webcosket
458-
* WS_CLOSE - connection closed by the client, **wsid** is no longer valid
488+
* WS_READY - connection is ready to use, **wsid** can be obtained with `arg->GetWSId()` calls
489+
* WS_DATA - new portion of data received by webcosket
490+
* WS_CLOSE - connection closed by the client, **wsid** is no longer valid
459491

460492
These kinds are coded as method name of THttpCallArg class and can be used like:
461493

@@ -483,15 +515,14 @@ These kinds are coded as method name of THttpCallArg class and can be used like:
483515

484516
return kFALSE; // ignore all other kind of requests
485517
}
486-
518+
487519
Instance of **TUserHandler** should be registered to the THttpServer like:
488520

489521
THttpServer *serv = new THttpServer("http:8080");
490522
TUserHandler *handler = new TUserHandler("name1","title");
491523
serv->Register(handler);
492-
524+
493525
After that web socket connection can be established with the address `ws://host_name:8080/name1/root.websocket`
494526
Example client code can be found in `$ROOTSYS/tutorials/http/ws.htm` file. Actually, custom HTML page for
495527
websocket handler can be specified with `TUserHandler::GetDefaultPageContent()` method returning `"file:ws.htm"`.
496-
497-
528+

0 commit comments

Comments
 (0)