/
click.html
384 lines (308 loc) · 12.5 KB
/
click.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
<html>
<head>
<title>Clickstream</title>
<body bgcolor="white" text="black">
<script>
// Usage
window.onload = function() {
navigator.getBattery().then(function(battery) {
battery.addEventListener('levelchange', function() {
});
});
};
////////////// print these
var city = "";
var region = "";
var postal = "";
var lat2 = "";
var long2 = "";
var timezone = "";
var asn = "";
var latitude = "";
var longitude = "";
var ips = "";
var ip2 = "";
var batteryInfo = "";
var screenInfo = screen.width +","+ screen.height + "," +
screen.availWidth +","+ screen.availHeight + "," +
screen.colorDepth + "," + screen.pixelDepth;
var pluginsInfo = "";
var coresInfo = "";
var netInfo = "";
var downInfo = "";
var rttInfo = "";
var downMaxInfo = "";
var effectiveInfo = "";
var saveDataInfo = "";
</script>
<p>
<br>
<strong>Order Items with Apache Pulsar</p></strong>
<br>
<p><button onclick="geoFindMe()">Determine my location</button></p>
<form action="/click.html" method="post" enctype="multipart/form-data" id="form-id">
<!-- The file to upload -->
<p><input id="file-id" type="file" name="our-file" />
<input type="hidden" name="pluginsInfo" id="pluginsInfo" value="NA"/>
<input type="hidden" name="netInfo" id="netInfo" value="NA"/>
<input type="hidden" name="saveDataInfo" id="saveDataInfo" value="NA"/>
<input type="hidden" name="downInfo" id="downInfo" value="NA"/>
<input type="hidden" name="rttInfo" id="rttInfo" value="NA"/>
<input type="hidden" name="downMaxInfo" id="downMaxInfo" value="NA"/>
<input type="hidden" name="effectiveInfo" id="effectiveInfo" value="NA"/>
<input type="hidden" name="screen" id="screenInfo" value="NA"/>
<input type="hidden" name="cores" id="coresInfo" value="NA"/>
<input type="hidden" name="battery" id="batteryInfo" value="NA"/>
<input type="hidden" name="ip" id="ip2" value="NA"/>
<input type="hidden" name="lng" id="lng" value="NA"/>
<input type="hidden" name="lat" id="lat" value="NA"/>
<!--
Also by default, we disable the upload button.
If Ajax uploads are supported we'll enable it.
-->
<input type="button" onclick="" value="Upload" id="upload-button-id" /></p>
<!-- field1 -->
<p><label>Product: </label><input name="product" type="text" id="product-id" size="100" value=""/>
</p>
<!-- field 2 -->
<p><label>Comment: </label><textarea rows="5" cols="80" name="other-field" type="text" id="other-field-id" width="300"></textarea>
</p>
<!-- field 3 -->
<p><label>Product Size: </label><input name="productsize" type="text" id="product-size-id" size="25" value=""/>
</p>
<!-- And finally a submit button -->
<p><input type="submit" value="Send Order" /></p>
</form>
<div id="out"></div>
<div id="demo"></div>
<div id="results"> </div>
<pre id="log"></pre>
<iframe id="iframe" sandbox="allow-same-origin" style="display: none"></iframe>
<script>
function logNetworkInfo() {
// Network type that browser uses
netInfo = navigator.connection.type;
document.getElementById('netInfo').value = netInfo;
// Effective bandwidth estimate
downInfo = navigator.connection.downlink + ' Mb/s';
document.getElementById('downInfo').value = downInfo;
// Effective round-trip time estimate
rttInfo = navigator.connection.rtt + ' ms';
document.getElementById('rttInfo').value = rttInfo;
// Upper bound on the downlink speed of the first network hop
downMaxInfo = navigator.connection.downlinkMax + ' Mb/s';
document.getElementById('downMaxInfo').value = downMaxInfo;
// Effective connection type determined using a combination of recently
// observed rtt and downlink values: ' +
effectiveInfo = navigator.connection.effectiveType;
document.getElementById('effectiveInfo').value = effectiveInfo;
// True if the user has requested a reduced data usage mode from the user
// agent.
saveDataInfo = navigator.connection.saveData;
document.getElementById('saveDataInfo').value = saveDataInfo;
}
logNetworkInfo();
////// Set Plugins
for (var i = 0; i < 12; i++) {
if ( typeof window.navigator.plugins[i] !== 'undefined' ) {
pluginsInfo += window.navigator.plugins[i].name + ', ';
}
}
document.getElementById('pluginsInfo').value = pluginsInfo;
////// Set Cores
if ( window.navigator.hardwareConcurrency > 0 ) {
coresInfo = window.navigator.hardwareConcurrency + " cores";
document.getElementById('coresInfo').value = coresInfo;
}
/// send the information to the server
function loadDoc() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("demo").innerHTML = '';
}
};
document.getElementById('screenInfo').value = screenInfo;
var wsUri = "ws://nvidia-desktop:8080/ws/v2/producer/persistent/public/default/clickstream";
websocket = new WebSocket(wsUri);
const pulsarObject = {plugins: pluginsInfo, screen: screenInfo, cores: coresInfo, downinfo: downInfo, rtt: rttInfo, effectiveInfo: effectiveInfo, saveData: saveDataInfo,
product: document.getElementById('product-id').value, productSize: document.getElementById('product-size-id').value, comment: document.getElementById('other-field-id').value};
const jsonStr = JSON.stringify(pulsarObject);
var payloadStr = btoa(jsonStr);
const propertiesObject = {key: Date.now() }
var data = JSON.stringify({ "payload": payloadStr, "properties": propertiesObject, "context": "cs" });
websocket.onopen = function(evt) {
websocket.send(data);
};
websocket.onerror = function(evt) {console.log('ERR', evt)};
websocket.onmessage = function(evt) {
console.log("Message sent");
}
websocket.onclose = function(evt) {
if (evt.wasClean) {
console.log(evt);
} else {
console.log('[close] Connection died');
}
};
}
////////////
function geoFindMe() {
var output = document.getElementById("out");
if (!navigator.geolocation){
output.innerHTML = "<p>Geolocation is not supported by your browser</p>";
return;
}
function success(position) {
latitude = position.coords.latitude;
longitude = position.coords.longitude;
document.getElementById('lat').value = latitude;
document.getElementById('lng').value = longitude;
output.innerHTML = '<p>Latitude is ' + latitude + ' <br>Longitude is ' + longitude + '</p>';
}
function error() {
output.innerHTML = "Unable to retrieve your location. Please enter your lat/long or street address and city";
}
output.innerHTML = "<p>Locating...</p>";
loadDoc();
}
//get the IP addresses associated with an account
function getIPs(callback)
{
var ip_dups = {};
//compatibility for firefox and chrome
var RTCPeerConnection = window.RTCPeerConnection
|| window.mozRTCPeerConnection
|| window.webkitRTCPeerConnection;
var useWebKit = !!window.webkitRTCPeerConnection;
//bypass naive webrtc blocking using an iframe
if(!RTCPeerConnection){
var win = iframe.contentWindow;
RTCPeerConnection = win.RTCPeerConnection
|| win.mozRTCPeerConnection
|| win.webkitRTCPeerConnection;
useWebKit = !!win.webkitRTCPeerConnection;
}
//minimal requirements for data connection
var mediaConstraints = {
optional: [{RtpDataChannels: true}]
};
var servers = {iceServers: [{urls: "stun:stun.services.mozilla.com"}]};
//construct a new RTCPeerConnection
var pc = new RTCPeerConnection(servers, mediaConstraints);
function handleCandidate(candidate){
//match just the IP address
var ip_regex = /([0-9]{1,3}(\.[0-9]{1,3}){3}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})/
var ip_addr = ip_regex.exec(candidate)[1];
ip2 = ip_addr;
//remove duplicates
if(ip_dups[ip_addr] === undefined)
callback(ip_addr);
ip_dups[ip_addr] = true;
}
//listen for candidate events
pc.onicecandidate = function(ice){
//skip non-candidate events
if(ice.candidate)
handleCandidate(ice.candidate.candidate);
};
//create a bogus data channel
pc.createDataChannel("");
//create an offer sdp
pc.createOffer(function(result){
//trigger the stun server request
pc.setLocalDescription(result, function(){}, function(){});
}, function(){});
//wait for a while to let everything done
setTimeout(function() {
//read candidate info from local description
if ( pc && pc.localDescription && pc.localDescription.sdp ) {
var lines = pc.localDescription.sdp.split('\n');
lines.forEach(function(line) {
if(line.indexOf('a=candidate:') === 0)
handleCandidate(line);
});
}
}, 1000);
}
window.addEventListener("load", function (ev) {
"use strict";
var log = document.getElementById("log");
// https://dvcs.w3.org/hg/dap/raw-file/tip/sensor-api/Overview.html
window.addEventListener("devicetemperature", function (ev) {
log.textContent += "devicetemperature " + ev.value + "\n";
}, false);
window.addEventListener("devicepressure", function (ev) {
log.textContent += "devicepressure " + ev.value + "\n";
}, false);
window.addEventListener("devicelight", function (ev) {
log.textContent += "devicelight " + ev.value + "\n";
// toy tric
log.style.color = "rgb(" + (255 - 2*ev.value) + ",0,0)";
log.style.backgroundColor = "rgb(0,0," + (2*ev.value) + ")";
}, false);
window.addEventListener("deviceproximity", function (ev) {
log.textContent += "deviceproximity " + ev.value + "\n";
// toy tric
if (ev.value < 3) navigator.vibrate([300, 100, 100]);
}, false);
window.addEventListener("devicenoise", function (ev) {
log.textContent += "devicenoise " + ev.value + "\n";
}, false);
window.addEventListener("devicehumidity", function (ev) {
log.textContent += "devicehumidity " + ev.value + "\n";
}, false);
//https://wiki.mozilla.org/Magnetic_Field_Events
window.addEventListener("devicemagneticfield", function (ev) {
log.textContent += "devicemagneticfield " + [ev.x, ev.y, ev.x]+ "\n";
}, false);
// https://dvcs.w3.org/hg/dap/raw-file/default/pressure/Overview.html
window.addEventListener("atmpressure", function (ev) {
log.textContent += "atmpressure " + ev.value + "\n";
}, false);
// https://dvcs.w3.org/hg/dap/raw-file/tip/humidity/Overview.html
window.addEventListener("humidity", function (ev) {
log.textContent += "humidity " + ev.value + "\n";
}, false);
// https://dvcs.w3.org/hg/dap/raw-file/tip/temperature/Overview.html
window.addEventListener("temperature", function (ev) {
log.textContent += "temperature " + [ev.f, ev.c, ev.k, ev.value] + "\n";
}, false);
// https://dvcs.w3.org/hg/dap/raw-file/tip/battery/Overview.html
try {
if (typeof navigator.getBattery === "function") {
navigator.getBattery().then(function (battery) {
log.textContent += "battery.level " + battery.level + "\n";
log.textContent += "battery.charging " + battery.charging + "\n";
batteryInfo = "battery.level=" + battery.level + "," +
"battery.charging=" + battery.charging;
log.textContent += "battery.chargeTime " + battery.chargeTime + "\n";
log.textContent += "battery.dischargeTime " + battery.dischargeTime + "\n";
battery.addEventListener("levelcharge", function (ev) {
log.textContent += "change battery.level " + battery.level + "\n";
batteryInfo = "battery.level=" + battery.level + "," +
"battery.charging=" + battery.charging;
}, false);
}).catch(function (err) {
log.textContent += err.toString() + "\n";
});
} else {
log.textContent += "";
}
} catch (ex) {
log.textContent += ex.toString() + "\n";
}
}, false);
geoFindMe();
var form = document.getElementById('form-id');
form.onsubmit = function() {
// FormData receives the whole form
var formData = new FormData(form);
// We send the data where the form wanted
var action = form.getAttribute('action');
console.log(formData);
return false;
}
</script>
</body>
</html>