summaryrefslogtreecommitdiffstats
path: root/priv
diff options
context:
space:
mode:
authorFlorent Gallaire <[email protected]>2013-11-11 02:16:50 +0100
committerFlorent Gallaire <[email protected]>2014-02-20 00:05:29 +0100
commit148b6fe476e35e9e8db448d6dc73d57a3b23e800 (patch)
treeaf917b87e683ce638dc02bd50ac8bab38d9b4bc7 /priv
parent5bf494144cf4f86e85cd80bfd8c7aa495a4e2209 (diff)
downloadbullet-148b6fe476e35e9e8db448d6dc73d57a3b23e800.tar.gz
bullet-148b6fe476e35e9e8db448d6dc73d57a3b23e800.tar.bz2
bullet-148b6fe476e35e9e8db448d6dc73d57a3b23e800.zip
DRY url.replace().
Automatically disable WebSocket when the URL begins with 'http'. Update the README with the new 'http' url syntax. Update the clock example with the new 'http' url syntax.
Diffstat (limited to 'priv')
-rw-r--r--priv/bullet.js19
1 files changed, 13 insertions, 6 deletions
diff --git a/priv/bullet.js b/priv/bullet.js
index 26a1fc5..162093b 100644
--- a/priv/bullet.js
+++ b/priv/bullet.js
@@ -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){
/**
@@ -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',
@@ -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;
@@ -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'},