Skip to content
This repository has been archived by the owner on Dec 11, 2018. It is now read-only.

Commit

Permalink
Merge branch 'http_url_syntax' of git://github.com/fgallaire/bullet
Browse files Browse the repository at this point in the history
  • Loading branch information
essen committed Jun 3, 2014
2 parents 2d64d09 + 148b6fe commit 999f02f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,12 @@ $(document).ready(function(){
});
```

Always use the WebSocket (ws:) form for your bullet URLs and Bullet
Use the WebSocket (ws:) form for your bullet URLs and Bullet
will change the URL as needed for non-WebSocket transports.

Use the standard (http:) form for your bullet URLs and Bullet
will only try non-WebSocket transports.

The `$.bullet` function takes an optional second 'options' object.
The following properties are supported:

Expand Down
17 changes: 11 additions & 6 deletions examples/clock/src/toppage_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ handle(Req, State) ->
Current time (best source): <span id=\"time_best\">unknown</span>
<span></span><span id=\"status_best\">unknown</span>
<button id=\"send_best\">Send Time</button></p>
<p><input type=\"checkbox\" checked=\"yes\" id=\"enable_best_nows\"></input>
Current time (best source non-websocket): <span id=\"time_best_nows\">unknown</span>
<span></span><span id=\"status_best_nows\">unknown</span>
<button id=\"send_best_nows\">Send Time</button></p>
<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>
Expand All @@ -44,10 +48,10 @@ handle(Req, State) ->
<script type=\"text/javascript\">
// <![CDATA[
$(document).ready(function(){
var start = function(name, options) {
var start = function(name, url, options) {
var bullet;
var open = function(){
bullet = $.bullet('ws://localhost:8080/bullet', options);
bullet = $.bullet(url, options);
bullet.onopen = function(){
$('#status_' + name).text('online');
};
Expand Down Expand Up @@ -81,12 +85,13 @@ $(document).ready(function(){
});
};
start('best', {});
start('websocket', {'disableEventSource': true,
start('best', 'ws://localhost:8080/bullet', {});
start('best_nows', 'http://localhost:8080/bullet', {});
start('websocket', 'ws://localhost:8080/bullet', {'disableEventSource': true,
'disableXHRPolling': true});
start('eventsource', {'disableWebSocket': true,
start('eventsource', 'ws://localhost:8080/bullet', {'disableWebSocket': true,
'disableXHRPolling': true});
start('polling', {'disableWebSocket': true,
start('polling', 'ws://localhost:8080/bullet', {'disableWebSocket': true,
'disableEventSource': true});
});
// ]]>
Expand Down
19 changes: 13 additions & 6 deletions priv/bullet.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@
var OPEN = 1;
var CLOSING = 2;
var CLOSED = 3;
var httpURL = url.replace('ws:', 'http:').replace('wss:', 'https:');

if (url == httpURL) {
if (options == undefined) {
var options = {'disableWebSocket': true};
}
else {
options.disableWebSocket = true;
}
}

var xhrSend = function(data){
/**
Expand All @@ -47,13 +57,12 @@
return false;
}

var sendUrl = url.replace('ws:', 'http:').replace('wss:', 'https:');
var self = this;
$.ajax({
async: false,
cache: false,
type: 'POST',
url: sendUrl,
url: httpURL,
data: data,
dataType: 'text',
contentType: 'application/x-www-form-urlencoded; charset=utf-8',
Expand Down Expand Up @@ -106,8 +115,7 @@
return false;
}

var eventsourceURL = url.replace('ws:', 'http:').replace('wss:', 'https:');
var source = new window.EventSource(eventsourceURL);
var source = new window.EventSource(httpURL);

source.onopen = function () {
fake.readyState = OPEN;
Expand Down Expand Up @@ -165,12 +173,11 @@
};

function poll(){
var fakeurl = url.replace('ws:', 'http:').replace('wss:', 'https:');

xhr = $.ajax({
type: 'GET',
cache: false,
url: fakeurl,
url: httpURL,
dataType: 'text',
data: {},
headers: {'X-Socket-Transport': 'xhrPolling'},
Expand Down

0 comments on commit 999f02f

Please sign in to comment.