summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2013-06-19 15:17:38 +0200
committerLoïc Hoguin <[email protected]>2013-06-19 15:18:35 +0200
commit48504dac66acd0f9a2516a9d0a7e1a1343ec4943 (patch)
tree82ce72babf925185d78dc4fd266bab052369b85a /examples
parent029c98c2f210be46f4e812dd627f944ca77990eb (diff)
parente8535ec4b8316effd3da3ce9622ae931e251531a (diff)
downloadbullet-48504dac66acd0f9a2516a9d0a7e1a1343ec4943.tar.gz
bullet-48504dac66acd0f9a2516a9d0a7e1a1343ec4943.tar.bz2
bullet-48504dac66acd0f9a2516a9d0a7e1a1343ec4943.zip
Merge branch 'example-enhance' of git://github.com/jdavisp3/bullet
Diffstat (limited to 'examples')
-rw-r--r--examples/clock/src/stream_handler.erl4
-rw-r--r--examples/clock/src/toppage_handler.erl54
2 files changed, 37 insertions, 21 deletions
diff --git a/examples/clock/src/stream_handler.erl b/examples/clock/src/stream_handler.erl
index 2f08342..72efa6f 100644
--- a/examples/clock/src/stream_handler.erl
+++ b/examples/clock/src/stream_handler.erl
@@ -15,8 +15,8 @@ init(_Transport, Req, _Opts, _Active) ->
TRef = erlang:send_after(?PERIOD, self(), refresh),
{ok, Req, TRef}.
-stream(<<"ping">>, Req, State) ->
- io:format("ping received~n"),
+stream(<<"ping: ", Name/binary>>, Req, State) ->
+ io:format("ping ~p received~n", [Name]),
{reply, <<"pong">>, Req, State};
stream(Data, Req, State) ->
io:format("stream received ~s~n", [Data]),
diff --git a/examples/clock/src/toppage_handler.erl b/examples/clock/src/toppage_handler.erl
index b9c6504..552cb0e 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');
+ 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', {});