Skip to content

Commit be0010e

Browse files
committed
updated example with latest js features.
1 parent 8f949e0 commit be0010e

2 files changed

Lines changed: 33 additions & 11 deletions

File tree

‎examples/latency-monitor/monitor.html‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,21 @@
22
<html>
33
<head>
44
<title>PubNub Latency Check Example</title>
5-
<link href=bootstrap.min.css rel=stylesheet>
5+
<meta http-equiv=content-type content=text/html;charset=utf-8>
6+
<link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.0/css/bootstrap-combined.min.css" rel="stylesheet">
67
<meta name=viewport content=width=device-width,initial-scale=1.0>
78
<meta name=description content="PubNub - Latency Monitor">
89
<meta name=author content="Stephen Blum - PubNub CTO">
910

1011
<style>
12+
#controls {
13+
margin-top: 80px;
14+
}
15+
#origin {
16+
position: absolute;
17+
top: 50px;
18+
width: 400px;
19+
}
1120
.span-block {
1221
text-align: center;
1322
background: #eee;
@@ -57,13 +66,11 @@
5766
<div class=container>
5867

5968
<!-- ORIGIN and START -->
60-
<div class=row-fluid>
61-
<div class=span2>
62-
&nbsp;
69+
<div class=row-fluid id=controls>
70+
<div class=span1>
6371
<input
6472
id=origin
6573
type=text
66-
class=span3
6774
value=pubsub.pubnub.com
6875
>
6976
</div>
@@ -101,7 +108,7 @@
101108
class="span-block"
102109
style=width:{size}%;background:#{color}>{ms}</div>
103110
</script>
104-
<div class="progress progress-danger progress-striped active">
111+
<div class="progress progress-striped active">
105112
<div id=latency-bar class=bar style=width:0%></div>
106113
</div>
107114

‎examples/latency-monitor/monitor.js‎

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
var display_latency = p.updater( function() {
3131
calc_median();
3232

33-
latency_average.innerHTML = median+'ms'
33+
median && (latency_average.innerHTML = median+'ms')
3434
latency_max.innerHTML = max+'ms'
3535
latency_last.innerHTML = Math.ceil(
3636
latency_results.length /
@@ -79,18 +79,29 @@
7979
p.css( delay, { opacity : '1' } )
8080
p.css( blink, { width : '0' } )
8181
}
82+
83+
var p2 = PUBNUB.init({
84+
publish_key : 'demo',
85+
subscribe_key : 'demo'
86+
});
87+
var p3 = PUBNUB.init({
88+
publish_key : 'demo',
89+
subscribe_key : 'demo'
90+
});
91+
8292
function check() {
8393
if (check.used) {
8494
check.start = +new Date;
8595
clearTimeout(check.ival);
8696
check.ival = setTimeout( function() {
8797
if (!monitor_button.running) return;
8898
p.css( blink, { width : '100%' } );
89-
p.css( delay, { opacity : '0.1' } )
9099
}, 25 );
91100
}
92101
check.used = 1;
93102
p.publish({ channel : channel, message : 1, callback : check });
103+
p2.publish({ channel : channel, message : 1 });
104+
p3.publish({ channel : channel, message : 1 });
94105
}
95106

96107
p.bind( 'click', monitor_button, function() {
@@ -101,15 +112,19 @@
101112
set_class( monitor_button, 'btn btn-danger' );
102113

103114
p = PUBNUB.init({
115+
windowing : 1000,
116+
timeout : 4000,
104117
origin : PUBNUB.$('origin').value,
105118
publish_key : 'demo',
106119
subscribe_key : 'demo'
107120
});
108121

109122
p.subscribe({
110-
channel : channel,
111-
connect : check,
112-
callback : finish
123+
windowing : 1000,
124+
timeout : 4000,
125+
channel : channel,
126+
connect : check,
127+
callback : finish
113128
});
114129

115130
monitor_button.innerHTML = 'Stop Monitor';

0 commit comments

Comments
 (0)