-
Notifications
You must be signed in to change notification settings - Fork 136
/
Copy pathmultiusers.html
117 lines (97 loc) · 4.48 KB
/
multiusers.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<!XLSTYPE html>
<html>
<head>
<title>JSPrintManager Multi-users Scenario</title>
<meta charset="utf-8" />
<link rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" />
</head>
<body>
<div class="row">
<div class="col-md-4">
</div>
<div class="col-md-4">
<div style="text-align:center">
<h1>Multi-users Scenario</h1>
<div class="alert alert-warning">
<small>
If you're viewing this page from a multi-user sessions machine then all the different users running an instance of the JSPrintManager App should be listed. To get the printers for <strong>your current user name</strong> then please select it from the list and click on the below button.
</small>
</div>
<fieldset>
<legend><strong>Users running JSPM App instances</strong></legend>
<select id="usersList" class="form-control"></select>
<br />
<button class="btn btn-info" onclick="doGetPrintersByUser();">Get user printers...</button>
</fieldset>
<br /><br />
<fieldset>
<legend><strong>User Printers</strong></legend>
<select id="printerName" class="form-control"></select>
</fieldset>
</div>
</div>
<div class="col-md-4">
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bluebird/3.3.5/bluebird.min.js"></script>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"></script>
<script src="scripts/JSPrintManager.js"></script>
<script>
var jspmAppInstances = null;
var clientPrinters = null;
$(function () {
// get current JSPM Instances
JSPM.JSPrintManager.getInstances().then(function (data) {
/*
{ "instances" : [{ "user" : "mike", "port" : 26443 }, { "user" : "john", "port" : 61111 }, ...] }
*/
if (data) {
var j = JSON.parse(data);
if (j.instances) {
jspmAppInstances = j.instances;
var options = '';
for (var i = 0; i < jspmAppInstances.length; i++) {
options += '<option value="' + jspmAppInstances[i].port + '">' + jspmAppInstances[i].user + '</option>';
}
$('#usersList').html(options);
}
}
}).catch((m) => console.error(m))
});
function doGetPrintersByUser() {
// get user instance port
var port = parseInt($('#usersList').val());
// connect to that instance!
JSPM.JSPrintManager.start(true, 'localhost', port);
JSPM.JSPrintManager.WS.onStatusChanged = function () {
if (jspmWSStatus()) {
//get client installed printers
JSPM.JSPrintManager.getPrinters().then(function (printersList) {
clientPrinters = printersList;
var options = '';
for (var i = 0; i < clientPrinters.length; i++) {
options += '<option>' + clientPrinters[i] + '</option>';
}
$('#printerName').html(options);
});
}
};
}
//Check JSPM WebSocket status
function jspmWSStatus() {
if (JSPM.JSPrintManager.websocket_status == JSPM.WSStatus.Open)
return true;
else if (JSPM.JSPrintManager.websocket_status == JSPM.WSStatus.Closed) {
console.warn('JSPrintManager (JSPM) is not installed or not running! Download JSPM Client App from https://neodynamic.com/downloads/jspm');
return false;
}
else if (JSPM.JSPrintManager.websocket_status == JSPM.WSStatus.Blocked) {
console.error('JSPM has blocked this website!');
return false;
}
}
</script>
</body>
</html>