batman-rails-flo 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +29 -0
  3. data/Rakefile +2 -0
  4. data/lib/batman-rails-flo.rb +5 -0
  5. data/lib/batman_rails_flo/railtie.rb +9 -0
  6. data/lib/batman_rails_flo/tasks.rake +14 -0
  7. data/lib/batman_rails_flo/version.rb +3 -0
  8. data/vendor/assets/javascripts/batman_rails_flo/flo_server.js +67 -0
  9. data/vendor/assets/javascripts/batman_rails_flo/live_reload.js.coffee +129 -0
  10. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/CNAME +1 -0
  11. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/CONTRIBUTING.md +9 -0
  12. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/LICENSE +22 -0
  13. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/README +50 -0
  14. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/bin/cake +7 -0
  15. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/bin/coffee +7 -0
  16. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/browser.js +134 -0
  17. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/cake.js +112 -0
  18. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/coffee-script.js +335 -0
  19. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/command.js +569 -0
  20. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/grammar.js +631 -0
  21. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/helpers.js +252 -0
  22. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/index.js +11 -0
  23. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/lexer.js +926 -0
  24. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/nodes.js +3158 -0
  25. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/optparse.js +139 -0
  26. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/parser.js +724 -0
  27. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/register.js +66 -0
  28. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/repl.js +163 -0
  29. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/rewriter.js +475 -0
  30. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/scope.js +146 -0
  31. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/lib/coffee-script/sourcemap.js +161 -0
  32. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/LICENSE +21 -0
  33. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/examples/pow.js +6 -0
  34. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/index.js +82 -0
  35. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/package.json +34 -0
  36. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/readme.markdown +63 -0
  37. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/chmod.js +38 -0
  38. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/clobber.js +37 -0
  39. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/mkdirp.js +28 -0
  40. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/perm.js +32 -0
  41. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/perm_sync.js +39 -0
  42. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/race.js +41 -0
  43. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/rel.js +32 -0
  44. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/return.js +25 -0
  45. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/return_sync.js +24 -0
  46. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/root.js +18 -0
  47. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/sync.js +32 -0
  48. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/umask.js +28 -0
  49. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/node_modules/mkdirp/test/umask_sync.js +32 -0
  50. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/package.json +50 -0
  51. data/vendor/assets/javascripts/batman_rails_flo/node_modules/coffee-script/register.js +1 -0
  52. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/LICENSE +30 -0
  53. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/PATENTS +23 -0
  54. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/README.md +124 -0
  55. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/bin/flo +26 -0
  56. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/configure/configure.html +57 -0
  57. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/configure/configure.js +205 -0
  58. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/configure/style.css +334 -0
  59. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/connection.js +235 -0
  60. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/devtools.html +12 -0
  61. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/index.js +323 -0
  62. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/logger.js +42 -0
  63. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/logo.png +0 -0
  64. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/manifest.json +13 -0
  65. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/client/session.js +305 -0
  66. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/index.js +10 -0
  67. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/lib/flo.js +226 -0
  68. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/lib/server.js +94 -0
  69. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/README.md +66 -0
  70. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/index.js +437 -0
  71. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/LICENSE +23 -0
  72. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/README.md +218 -0
  73. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/minimatch.js +1055 -0
  74. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/lru-cache/CONTRIBUTORS +14 -0
  75. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/lru-cache/LICENSE +23 -0
  76. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/lru-cache/README.md +97 -0
  77. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/lru-cache/lib/lru-cache.js +252 -0
  78. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/lru-cache/package.json +33 -0
  79. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/lru-cache/test/basic.js +369 -0
  80. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/lru-cache/test/foreach.js +52 -0
  81. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/lru-cache/test/memory-leak.js +50 -0
  82. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/sigmund/LICENSE +27 -0
  83. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/sigmund/README.md +53 -0
  84. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/sigmund/bench.js +283 -0
  85. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/sigmund/package.json +42 -0
  86. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/sigmund/sigmund.js +39 -0
  87. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/node_modules/sigmund/test/basic.js +24 -0
  88. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/package.json +40 -0
  89. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/test/basic.js +399 -0
  90. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/test/brace-expand.js +33 -0
  91. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/test/caching.js +14 -0
  92. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/test/defaults.js +274 -0
  93. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/minimatch/test/extglob-ending-with-state-char.js +8 -0
  94. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/lib/walker.js +111 -0
  95. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/license +13 -0
  96. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/node_modules/makeerror/lib/makeerror.js +87 -0
  97. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/node_modules/makeerror/node_modules/tmpl/lib/tmpl.js +17 -0
  98. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/node_modules/makeerror/node_modules/tmpl/package.json +31 -0
  99. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/node_modules/makeerror/node_modules/tmpl/readme.md +10 -0
  100. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/node_modules/makeerror/package.json +34 -0
  101. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/node_modules/makeerror/readme.md +77 -0
  102. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/package.json +36 -0
  103. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/walker/readme.md +52 -0
  104. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/watch/LICENSE +55 -0
  105. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/watch/main.js +128 -0
  106. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/watch/package.json +34 -0
  107. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/watch/readme.mkd +72 -0
  108. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/watch/test/d/d/t +0 -0
  109. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/watch/test/d/t +0 -0
  110. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/watch/test/test_monitor.js +31 -0
  111. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/watch/test/test_monitorRootDirectory.js +28 -0
  112. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/node_modules/watch/test/test_watchTree.js +20 -0
  113. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/package.json +45 -0
  114. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/sane/test/test.js +243 -0
  115. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/CHANGELOG.md +81 -0
  116. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/LICENSE +177 -0
  117. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/Makefile +11 -0
  118. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/README.md +245 -0
  119. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/binding.gyp +14 -0
  120. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/Makefile +355 -0
  121. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/Release/linker.lock +0 -0
  122. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/Release/obj.target/validation/src/validation.o +0 -0
  123. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/Release/obj.target/xor/src/xor.o +0 -0
  124. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/Release/validation.node +0 -0
  125. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/Release/xor.node +0 -0
  126. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/binding.Makefile +6 -0
  127. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/config.gypi +115 -0
  128. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/gyp-mac-tool +512 -0
  129. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/validation.target.mk +154 -0
  130. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/build/xor.target.mk +154 -0
  131. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/index.js +1 -0
  132. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/install.js +31 -0
  133. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/Constants.js +23 -0
  134. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/Deprecation.js +38 -0
  135. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/Validation.fallback.js +12 -0
  136. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/Validation.js +18 -0
  137. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/WebSocketClient.js +359 -0
  138. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/WebSocketConnection.js +717 -0
  139. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/WebSocketFrame.js +282 -0
  140. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/WebSocketRequest.js +478 -0
  141. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/WebSocketRouter.js +154 -0
  142. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/WebSocketRouterRequest.js +59 -0
  143. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/WebSocketServer.js +216 -0
  144. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/utils.js +7 -0
  145. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/websocket.js +11 -0
  146. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/xor.fallback.js +13 -0
  147. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/lib/xor.js +18 -0
  148. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/package.json +43 -0
  149. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/src/validation.cc +144 -0
  150. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/src/xor.cpp +86 -0
  151. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/vendor/FastBufferList.js +192 -0
  152. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/vendor/node-ctype/LICENSE +18 -0
  153. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/node_modules/websocket/vendor/node-ctype/ctio-faster.js +1126 -0
  154. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/package.json +25 -0
  155. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/test/client/browser_websocket.js +63 -0
  156. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/test/client/connection_test.js +57 -0
  157. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/test/client/logger_mock.js +15 -0
  158. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/test/client/session_test.js +194 -0
  159. data/vendor/assets/javascripts/batman_rails_flo/node_modules/fb-flo/test/server/flo_test.js +211 -0
  160. data/vendor/assets/javascripts/batman_rails_flo/package.json +15 -0
  161. data/vendor/assets/javascripts/batman_rails_flo/reload_event_handler.js.coffee +56 -0
  162. metadata +232 -0
@@ -0,0 +1,154 @@
1
+ /************************************************************************
2
+ * Copyright 2010-2011 Worlize Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ ***********************************************************************/
16
+
17
+ var extend = require('./utils').extend;
18
+ var util = require('util');
19
+ var EventEmitter = require('events').EventEmitter;
20
+ var WebSocketRouterRequest = require('./WebSocketRouterRequest');
21
+
22
+ function WebSocketRouter(config) {
23
+ this.config = {
24
+ // The WebSocketServer instance to attach to.
25
+ server: null
26
+ };
27
+ if (config) {
28
+ extend(this.config, config);
29
+ }
30
+ if (this.config.server) {
31
+ this.attachServer(this.config.server);
32
+ }
33
+ this.handlers = [];
34
+
35
+ this._requestHandler = this.handleRequest.bind(this);
36
+ }
37
+
38
+ util.inherits(WebSocketRouter, EventEmitter);
39
+
40
+ WebSocketRouter.prototype.attachServer = function(server) {
41
+ if (server) {
42
+ this.server = server;
43
+ this.server.on('request', this._requestHandler);
44
+ }
45
+ else {
46
+ throw new Error("You must specify a WebSocketServer instance to attach to.");
47
+ }
48
+ };
49
+
50
+ WebSocketRouter.prototype.detachServer = function() {
51
+ if (this.server) {
52
+ this.server.removeListener('request', this._requestHandler);
53
+ this.server = null;
54
+ }
55
+ else {
56
+ throw new Error("Cannot detach from server: not attached.")
57
+ }
58
+ };
59
+
60
+ WebSocketRouter.prototype.mount = function(path, protocol, callback) {
61
+ if (!path) {
62
+ throw new Error("You must specify a path for this handler.");
63
+ }
64
+ if (!protocol) {
65
+ protocol = "____no_protocol____";
66
+ }
67
+ if (!callback) {
68
+ throw new Error("You must specify a callback for this handler.");
69
+ }
70
+
71
+ path = this.pathToRegExp(path);
72
+ if (!(path instanceof RegExp)) {
73
+ throw new Error("Path must be specified as either a string or a RegExp.");
74
+ }
75
+ var pathString = path.toString();
76
+
77
+ // normalize protocol to lower-case
78
+ protocol = protocol.toLocaleLowerCase();
79
+
80
+ if (this.findHandlerIndex(pathString, protocol) !== -1) {
81
+ throw new Error("You may only mount one handler per path/protocol combination.");
82
+ }
83
+
84
+ this.handlers.push({
85
+ 'path': path,
86
+ 'pathString': pathString,
87
+ 'protocol': protocol,
88
+ 'callback': callback
89
+ });
90
+ };
91
+ WebSocketRouter.prototype.unmount = function(path, protocol) {
92
+ var index = this.findHandlerIndex(this.pathToRegExp(path).toString(), protocol);
93
+ if (index !== -1) {
94
+ this.handlers.splice(index, 1);
95
+ }
96
+ else {
97
+ throw new Error("Unable to find a route matching the specified path and protocol.");
98
+ }
99
+ };
100
+
101
+ WebSocketRouter.prototype.findHandlerIndex = function(pathString, protocol) {
102
+ protocol = protocol.toLocaleLowerCase();
103
+ for (var i=0, len=this.handlers.length; i < len; i++) {
104
+ var handler = this.handlers[i];
105
+ if (handler.pathString === pathString && handler.protocol === protocol) {
106
+ return i;
107
+ }
108
+ }
109
+ return -1;
110
+ };
111
+
112
+ WebSocketRouter.prototype.pathToRegExp = function(path) {
113
+ if (typeof(path) === 'string') {
114
+ if (path === '*') {
115
+ path = /^.*$/;
116
+ }
117
+ else {
118
+ path = path.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
119
+ path = new RegExp('^' + path + '$');
120
+ }
121
+ }
122
+ return path;
123
+ };
124
+
125
+ WebSocketRouter.prototype.handleRequest = function(request) {
126
+ var requestedProtocols = request.requestedProtocols;
127
+ if (requestedProtocols.length === 0) {
128
+ requestedProtocols = ['____no_protocol____'];
129
+ }
130
+
131
+ // Find a handler with the first requested protocol first
132
+ for (var i=0; i < requestedProtocols.length; i++) {
133
+ var requestedProtocol = requestedProtocols[i].toLocaleLowerCase();
134
+
135
+ // find the first handler that can process this request
136
+ for (var j=0, len=this.handlers.length; j < len; j++) {
137
+ var handler = this.handlers[j];
138
+ if (handler.path.test(request.resourceURL.pathname)) {
139
+ if (requestedProtocol === handler.protocol ||
140
+ handler.protocol === '*')
141
+ {
142
+ var routerRequest = new WebSocketRouterRequest(request, requestedProtocol);
143
+ handler.callback(routerRequest);
144
+ return;
145
+ }
146
+ }
147
+ }
148
+ }
149
+
150
+ // If we get here we were unable to find a suitable handler.
151
+ request.reject(404, "No handler is available for the given request.");
152
+ };
153
+
154
+ module.exports = WebSocketRouter;
@@ -0,0 +1,59 @@
1
+ /************************************************************************
2
+ * Copyright 2010-2011 Worlize Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ ***********************************************************************/
16
+
17
+ var deprecation = require('./Deprecation');
18
+ var util = require('util');
19
+ var EventEmitter = require('events').EventEmitter;
20
+
21
+ function WebSocketRouterRequest(webSocketRequest, resolvedProtocol) {
22
+ this.webSocketRequest = webSocketRequest;
23
+ if (resolvedProtocol === '____no_protocol____') {
24
+ this.protocol = null;
25
+ }
26
+ else {
27
+ this.protocol = resolvedProtocol;
28
+ }
29
+ this.origin = webSocketRequest.origin;
30
+ this.resource = webSocketRequest.resource;
31
+ this.resourceURL = webSocketRequest.resourceURL;
32
+ this.httpRequest = webSocketRequest.httpRequest;
33
+ this.remoteAddress = webSocketRequest.remoteAddress;
34
+ this.webSocketVersion = webSocketRequest.webSocketVersion;
35
+ // Deprecated websocketVersion (proper casing...)
36
+ Object.defineProperty(this, "websocketVersion", {
37
+ get: function() {
38
+ deprecation.warn('websocketVersion');
39
+ return this.webSocketVersion;
40
+ }
41
+ });
42
+ this.requestedExtensions = webSocketRequest.requestedExtensions;
43
+ this.cookies = webSocketRequest.cookies;
44
+ }
45
+
46
+ util.inherits(WebSocketRouterRequest, EventEmitter);
47
+
48
+ WebSocketRouterRequest.prototype.accept = function(origin, cookies) {
49
+ var connection = this.webSocketRequest.accept(this.protocol, origin, cookies);
50
+ this.emit('requestAccepted', connection);
51
+ return connection;
52
+ };
53
+
54
+ WebSocketRouterRequest.prototype.reject = function(status, reason, extraHeaders) {
55
+ this.webSocketRequest.reject(status, reason, extraHeaders);
56
+ this.emit('requestRejected', this);
57
+ };
58
+
59
+ module.exports = WebSocketRouterRequest;
@@ -0,0 +1,216 @@
1
+ /************************************************************************
2
+ * Copyright 2010-2011 Worlize Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ ***********************************************************************/
16
+
17
+ var extend = require('./utils').extend;
18
+ var util = require('util');
19
+ var EventEmitter = require('events').EventEmitter;
20
+ var WebSocketRequest = require('./WebSocketRequest');
21
+ var Constants = require('./Constants');
22
+
23
+ var WebSocketServer = function WebSocketServer(config) {
24
+ this._handlers = {
25
+ upgrade: this.handleUpgrade.bind(this),
26
+ requestAccepted: this.handleRequestAccepted.bind(this)
27
+ };
28
+ this.connections = [];
29
+ if (config) {
30
+ this.mount(config);
31
+ }
32
+ };
33
+
34
+ util.inherits(WebSocketServer, EventEmitter);
35
+
36
+ WebSocketServer.prototype.mount = function(config) {
37
+ this.config = {
38
+ // The http server instance to attach to. Required.
39
+ httpServer: null,
40
+
41
+ // 64KiB max frame size.
42
+ maxReceivedFrameSize: 0x10000,
43
+
44
+ // 1MiB max message size, only applicable if
45
+ // assembleFragments is true
46
+ maxReceivedMessageSize: 0x100000,
47
+
48
+ // Outgoing messages larger than fragmentationThreshold will be
49
+ // split into multiple fragments.
50
+ fragmentOutgoingMessages: true,
51
+
52
+ // Outgoing frames are fragmented if they exceed this threshold.
53
+ // Default is 16KiB
54
+ fragmentationThreshold: 0x4000,
55
+
56
+ // If true, the server will automatically send a ping to all
57
+ // clients every 'keepaliveInterval' milliseconds. The timer is
58
+ // reset on any received data from the client.
59
+ keepalive: true,
60
+
61
+ // The interval to send keepalive pings to connected clients if the
62
+ // connection is idle. Any received data will reset the counter.
63
+ keepaliveInterval: 20000,
64
+
65
+ // If true, the server will consider any connection that has not
66
+ // received any data within the amount of time specified by
67
+ // 'keepaliveGracePeriod' after a keepalive ping has been sent to
68
+ // be dead, and will drop the connection.
69
+ // Ignored if keepalive is false.
70
+ dropConnectionOnKeepaliveTimeout: true,
71
+
72
+ // The amount of time to wait after sending a keepalive ping before
73
+ // closing the connection if the connected peer does not respond.
74
+ // Ignored if keepalive is false.
75
+ keepaliveGracePeriod: 10000,
76
+
77
+ // Whether to use native TCP keep-alive instead of WebSockets ping
78
+ // and pong packets. Native TCP keep-alive sends smaller packets
79
+ // on the wire and so uses bandwidth more efficiently. This may
80
+ // be more important when talking to mobile devices.
81
+ // If this value is set to true, then these values will be ignored:
82
+ // keepaliveGracePeriod
83
+ // dropConnectionOnKeepaliveTimeout
84
+ useNativeKeepalive: false,
85
+
86
+ // If true, fragmented messages will be automatically assembled
87
+ // and the full message will be emitted via a 'message' event.
88
+ // If false, each frame will be emitted via a 'frame' event and
89
+ // the application will be responsible for aggregating multiple
90
+ // fragmented frames. Single-frame messages will emit a 'message'
91
+ // event in addition to the 'frame' event.
92
+ // Most users will want to leave this set to 'true'
93
+ assembleFragments: true,
94
+
95
+ // If this is true, websocket connections will be accepted
96
+ // regardless of the path and protocol specified by the client.
97
+ // The protocol accepted will be the first that was requested
98
+ // by the client. Clients from any origin will be accepted.
99
+ // This should only be used in the simplest of cases. You should
100
+ // probably leave this set to 'false' and inspect the request
101
+ // object to make sure it's acceptable before accepting it.
102
+ autoAcceptConnections: false,
103
+
104
+ // The Nagle Algorithm makes more efficient use of network resources
105
+ // by introducing a small delay before sending small packets so that
106
+ // multiple messages can be batched together before going onto the
107
+ // wire. This however comes at the cost of latency, so the default
108
+ // is to disable it. If you don't need low latency and are streaming
109
+ // lots of small messages, you can change this to 'false'
110
+ disableNagleAlgorithm: true,
111
+
112
+ // The number of milliseconds to wait after sending a close frame
113
+ // for an acknowledgement to come back before giving up and just
114
+ // closing the socket.
115
+ closeTimeout: 5000
116
+ };
117
+ extend(this.config, config);
118
+
119
+ // this.httpServer = httpServer;
120
+ // if (typeof(pathRegExp) === 'string') {
121
+ // pathRegExp = new RegExp('^' + pathRegExp + '$');
122
+ // }
123
+ // this.pathRegExp = pathRegExp;
124
+ // this.protocol = protocol;
125
+ if (this.config.httpServer) {
126
+ this.config.httpServer.on('upgrade', this._handlers.upgrade);
127
+ }
128
+ else {
129
+ throw new Error("You must specify an httpServer on which to mount the WebSocket server.")
130
+ }
131
+ };
132
+
133
+ WebSocketServer.prototype.unmount = function() {
134
+ this.config.httpServer.removeListener('upgrade', this._handlers.upgrade);
135
+ };
136
+
137
+ WebSocketServer.prototype.closeAllConnections = function() {
138
+ this.connections.forEach(function(connection) {
139
+ connection.close();
140
+ });
141
+ };
142
+
143
+ WebSocketServer.prototype.broadcast = function(data) {
144
+ if (Buffer.isBuffer(data)) {
145
+ this.broadcastBytes(data);
146
+ }
147
+ else if (typeof(data.toString) === 'function') {
148
+ this.broadcastUTF(data);
149
+ }
150
+ };
151
+
152
+ WebSocketServer.prototype.broadcastUTF = function(utfData) {
153
+ this.connections.forEach(function(connection) {
154
+ connection.sendUTF(utfData);
155
+ });
156
+ };
157
+
158
+ WebSocketServer.prototype.broadcastBytes = function(binaryData) {
159
+ this.connections.forEach(function(connection) {
160
+ connection.sendBytes(binaryData);
161
+ });
162
+ };
163
+
164
+ WebSocketServer.prototype.shutDown = function() {
165
+ this.unmount();
166
+ this.closeAllConnections();
167
+ };
168
+
169
+ WebSocketServer.prototype.handleUpgrade = function(request, socket, head) {
170
+ var wsRequest = new WebSocketRequest(socket, request, this.config);
171
+ try {
172
+ wsRequest.readHandshake();
173
+ }
174
+ catch(e) {
175
+ wsRequest.reject(
176
+ e.httpCode ? e.httpCode : 400,
177
+ e.message,
178
+ e.headers
179
+ );
180
+ if (Constants.DEBUG) {
181
+ console.error((new Date()) + " WebSocket: Invalid handshake: " + e.message);
182
+ }
183
+ return;
184
+ }
185
+
186
+ wsRequest.once('requestAccepted', this._handlers.requestAccepted);
187
+
188
+ if (!this.config.autoAcceptConnections && this.listeners('request').length > 0) {
189
+ this.emit('request', wsRequest);
190
+ }
191
+ else if (this.config.autoAcceptConnections) {
192
+ wsRequest.accept(wsRequest.requestedProtocols[0], wsRequest.origin);
193
+ }
194
+ else {
195
+ wsRequest.reject(404, "No handler is configured to accept the connection.");
196
+ }
197
+ };
198
+
199
+ WebSocketServer.prototype.handleRequestAccepted = function(connection) {
200
+ var self = this;
201
+ connection.once('close', function(closeReason, description) {
202
+ self.handleConnectionClose(connection, closeReason, description);
203
+ });
204
+ this.connections.push(connection);
205
+ this.emit('connect', connection);
206
+ };
207
+
208
+ WebSocketServer.prototype.handleConnectionClose = function(connection, closeReason, description) {
209
+ var index = this.connections.indexOf(connection);
210
+ if (index !== -1) {
211
+ this.connections.splice(index, 1);
212
+ }
213
+ this.emit('close', connection, closeReason, description);
214
+ };
215
+
216
+ module.exports = WebSocketServer;
@@ -0,0 +1,7 @@
1
+ module.exports = {
2
+ extend: function extend(dest, source) {
3
+ for (var prop in source) {
4
+ dest[prop] = source[prop];
5
+ }
6
+ }
7
+ };
@@ -0,0 +1,11 @@
1
+ module.exports = {
2
+ "server" : require('./WebSocketServer'),
3
+ "client" : require('./WebSocketClient'),
4
+ "router" : require('./WebSocketRouter'),
5
+ "frame" : require('./WebSocketFrame'),
6
+ "request" : require('./WebSocketRequest'),
7
+ "connection" : require('./WebSocketConnection'),
8
+ "constants" : require('./Constants'),
9
+ "deprecation": require('./Deprecation'),
10
+ "version" : "1.0.8"
11
+ };