diff options
author | Dave Peticolas <[email protected]> | 2013-06-09 14:00:38 -0700 |
---|---|---|
committer | Dave Peticolas <[email protected]> | 2013-06-09 14:00:38 -0700 |
commit | e8535ec4b8316effd3da3ce9622ae931e251531a (patch) | |
tree | db8bec71cb643391697920f8ddec996d574d2bc5 /examples/clock | |
parent | d4d541a4ea88b5483af2eae5c8e84649ac91c687 (diff) | |
download | bullet-e8535ec4b8316effd3da3ce9622ae931e251531a.tar.gz bullet-e8535ec4b8316effd3da3ce9622ae931e251531a.tar.bz2 bullet-e8535ec4b8316effd3da3ce9622ae931e251531a.zip |
Individual bullet connections in the example can be enabled/disabled.
This illustrates how to close bullet connections.
Diffstat (limited to 'examples/clock')
-rw-r--r-- | examples/clock/src/toppage_handler.erl | 54 |
1 files changed, 35 insertions, 19 deletions
diff --git a/examples/clock/src/toppage_handler.erl b/examples/clock/src/toppage_handler.erl index 2b878be..844e9ba 100644 --- a/examples/clock/src/toppage_handler.erl +++ b/examples/clock/src/toppage_handler.erl @@ -20,13 +20,17 @@ handle(Req, State) -> </head> <body> - <p>Current time (best source): <span id=\"time_best\">unknown</span> + <p><input type=\"checkbox\" checked=\"yes\" id=\"enable_best\"></input> + Current time (best source): <span id=\"time_best\">unknown</span> <span> </span><span id=\"status_best\">unknown</span></p> - <p>Current time (websocket only): <span id=\"time_websocket\">unknown</span> + <p><input type=\"checkbox\" checked=\"yes\" id=\"enable_websocket\"></input> + Current time (websocket only): <span id=\"time_websocket\">unknown</span> <span> </span><span id=\"status_websocket\">unknown</span></p> - <p>Current time (eventsource only): <span id=\"time_eventsource\">unknown</span> + <p><input type=\"checkbox\" checked=\"yes\" id=\"enable_eventsource\"></input> + Current time (eventsource only): <span id=\"time_eventsource\">unknown</span> <span> </span><span id=\"status_eventsource\">unknown</span></p> - <p>Current time (polling only): <span id=\"time_polling\">unknown</span> + <p><input type=\"checkbox\" checked=\"yes\" id=\"enable_polling\"></input> + Current time (polling only): <span id=\"time_polling\">unknown</span> <span> </span><span id=\"status_polling\">unknown</span></p> <script @@ -37,22 +41,34 @@ handle(Req, State) -> // <![CDATA[ $(document).ready(function(){ var start = function(name, options) { - var bullet = $.bullet('ws://localhost:8080/bullet', options); - bullet.onopen = function(){ - $('#status_' + name).text('online'); - }; - bullet.ondisconnect = function(){ - $('#status_' + name).text('offline'); - }; - bullet.onmessage = function(e){ - if (e.data != 'pong'){ - $('#time_' + name).text(e.data); - } - }; - bullet.onheartbeat = function(){ - console.log('ping: ' + name); - bullet.send('ping: ' + name); + var bullet; + var open = function(){ + bullet = $.bullet('ws://localhost:8080/bullet', options); + bullet.onopen = function(){ + $('#status_' + name).text('online'); + }; + bullet.onclose = bullet.ondisconnect = function(){ + $('#status_' + name).text('offline'); + }; + bullet.onmessage = function(e){ + if (e.data != 'pong'){ + $('#time_' + name).text(e.data); + } + }; + bullet.onheartbeat = function(){ + console.log('ping: ' + name); + bullet.send('ping: ' + name); + }; } + open(); + $('#enable_' + name).on('change', function(){ + if (this.checked){ + open(); + } else{ + bullet.close(); + bullet = null; + } + }); }; start('best', {}); |