[Pkg-javascript-commits] [sockjs-client] 11/434: Sock goes back to SockJS, there is a better way after all.

Tonnerre Lombard tonnerre-guest at moszumanska.debian.org
Wed Jan 8 00:46:57 UTC 2014


This is an automated email from the git hooks/post-receive script.

tonnerre-guest pushed a commit to branch master
in repository sockjs-client.

commit 1715ae679000d148d967d5a6a8f2fb9085e0b7e9
Author: Marek Majkowski <majek04 at gmail.com>
Date:   Sat Jul 23 21:59:19 2011 +0100

    Sock goes back to SockJS, there is a better way after all.
---
 lib/main.js   |  6 ++--
 lib/sockjs.js | 93 +++++++++++++++++++++--------------------------------------
 2 files changed, 37 insertions(+), 62 deletions(-)

diff --git a/lib/main.js b/lib/main.js
index e31efb9..1b80b9a 100644
--- a/lib/main.js
+++ b/lib/main.js
@@ -1,8 +1,10 @@
-(function(){
+// Public object
+SockJS = (function(){
 <!-- include lib/reventtarget.js -->
 <!-- include lib/simpleevent.js -->
 <!-- include lib/utils.js -->
 <!-- include lib/sockjs.js -->
 <!-- include lib/trans-ws.js -->
 <!-- include lib/trans-jsonp.js -->
- })();
+                  return SockJS;
+          })();
diff --git a/lib/sockjs.js b/lib/sockjs.js
index 6389aaf..0d78bc2 100644
--- a/lib/sockjs.js
+++ b/lib/sockjs.js
@@ -1,5 +1,5 @@
 // Public object.
-var Sock = SockJS = function(url, protocols, options) {
+var SockJS = function(url, protocols, options) {
     this._options = {devel: true, debug: true};
     if (typeof options !== 'undefined') {
         utils.objectExtend(this._options, options);
@@ -15,91 +15,64 @@ var Sock = SockJS = function(url, protocols, options) {
     default: this._protocols = protocols; break;
     }
     this.protocol = undefined;
-    this.readyState = Sock.CONNECTING;
+    this.readyState = SockJS.CONNECTING;
     this._try_next_protocol();
 };
 // Inheritance
-Sock.prototype = new REventTarget();
+SockJS.prototype = new REventTarget();
 
-Sock.version = "0.0.1";
+SockJS.version = "0.0.1";
 
-Sock.CONNECTING = 0;
-Sock.OPEN = 1;
-Sock.CLOSING = 2;
-Sock.CLOSED = 3;
+SockJS.CONNECTING = 0;
+SockJS.OPEN = 1;
+SockJS.CLOSING = 2;
+SockJS.CLOSED = 3;
 
-Sock.prototype._debug = function() {
-    if ('console' in window && console.log) {
+SockJS.prototype._debug = function() {
+    if (this._options.debug && 'console' in window && console.log) {
         console.log.apply(console, arguments);
     }
 };
 
-// Sock.prototype._emit = function(eventType, value, t) {
-//     this._debug('emit', eventType, value, t);
-//     if (this._protocol_is_fine === false &&
-//         (eventType === 'open' || eventType === 'message')) {
-//         this._protocol_is_fine = true;
-//     }
-//     switch(eventType) {
-//     case 'open':
-//         break;
-//     case 'message':
-//         break;
-//     case 'stop':
-//         break;
-//     case 'close':
-//         if ('wasClean' in value &&
-//             value.wasClean === false &&
-//             this._protocol_is_fine === false) {
-//             this._try_next_protocol();
-//         }
-//         break; // ignore
-//     case 'error':
-//         break;
-//     default:
-//     }
-//     //this.dispatchEvent(eventType, value);
-// };
-
-Sock.prototype._didOpen = function() {
-    if (this.readyState !== Sock.CONNECTING)
+SockJS.prototype._didOpen = function() {
+    if (this.readyState !== SockJS.CONNECTING)
             throw 'INVALID_STATE_ERR';
-    this.readyState = Sock.OPEN;
+    this.readyState = SockJS.OPEN;
     this.dispatchEvent(new SimpleEvent("open"));
 };
 
-Sock.prototype._didClose = function(status, reason) {
-    if (this.readyState !== Sock.CONNECTING &&
-        this.readyState !== Sock.OPEN &&
-        this.readyState !== Sock.CLOSING)
+SockJS.prototype._didClose = function(status, reason) {
+    if (this.readyState !== SockJS.CONNECTING &&
+        this.readyState !== SockJS.OPEN &&
+        this.readyState !== SockJS.CLOSING)
             throw 'INVALID_STATE_ERR';
 
     var close_event = new SimpleEvent("close", {status: status, reason: reason});
-    if (this.readyState === Sock.CONNECTING) {
+    if (this.readyState === SockJS.CONNECTING) {
         if (this._try_next_protocol(close_event) === false) {
-            this.readyState = Sock.CLOSED;
+            this.readyState = SockJS.CLOSED;
             var e = new SimpleEvent("close", {status: 2000,
                                               reason: "All transports failed."});
             this.dispatchEvent(e);
         }
     } else {
-        if (this.readyState === Sock.CLOSING &&
+        if (this.readyState === SockJS.CLOSING &&
             status === 1001 && this._close_status) {
             close_event = new SimpleEvent("close", {status: this._close_status,
                                                     reason: this._close_reason});
         }
-        this.readyState = Sock.CLOSED;
+        this.readyState = SockJS.CLOSED;
         this.dispatchEvent(close_event);
     }
 };
 
-Sock.prototype._didMessage = function(data) {
-    if (this.readyState !== Sock.OPEN)
+SockJS.prototype._didMessage = function(data) {
+    if (this.readyState !== SockJS.OPEN)
             return;
     this.dispatchEvent(new SimpleEvent("message", {data: data}));
 };
 
-Sock.prototype._try_next_protocol = function(close_event) {
+SockJS.prototype._try_next_protocol = function(close_event) {
     if (this.protocol)
         this._debug('Closed transport:', this.protocol, close_event);
 
@@ -113,8 +86,8 @@ Sock.prototype._try_next_protocol = function(close_event) {
     }
 
     this._debug('Opening transport:', this.protocol);
-    if (Sock[this.protocol].enabled() === true) {
-        this._transport = new Sock[this.protocol](this, this._trans_url, this._base_url);
+    if (SockJS[this.protocol].enabled() === true) {
+        this._transport = new SockJS[this.protocol](this, this._trans_url, this._base_url);
         return true;
     }
     var e = new SimpleEvent("close", {status: 1000,
@@ -122,22 +95,22 @@ Sock.prototype._try_next_protocol = function(close_event) {
     return this._try_next_protocol(e);
 };
 
-Sock.prototype.close = function(status, reason) {
-    if(this.readyState !== Sock.CONNECTING &&
-       this.readyState !== Sock.OPEN) {
+SockJS.prototype.close = function(status, reason) {
+    if(this.readyState !== SockJS.CONNECTING &&
+       this.readyState !== SockJS.OPEN) {
         return false;
     }
-    this.readyState = Sock.CLOSING;
+    this.readyState = SockJS.CLOSING;
     this._close_status = status || 1000;
     this._close_reason = reason || "Normal closure";
     this._transport.doClose();
     return true;
 };
 
-Sock.prototype.send = function(data) {
-    if (this.readyState === Sock.CONNECTING)
+SockJS.prototype.send = function(data) {
+    if (this.readyState === SockJS.CONNECTING)
             throw 'INVALID_STATE_ERR';
-    if (this.readyState === Sock.OPEN) {
+    if (this.readyState === SockJS.OPEN) {
         this._transport.doSend(data);
     }
     return true;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/sockjs-client.git



More information about the Pkg-javascript-commits mailing list