THRIFT-4437: JavaScript WebSocket - fix duplicate callbacks and enable ThriftWS test suite
Client: js

This closes #1450
diff --git a/lib/js/Gruntfile.js b/lib/js/Gruntfile.js
index bff250f..e678cd5 100644
--- a/lib/js/Gruntfile.js
+++ b/lib/js/Gruntfile.js
@@ -161,11 +161,13 @@
                               'external_daemon:ThriftTestServer', 'external_daemon:ThriftTestServer_TLS',
                               'shell:ThriftGenDeepConstructor', 'qunit:ThriftDeepConstructor',
                               'qunit:ThriftJS', 'qunit:ThriftJS_TLS',
+                              'qunit:ThriftWS',
                               'shell:ThriftGenJQ', 'qunit:ThriftJSJQ', 'qunit:ThriftJSJQ_TLS'
                              ]);
   grunt.registerTask('default', ['jshint', 'shell:InstallThriftJS', 'shell:InstallThriftNodeJSDep', 'shell:ThriftGen',
                                  'external_daemon:ThriftTestServer', 'external_daemon:ThriftTestServer_TLS',
                                  'qunit:ThriftJS', 'qunit:ThriftJS_TLS',
+                                 'qunit:ThriftWS',
                                  'shell:ThriftGenJQ', 'qunit:ThriftJSJQ', 'qunit:ThriftJSJQ_TLS',
                                  'concat', 'uglify', 'jsdoc'
                                 ]);
diff --git a/lib/js/src/thrift.js b/lib/js/src/thrift.js
index 1a11871..5d420a2 100644
--- a/lib/js/src/thrift.js
+++ b/lib/js/src/thrift.js
@@ -572,18 +572,11 @@
           var clientCallback = callback;
           return function(msg) {
             self.setRecvBuffer(msg);
-            clientCallback();
+            if (clientCallback) {
+                clientCallback();
+            }
           };
         }()));
-        if(callback) {
-          this.callbacks.push((function() {
-            var clientCallback = callback;
-            return function(msg) {
-              self.setRecvBuffer(msg);
-              clientCallback();
-            };
-          }()));
-        }
       } else {
         //Queue the send to go out __onOpen
         this.send_pending.push({