summaryrefslogtreecommitdiffstats
path: root/priv
diff options
context:
space:
mode:
authorDave Peticolas <[email protected]>2013-06-22 11:25:45 -0700
committerDave Peticolas <[email protected]>2013-06-22 11:25:45 -0700
commit95366273731c5b05927053bc781624ebb06b1cb7 (patch)
treec31a2caed8566de71ca0dd66dbbc790696d491b4 /priv
parentc03955c595374c50b9e1354347b7dd362b08e10e (diff)
downloadbullet-95366273731c5b05927053bc781624ebb06b1cb7.tar.gz
bullet-95366273731c5b05927053bc781624ebb06b1cb7.tar.bz2
bullet-95366273731c5b05927053bc781624ebb06b1cb7.zip
Use xhr for sending with eventsource connections.
Diffstat (limited to 'priv')
-rw-r--r--priv/bullet.js61
1 files changed, 32 insertions, 29 deletions
diff --git a/priv/bullet.js b/priv/bullet.js
index 0fbc2ac..e43fe75 100644
--- a/priv/bullet.js
+++ b/priv/bullet.js
@@ -38,6 +38,36 @@
var CLOSING = 2;
var CLOSED = 3;
+ var xhrSend = function(data){
+ /**
+ Send a message using ajax. Used for both the
+ eventsource and xhrPolling transports.
+ */
+ if (this.readyState != CONNECTING && this.readyState != OPEN){
+ return false;
+ }
+
+ var sendUrl = url.replace('ws:', 'http:').replace('wss:', 'https:');
+
+ $.ajax({
+ async: false,
+ cache: false,
+ type: 'POST',
+ url: sendUrl,
+ data: data,
+ dataType: 'text',
+ contentType: 'application/x-www-form-urlencoded; charset=utf-8',
+ headers: {'X-Socket-Transport': 'xhrPolling'},
+ success: function(data){
+ if (data.length !== 0){
+ fake.onmessage({'data': data});
+ }
+ }
+ });
+
+ return true;
+ };
+
var transports = {
/**
The websocket transport is disabled for Firefox 6.0 because it
@@ -96,9 +126,7 @@
var fake = {
readyState: CONNECTING,
- send: function(data){
- return false; // fallback to another method instead?
- },
+ send: xhrSend,
close: function(){
fake.readyState = CLOSED;
source.close();
@@ -120,32 +148,7 @@
var fake = {
readyState: CONNECTING,
- send: function(data){
- if (this.readyState != CONNECTING && this.readyState != OPEN){
- return false;
- }
-
- var fakeurl = url.replace('ws:', 'http:').replace('wss:', 'https:');
-
- $.ajax({
- async: false,
- cache: false,
- type: 'POST',
- url: fakeurl,
- data: data,
- dataType: 'text',
- contentType:
- 'application/x-www-form-urlencoded; charset=utf-8',
- headers: {'X-Socket-Transport': 'xhrPolling'},
- success: function(data){
- if (data.length !== 0){
- fake.onmessage({'data': data});
- }
- }
- });
-
- return true;
- },
+ send: xhrSend,
close: function(){
this.readyState = CLOSED;
if (xhr){