Skip to content
Browse files

Adding socket.io, some html and initial app.js

  • Loading branch information...
1 parent b585c07 commit 84f818690c3e28bf3e996c659bb727f10f7d6125 @DanBUK DanBUK committed Feb 6, 2011
Showing with 25,544 additions and 4 deletions.
  1. +38 −4 irc.js
  2. +77 −0 public/index.html
  3. +1 −0 public/socket.io/.gitignore
  4. +2 −0 public/socket.io/Makefile
  5. +208 −0 public/socket.io/README.md
  6. +50 −0 public/socket.io/bin/build
  7. +25 −0 public/socket.io/lib/io.js
  8. +163 −0 public/socket.io/lib/socket.js
  9. +141 −0 public/socket.io/lib/transport.js
  10. +53 −0 public/socket.io/lib/transports/flashsocket.js
  11. +73 −0 public/socket.io/lib/transports/htmlfile.js
  12. +116 −0 public/socket.io/lib/transports/jsonp-polling.js
  13. +65 −0 public/socket.io/lib/transports/websocket.js
  14. +36 −0 public/socket.io/lib/transports/xhr-multipart.js
  15. +61 −0 public/socket.io/lib/transports/xhr-polling.js
  16. +135 −0 public/socket.io/lib/transports/xhr.js
  17. +60 −0 public/socket.io/lib/util.js
  18. +1 −0 public/socket.io/lib/vendor/web-socket-js/.gitignore
  19. +604 −0 public/socket.io/lib/vendor/web-socket-js/FABridge.js
  20. +109 −0 public/socket.io/lib/vendor/web-socket-js/README.txt
  21. BIN public/socket.io/lib/vendor/web-socket-js/WebSocketMain.swf
  22. BIN public/socket.io/lib/vendor/web-socket-js/WebSocketMainInsecure.zip
  23. +452 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/WebSocket.as
  24. +88 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/WebSocketMain.as
  25. +19 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/WebSocketMainInsecure.as
  26. +943 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/bridge/FABridge.as
  27. +10 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/build.sh
  28. +204 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/adobe/net/proxies/RFC2817Socket.as
  29. +375 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/gsolo/encryption/MD5.as
  30. +287 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/Crypto.as
  31. +3,235 −0 ...c/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/cert/MozillaRootCertificates.as
  32. +218 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/cert/X509Certificate.as
  33. +57 −0 ...socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/cert/X509CertificateCollection.as
  34. +82 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/HMAC.as
  35. +27 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/IHMAC.as
  36. +21 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/IHash.as
  37. +137 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/MAC.as
  38. +124 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/MD2.as
  39. +204 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/MD5.as
  40. +106 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/SHA1.as
  41. +28 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/SHA224.as
  42. +115 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/SHA256.as
  43. +71 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/hash/SHABase.as
  44. +90 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/prng/ARC4.as
  45. +20 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/prng/IPRNG.as
  46. +119 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/prng/Random.as
  47. +142 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/prng/TLSPRF.as
  48. +339 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/rsa/RSAKey.as
  49. +2,797 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/AESKey.as
  50. +375 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/BlowFishKey.as
  51. +55 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/CBCMode.as
  52. +61 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/CFB8Mode.as
  53. +64 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/CFBMode.as
  54. +58 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/CTRMode.as
  55. +365 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/DESKey.as
  56. +86 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/ECBMode.as
  57. +21 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/ICipher.as
  58. +15 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/IMode.as
  59. +32 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/IPad.as
  60. +21 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/IStreamCipher.as
  61. +35 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/ISymmetricKey.as
  62. +110 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/IVMode.as
  63. +34 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/NullPad.as
  64. +52 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/OFBMode.as
  65. +44 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/PKCS5.as
  66. +44 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/SSLPad.as
  67. +60 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/SimpleIVMode.as
  68. +42 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/TLSPad.as
  69. +88 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/TripleDESKey.as
  70. +94 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/XTeaKey.as
  71. +29 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/aeskey.pl
  72. +2,304 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/symmetric/dump.txt
  73. +1,220 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/AESKeyTest.as
  74. +58 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/ARC4Test.as
  75. +39 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/BigIntegerTest.as
  76. +148 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/BlowFishKeyTest.as
  77. +160 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/CBCModeTest.as
  78. +71 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/CFB8ModeTest.as
  79. +98 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/CFBModeTest.as
  80. +109 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/CTRModeTest.as
  81. +112 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/DESKeyTest.as
  82. +151 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/ECBModeTest.as
  83. +184 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/HMACTest.as
  84. +20 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/ITestHarness.as
  85. +56 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/MD2Test.as
  86. +58 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/MD5Test.as
  87. +101 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/OFBModeTest.as
  88. +92 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/RSAKeyTest.as
  89. +198 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/SHA1Test.as
  90. +58 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/SHA224Test.as
  91. +60 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/SHA256Test.as
  92. +51 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/TLSPRFTest.as
  93. +42 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/TestCase.as
  94. +59 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/TripleDESKeyTest.as
  95. +66 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/tests/XTeaKeyTest.as
  96. +102 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/BulkCiphers.as
  97. +117 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/CipherSuites.as
  98. +14 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/IConnectionState.as
  99. +29 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/ISecurityParameters.as
  100. +24 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/KeyExchanges.as
  101. +38 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/MACs.as
  102. +171 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/SSLConnectionState.as
  103. +26 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/SSLEvent.as
  104. +340 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/SSLSecurityParameters.as
  105. +70 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/TLSConfig.as
  106. +151 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/TLSConnectionState.as
  107. +895 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/TLSEngine.as
  108. +39 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/TLSError.as
  109. +27 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/TLSEvent.as
  110. +197 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/TLSSecurityParameters.as
  111. +370 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/TLSSocket.as
  112. +26 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/TLSSocketEvent.as
  113. +180 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/crypto/tls/TLSTest.as
  114. +90 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/math/BarrettReduction.as
  115. +1,543 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/math/BigInteger.as
  116. +35 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/math/ClassicReduction.as
  117. +11 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/math/IReduction.as
  118. +85 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/math/MontgomeryReduction.as
  119. +34 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/math/NullReduction.as
  120. +11 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/math/bi_internal.as
  121. +25 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/util/ArrayUtil.as
  122. +189 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/util/Base64.as
  123. +66 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/util/Hex.as
  124. +28 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/util/Memory.as
  125. +43 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/util/der/ByteString.as
  126. +210 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/util/der/DER.as
  127. +21 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/util/der/IAsn1Type.as
  128. +44 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/util/der/Integer.as
  129. +35 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/util/der/OID.as
  130. +112 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/util/der/ObjectIdentifier.as
  131. +118 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/util/der/PEM.as
  132. +49 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/util/der/PrintableString.as
  133. +90 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/util/der/Sequence.as
  134. +27 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/util/der/Set.as
  135. +94 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/util/der/Type.as
  136. +60 −0 public/socket.io/lib/vendor/web-socket-js/flash-src/com/hurlant/util/der/UTCTime.as
  137. +76 −0 public/socket.io/lib/vendor/web-socket-js/sample.html
  138. +4 −0 public/socket.io/lib/vendor/web-socket-js/swfobject.js
Sorry, we could not display the entire diff because it was too big.
View
42 irc.js
@@ -1,5 +1,39 @@
var http = require('http');
-http.createServer(function (req, res) {
- res.writeHead(200, {'Content-Type': 'text/plain'});
- res.end('Hello World\n');
-}).listen(8069);
+var fs = require('fs');
+var io = require('socket.io');
+var express = require('express');
+var ircjs = require('irc-js');
+
+var app = express.createServer();
+
+app.configure(function(){
+ app.use(express.staticProvider(__dirname + '/public'));
+});
+
+app.get('/', function(req, res, next){
+ res.render('./public/index.html');
+});
+app.listen(process.ENV['app_port'], process.ENV['app_host']);
+
+var socket = io.listen(app, {
+ flashPolicyServer: false,
+ transports: ['htmlfile', 'xhr-multipart', 'xhr-polling', 'jsonp-polling']
+});
+
+socket.on('connection', function(client) {
+/* var my_timer;
+ var my_client = client;
+ my_timer = setInterval(function () {
+ my_client.send(JSON.stringify({ timestamp: (new Date()).getTime() }));
+ }, 1000);
+*/
+
+ client.on('message', function(data) {
+ console.log(data);
+ });
+
+ client.on('disconnect', function() {
+ clearTimeout(my_timer);
+ console.log('disconnect');
+ });
+});
View
77 public/index.html
@@ -0,0 +1,77 @@
+<html>
+<head>
+ <title>Bejesus IRC Channel</title>
+ <style type="text/css">
+ * {
+ margin: 0px;
+ }
+ body, html {
+ margin: 0px;
+ padding: 0px;
+ color: #000;
+ background:#a7a09a;
+ height: 98%;
+ }
+ div#top_section {
+ min-height: 100%;
+ height: auto !important;
+ height: 100%;
+ }
+ div#nick_list {
+ float: right;
+ width: 150px;
+ }
+ div#chat_body {
+ float: left;
+ }
+ div#chat_bar .push {
+ clear: both;
+ height: 2em;
+ }
+ </style>
+ <script src="/socket.io/socket.io.js"></script>
+ <script type="text/javascript">
+ var sock = null;
+ // var ts = null;
+ var body_loaded = function () {
+ sock = new io.Socket();
+ sock.on('message', handleMessage);
+ sock.connect();
+ // ts = document.getElementById('timestamp');
+ var name = prompt("Please enter your nickname:", "");
+ switch (name) {
+ case "":
+ alert("You did not input a nickname, please reload if you wish to connect.");
+ sock.disconnect();
+ break;
+ case null:
+ alert("Login cancelled, please reload if you wish to connect.");
+ sock.disconnect();
+ break;
+ default:
+ sock.send(JSON.stringify({ nickname: name }));
+ break;
+ }
+ };
+ var handleMessage = function (data) {
+ var obj = JSON.parse(data);
+ // ts.textContent = obj.timestamp;
+ };
+ </script>
+</head>
+<body onload="body_loaded();">
+ <div id="top_section">
+ <div id="nick_list">
+ <ol id="nick_ol">
+ <li>dan</li>
+ </ol>
+ </div>
+ <div id="chat_body">
+ <span>Body</span>
+ </div>
+ </div>
+ <div id="chat_bar">
+ <input type="text" id="text_input"></input><button>Send</button>
+ </div>
+</body>
+</html>
View
1 public/socket.io/.gitignore
@@ -0,0 +1 @@
+s3
View
2 public/socket.io/Makefile
@@ -0,0 +1,2 @@
+build:
+ ./bin/build
View
208 public/socket.io/README.md
@@ -0,0 +1,208 @@
+socket.io
+=========
+
+#### Sockets for the rest of us
+
+The `socket.io` client is basically a simple HTTP Socket interface implementation. It allows you to establish a realtime connection with a server (see `socket.io` server [here](http://github.com/LearnBoost/Socket.IO-node)), hiding the complexity of the different transports (WebSocket, Flash, forever iframe, XHR long polling, XHR multipart encoded, etc), while retaining a WebSocket-like API:
+
+ socket = new io.Socket('localhost');
+ socket.connect();
+ socket.on('connect', function(){
+ // connected
+ });
+ socket.on('message', function(data){
+ // data here
+ });
+ socket.send('some data');
+
+### Features
+
+- Supports
+ - WebSocket
+ - Adobe Flash Socket
+ - ActiveX HTMLFile (IE)
+ - XHR with multipart encoding
+ - XHR with long-polling
+ - JSONP polling (for cross-domain)
+
+- Tested on
+ - Safari 4
+ - Google Chrome 5
+ - Internet Explorer 6
+ - Internet Explorer 7
+ - Internet Explorer 8
+ - iPhone Safari
+ - iPad Safari
+ - Firefox 3
+ - Firefox 4 (Minefield)
+ - Opera 10.61
+
+- ActionScript Socket is known not to work behind proxies, as it doesn't have access to the user agent proxy settings to implement the CONNECT HTTP method. If it fails, `socket.io` will try something else.
+
+- On a successful connection, it remembers the transport for next time (stores it in a cookie).
+
+- Small. Closure Compiled with all deps: 5.82kb (gzipped).
+
+- Easy to use! See [socket.io-node](http://github.com/LearnBoost/Socket.IO-node) for the server to connect to.
+
+### How to use
+
+ socket = new io.Socket('localhost');
+ socket.connect();
+ socket.send('some data');
+ socket.on('message', function(data){
+ alert('got some data' + data);
+ });
+
+For an example, check out the chat [source](https://github.com/LearnBoost/Socket.IO-node/blob/master/test/chat.html).
+
+### Notes
+
+If you are serving you .swf from a other domain than socket.io.js you will need to change the WEB_SOCKET_SWF_LOCATION to the insecure version.
+
+ <script>WEB_SOCKET_SWF_LOCATION = '/path/to/WebSocketMainInsecure.swf';</script>
+
+The insecure version can be found [here](http://github.com/gimite/web-socket-js/blob/master/WebSocketMainInsecure.zip).
+
+IMPORTANT! When checking out the git repo, make sure to include the submodules. One way to do it is:
+
+ git clone [repo] --recursive
+
+Another, once cloned
+
+ git submodule update --init --recursive
+
+### Documentation
+
+#### io.Socket
+
+ new io.Socket(host, [options]);
+
+Options:
+
+- *port*
+
+ Current port or 80
+
+ The port `socket.io` server is attached to (defaults to the document.location port)
+
+- *resource*
+
+ socket.io
+
+ The resource is what allows the `socket.io` server to identify incoming connections by `socket.io` clients. In other words, any HTTP server can implement socket.io and still serve other normal, non-realtime HTTP requests.
+
+- *transports*
+
+ ['websocket', 'flashsocket', 'htmlfile', 'xhr-multipart', 'xhr-polling']
+
+ A list of the transports to attempt to utilize (in order of preference)
+
+- *transportOptions*
+
+ {
+ someTransport: {
+ someOption: true
+ },
+ ...
+ }
+
+ An object containing (optional) options to pass to each transport.
+
+Properties:
+
+- *options*
+
+ The passed in options combined with the defaults
+
+- *connected*
+
+ Whether the socket is connected or not.
+
+- *connecting*
+
+ Whether the socket is connecting or not.
+
+- *transport*
+
+ The transport instance.
+
+Methods:
+
+- *connect*
+
+ Establishes a connection
+
+- *send(message)*
+
+ A string of data to send.
+
+- *disconnect*
+
+ Closes the connection
+
+- *on(event, λ)*
+
+ Adds a listener for the event *event*
+
+- *removeEvent(event, λ)*
+
+ Removes the listener λ for the event *event*
+
+Events:
+
+- *connect*
+
+ Fired when the connection is established and the handshake successful
+
+- *connecting(transport_type)*
+
+ Fired when a connection is attempted, passing the transport name
+
+- *connect_failed*
+
+ Fired when the connection timeout occurs after the last connection attempt.
+ This only fires if the `connectTimeout` option is set.
+ If the `tryTransportsOnConnectTimeout` option is set, this only fires once all
+ possible transports have been tried.
+
+- *message(message)*
+
+ Fired when a message arrives from the server
+
+- *close*
+
+ Fired when the connection is closed. Be careful with using this event, as some transports will fire it even under temporary, expected disconnections (such as XHR-Polling).
+
+- *disconnect*
+
+ Fired when the connection is considered disconnected.
+
+### Credits
+
+Guillermo Rauch &lt;guillermo@learnboost.com&gt;
+
+### License
+
+(The MIT License)
+
+Copyright (c) 2010 LearnBoost &lt;dev@learnboost.com&gt;
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
50 public/socket.io/bin/build
@@ -0,0 +1,50 @@
+#!/usr/bin/env node
+
+/**
+ * Socket.IO client
+ *
+ * @author Guillermo Rauch <guillermo@learnboost.com>
+ * @license The MIT license.
+ * @copyright Copyright (c) 2010 LearnBoost <dev@learnboost.com>
+ */
+
+/*
+ * This file will help you take all the Socket.IO client files and build socket.io.js.
+ * You can later use Google Closure Compiler on it.
+ */
+
+var fs = require('fs'),
+ sys = require('sys'),
+ socket = require('../lib/io'),
+ files = [
+ 'io.js',
+ 'util.js',
+ 'transport.js',
+ 'transports/xhr.js',
+ 'transports/websocket.js',
+ 'transports/flashsocket.js',
+ 'transports/htmlfile.js',
+ 'transports/xhr-multipart.js',
+ 'transports/xhr-polling.js',
+ 'transports/jsonp-polling.js',
+ 'socket.js',
+ 'vendor/web-socket-js/swfobject.js',
+ 'vendor/web-socket-js/FABridge.js',
+ 'vendor/web-socket-js/web_socket.js'
+ ],
+ content = "/** Socket.IO "+ socket.io.version +" - Built with build.js */\n";
+
+sys.log('Reading files…');
+
+files.forEach(function(file){
+ var path = __dirname + '/../lib/' + file;
+ sys.log (' + ' + path);
+ content += fs.readFileSync(path) + "\n";
+});
+
+sys.log('Generating…');
+
+fs.write(fs.openSync(__dirname + '/../socket.io.js', 'w'), content, 0, 'utf8');
+sys.log(' + ' + __dirname + '/../socket.io.js');
+
+sys.log('All done!');
View
25 public/socket.io/lib/io.js
@@ -0,0 +1,25 @@
+/**
+ * Socket.IO client
+ *
+ * @author Guillermo Rauch <guillermo@learnboost.com>
+ * @license The MIT license.
+ * @copyright Copyright (c) 2010 LearnBoost <dev@learnboost.com>
+ */
+
+this.io = {
+ version: '0.6.2',
+
+ setPath: function(path){
+ if (window.console && console.error) console.error('io.setPath will be removed. Please set the variable WEB_SOCKET_SWF_LOCATION pointing to WebSocketMain.swf');
+ this.path = /\/$/.test(path) ? path : path + '/';
+ WEB_SOCKET_SWF_LOCATION = path + 'lib/vendor/web-socket-js/WebSocketMain.swf';
+ }
+};
+
+if ('jQuery' in this) jQuery.io = this.io;
+
+if (typeof window != 'undefined'){
+ // WEB_SOCKET_SWF_LOCATION = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//cdn.socket.io/' + this.io.version + '/WebSocketMain.swf';
+ if (typeof WEB_SOCKET_SWF_LOCATION === 'undefined')
+ WEB_SOCKET_SWF_LOCATION = '/socket.io/lib/vendor/web-socket-js/WebSocketMain.swf';
+}
View
163 public/socket.io/lib/socket.js
@@ -0,0 +1,163 @@
+/**
+ * Socket.IO client
+ *
+ * @author Guillermo Rauch <guillermo@learnboost.com>
+ * @license The MIT license.
+ * @copyright Copyright (c) 2010 LearnBoost <dev@learnboost.com>
+ */
+
+(function(){
+
+ var Socket = io.Socket = function(host, options){
+ this.host = host || document.domain;
+ this.options = {
+ secure: false,
+ document: document,
+ port: document.location.port || 80,
+ resource: 'socket.io',
+ transports: ['websocket', 'flashsocket', 'htmlfile', 'xhr-multipart', 'xhr-polling', 'jsonp-polling'],
+ transportOptions: {
+ 'xhr-polling': {
+ timeout: 25000 // based on polling duration default
+ },
+ 'jsonp-polling': {
+ timeout: 25000
+ }
+ },
+ connectTimeout: 5000,
+ tryTransportsOnConnectTimeout: true,
+ rememberTransport: true
+ };
+ io.util.merge(this.options, options);
+ this.connected = false;
+ this.connecting = false;
+ this._events = {};
+ this.transport = this.getTransport();
+ if (!this.transport && 'console' in window) console.error('No transport available');
+ };
+
+ Socket.prototype.getTransport = function(override){
+ var transports = override || this.options.transports, match;
+ if (this.options.rememberTransport && !override){
+ match = this.options.document.cookie.match('(?:^|;)\\s*socketio=([^;]*)');
+ if (match){
+ this._rememberedTransport = true;
+ transports = [decodeURIComponent(match[1])];
+ }
+ }
+ for (var i = 0, transport; transport = transports[i]; i++){
+ if (io.Transport[transport]
+ && io.Transport[transport].check()
+ && (!this._isXDomain() || io.Transport[transport].xdomainCheck())){
+ return new io.Transport[transport](this, this.options.transportOptions[transport] || {});
+ }
+ }
+ return null;
+ };
+
+ Socket.prototype.connect = function(){
+ if (this.transport && !this.connected){
+ if (this.connecting) this.disconnect();
+ this.connecting = true;
+ this.emit('connecting', [this.transport.type]);
+ this.transport.connect();
+ if (this.options.connectTimeout){
+ var self = this;
+ this.connectTimeoutTimer = setTimeout(function(){
+ if (!self.connected){
+ self.disconnect();
+ if (self.options.tryTransportsOnConnectTimeout && !self._rememberedTransport){
+ if(!self._remainingTransports) self._remainingTransports = self.options.transports.slice(0);
+ var transports = self._remainingTransports;
+ while(transports.length > 0 && transports.splice(0,1)[0] != self.transport.type){}
+ if(transports.length){
+ self.transport = self.getTransport(transports);
+ self.connect();
+ }
+ }
+ if(!self._remainingTransports || self._remainingTransports.length == 0) self.emit('connect_failed');
+ }
+ if(self._remainingTransports && self._remainingTransports.length == 0) delete self._remainingTransports;
+ }, this.options.connectTimeout);
+ }
+ }
+ return this;
+ };
+
+ Socket.prototype.send = function(data){
+ if (!this.transport || !this.transport.connected) return this._queue(data);
+ this.transport.send(data);
+ return this;
+ };
+
+ Socket.prototype.disconnect = function(){
+ if (this.connectTimeoutTimer) clearTimeout(this.connectTimeoutTimer);
+ this.transport.disconnect();
+ return this;
+ };
+
+ Socket.prototype.on = function(name, fn){
+ if (!(name in this._events)) this._events[name] = [];
+ this._events[name].push(fn);
+ return this;
+ };
+
+ Socket.prototype.emit = function(name, args){
+ if (name in this._events){
+ var events = this._events[name].concat();
+ for (var i = 0, ii = events.length; i < ii; i++)
+ events[i].apply(this, args === undefined ? [] : args);
+ }
+ return this;
+ };
+
+ Socket.prototype.removeEvent = function(name, fn){
+ if (name in this._events){
+ for (var a = 0, l = this._events[name].length; a < l; a++)
+ if (this._events[name][a] == fn) this._events[name].splice(a, 1);
+ }
+ return this;
+ };
+
+ Socket.prototype._queue = function(message){
+ if (!('_queueStack' in this)) this._queueStack = [];
+ this._queueStack.push(message);
+ return this;
+ };
+
+ Socket.prototype._doQueue = function(){
+ if (!('_queueStack' in this) || !this._queueStack.length) return this;
+ this.transport.send(this._queueStack);
+ this._queueStack = [];
+ return this;
+ };
+
+ Socket.prototype._isXDomain = function(){
+ return this.host !== document.domain;
+ };
+
+ Socket.prototype._onConnect = function(){
+ this.connected = true;
+ this.connecting = false;
+ this._doQueue();
+ if (this.options.rememberTransport) this.options.document.cookie = 'socketio=' + encodeURIComponent(this.transport.type);
+ this.emit('connect');
+ };
+
+ Socket.prototype._onMessage = function(data){
+ this.emit('message', [data]);
+ };
+
+ Socket.prototype._onDisconnect = function(){
+ var wasConnected = this.connected;
+ this.connected = false;
+ this.connecting = false;
+ this._queueStack = [];
+ if (wasConnected) this.emit('disconnect');
+ };
+
+ Socket.prototype.fire = Socket.prototype.emit;
+
+ Socket.prototype.addListener = Socket.prototype.addEvent = Socket.prototype.addEventListener = Socket.prototype.on;
+
+})();
View
141 public/socket.io/lib/transport.js
@@ -0,0 +1,141 @@
+/**
+ * Socket.IO client
+ *
+ * @author Guillermo Rauch <guillermo@learnboost.com>
+ * @license The MIT license.
+ * @copyright Copyright (c) 2010 LearnBoost <dev@learnboost.com>
+ */
+
+// abstract
+
+(function(){
+
+ var frame = '~m~',
+
+ stringify = function(message){
+ if (Object.prototype.toString.call(message) == '[object Object]'){
+ if (!('JSON' in window)){
+ if ('console' in window && console.error) console.error('Trying to encode as JSON, but JSON.stringify is missing.');
+ return '{ "$error": "Invalid message" }';
+ }
+ return '~j~' + JSON.stringify(message);
+ } else {
+ return String(message);
+ }
+ };
+
+ Transport = io.Transport = function(base, options){
+ this.base = base;
+ this.options = {
+ timeout: 15000 // based on heartbeat interval default
+ };
+ io.util.merge(this.options, options);
+ };
+
+ Transport.prototype.send = function(){
+ throw new Error('Missing send() implementation');
+ };
+
+ Transport.prototype.connect = function(){
+ throw new Error('Missing connect() implementation');
+ };
+
+ Transport.prototype.disconnect = function(){
+ throw new Error('Missing disconnect() implementation');
+ };
+
+ Transport.prototype._encode = function(messages){
+ var ret = '', message,
+ messages = io.util.isArray(messages) ? messages : [messages];
+ for (var i = 0, l = messages.length; i < l; i++){
+ message = messages[i] === null || messages[i] === undefined ? '' : stringify(messages[i]);
+ ret += frame + message.length + frame + message;
+ }
+ return ret;
+ };
+
+ Transport.prototype._decode = function(data){
+ var messages = [], number, n;
+ do {
+ if (data.substr(0, 3) !== frame) return messages;
+ data = data.substr(3);
+ number = '', n = '';
+ for (var i = 0, l = data.length; i < l; i++){
+ n = Number(data.substr(i, 1));
+ if (data.substr(i, 1) == n){
+ number += n;
+ } else {
+ data = data.substr(number.length + frame.length);
+ number = Number(number);
+ break;
+ }
+ }
+ messages.push(data.substr(0, number)); // here
+ data = data.substr(number);
+ } while(data !== '');
+ return messages;
+ };
+
+ Transport.prototype._onData = function(data){
+ this._setTimeout();
+ var msgs = this._decode(data);
+ if (msgs && msgs.length){
+ for (var i = 0, l = msgs.length; i < l; i++){
+ this._onMessage(msgs[i]);
+ }
+ }
+ };
+
+ Transport.prototype._setTimeout = function(){
+ var self = this;
+ if (this._timeout) clearTimeout(this._timeout);
+ this._timeout = setTimeout(function(){
+ self._onTimeout();
+ }, this.options.timeout);
+ };
+
+ Transport.prototype._onTimeout = function(){
+ this._onDisconnect();
+ };
+
+ Transport.prototype._onMessage = function(message){
+ if (!this.sessionid){
+ this.sessionid = message;
+ this._onConnect();
+ } else if (message.substr(0, 3) == '~h~'){
+ this._onHeartbeat(message.substr(3));
+ } else if (message.substr(0, 3) == '~j~'){
+ this.base._onMessage(JSON.parse(message.substr(3)));
+ } else {
+ this.base._onMessage(message);
+ }
+ },
+
+ Transport.prototype._onHeartbeat = function(heartbeat){
+ this.send('~h~' + heartbeat); // echo
+ };
+
+ Transport.prototype._onConnect = function(){
+ this.connected = true;
+ this.connecting = false;
+ this.base._onConnect();
+ this._setTimeout();
+ };
+
+ Transport.prototype._onDisconnect = function(){
+ this.connecting = false;
+ this.connected = false;
+ this.sessionid = null;
+ this.base._onDisconnect();
+ };
+
+ Transport.prototype._prepareUrl = function(){
+ return (this.base.options.secure ? 'https' : 'http')
+ + '://' + this.base.host
+ + ':' + this.base.options.port
+ + '/' + this.base.options.resource
+ + '/' + this.type
+ + (this.sessionid ? ('/' + this.sessionid) : '/');
+ };
+
+})();
View
53 public/socket.io/lib/transports/flashsocket.js
@@ -0,0 +1,53 @@
+/**
+ * Socket.IO client
+ *
+ * @author Guillermo Rauch <guillermo@learnboost.com>
+ * @license The MIT license.
+ * @copyright Copyright (c) 2010 LearnBoost <dev@learnboost.com>
+ */
+
+(function(){
+
+ var Flashsocket = io.Transport.flashsocket = function(){
+ io.Transport.websocket.apply(this, arguments);
+ };
+
+ io.util.inherit(Flashsocket, io.Transport.websocket);
+
+ Flashsocket.prototype.type = 'flashsocket';
+
+ Flashsocket.prototype.connect = function(){
+ var self = this, args = arguments;
+ WebSocket.__addTask(function(){
+ io.Transport.websocket.prototype.connect.apply(self, args);
+ });
+ return this;
+ };
+
+ Flashsocket.prototype.send = function(){
+ var self = this, args = arguments;
+ WebSocket.__addTask(function(){
+ io.Transport.websocket.prototype.send.apply(self, args);
+ });
+ return this;
+ };
+
+ Flashsocket.check = function(){
+ if (typeof WebSocket == 'undefined' || !('__addTask' in WebSocket)) return false;
+ if (io.util.opera) return false; // opera is buggy with this transport
+ if ('navigator' in window && 'plugins' in navigator && navigator.plugins['Shockwave Flash']){
+ return !!navigator.plugins['Shockwave Flash'].description;
+ }
+ if ('ActiveXObject' in window) {
+ try {
+ return !!new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version');
+ } catch (e) {}
+ }
+ return false;
+ };
+
+ Flashsocket.xdomainCheck = function(){
+ return true;
+ };
+
+})();
View
73 public/socket.io/lib/transports/htmlfile.js
@@ -0,0 +1,73 @@
+/**
+ * Socket.IO client
+ *
+ * @author Guillermo Rauch <guillermo@learnboost.com>
+ * @license The MIT license.
+ * @copyright Copyright (c) 2010 LearnBoost <dev@learnboost.com>
+ */
+
+(function(){
+
+ var HTMLFile = io.Transport.htmlfile = function(){
+ io.Transport.XHR.apply(this, arguments);
+ };
+
+ io.util.inherit(HTMLFile, io.Transport.XHR);
+
+ HTMLFile.prototype.type = 'htmlfile';
+
+ HTMLFile.prototype._get = function(){
+ var self = this;
+ this._open();
+ window.attachEvent('onunload', function(){ self._destroy(); });
+ };
+
+ HTMLFile.prototype._open = function(){
+ this._doc = new ActiveXObject('htmlfile');
+ this._doc.open();
+ this._doc.write('<html></html>');
+ this._doc.parentWindow.s = this;
+ this._doc.close();
+
+ var _iframeC = this._doc.createElement('div');
+ this._doc.body.appendChild(_iframeC);
+ this._iframe = this._doc.createElement('iframe');
+ _iframeC.appendChild(this._iframe);
+ this._iframe.src = this._prepareUrl() + '/' + (+ new Date);
+ };
+
+ HTMLFile.prototype._ = function(data, doc){
+ this._onData(data);
+ var script = doc.getElementsByTagName('script')[0];
+ script.parentNode.removeChild(script);
+ };
+
+ HTMLFile.prototype._destroy = function(){
+ if (this._iframe){
+ this._iframe.src = 'about:blank';
+ this._doc = null;
+ CollectGarbage();
+ }
+ };
+
+ HTMLFile.prototype.disconnect = function(){
+ this._destroy();
+ return io.Transport.XHR.prototype.disconnect.call(this);
+ };
+
+ HTMLFile.check = function(){
+ if ('ActiveXObject' in window){
+ try {
+ var a = new ActiveXObject('htmlfile');
+ return a && io.Transport.XHR.check();
+ } catch(e){}
+ }
+ return false;
+ };
+
+ HTMLFile.xdomainCheck = function(){
+ // we can probably do handling for sub-domains, we should test that it's cross domain but a subdomain here
+ return false;
+ };
+
+})();
View
116 public/socket.io/lib/transports/jsonp-polling.js
@@ -0,0 +1,116 @@
+/**
+ * Socket.IO client
+ *
+ * @author Guillermo Rauch <guillermo@learnboost.com>
+ * @license The MIT license.
+ * @copyright Copyright (c) 2010 LearnBoost <dev@learnboost.com>
+ */
+
+io.JSONP = [];
+
+JSONPPolling = io.Transport['jsonp-polling'] = function(){
+ io.Transport.XHR.apply(this, arguments);
+ this._insertAt = document.getElementsByTagName('script')[0];
+ this._index = io.JSONP.length;
+ io.JSONP.push(this);
+};
+
+io.util.inherit(JSONPPolling, io.Transport['xhr-polling']);
+
+JSONPPolling.prototype.type = 'jsonp-polling';
+
+JSONPPolling.prototype._send = function(data){
+ var self = this;
+ if (!('_form' in this)){
+ var form = document.createElement('FORM'),
+ area = document.createElement('TEXTAREA'),
+ id = this._iframeId = 'socket_io_iframe_' + this._index,
+ iframe;
+
+ form.style.position = 'absolute';
+ form.style.top = '-1000px';
+ form.style.left = '-1000px';
+ form.target = id;
+ form.method = 'POST';
+ form.action = this._prepareUrl() + '/' + (+new Date) + '/' + this._index;
+ area.name = 'data';
+ form.appendChild(area);
+ this._insertAt.parentNode.insertBefore(form, this._insertAt);
+ document.body.appendChild(form);
+
+ this._form = form;
+ this._area = area;
+ }
+
+ function complete(){
+ initIframe();
+ self._posting = false;
+ self._checkSend();
+ };
+
+ function initIframe(){
+ if (self._iframe){
+ self._form.removeChild(self._iframe);
+ }
+
+ try {
+ // ie6 dynamic iframes with target="" support (thanks Chris Lambacher)
+ iframe = document.createElement('<iframe name="'+ self._iframeId +'">');
+ } catch(e){
+ iframe = document.createElement('iframe');
+ iframe.name = self._iframeId;
+ }
+
+ iframe.id = self._iframeId;
+
+ self._form.appendChild(iframe);
+ self._iframe = iframe;
+ };
+
+ initIframe();
+
+ this._posting = true;
+ this._area.value = data;
+
+ try {
+ this._form.submit();
+ } catch(e){}
+
+ if (this._iframe.attachEvent){
+ iframe.onreadystatechange = function(){
+ if (self._iframe.readyState == 'complete') complete();
+ };
+ } else {
+ this._iframe.onload = complete;
+ }
+};
+
+JSONPPolling.prototype._get = function(){
+ var self = this,
+ script = document.createElement('SCRIPT');
+ if (this._script){
+ this._script.parentNode.removeChild(this._script);
+ this._script = null;
+ }
+ script.async = true;
+ script.src = this._prepareUrl() + '/' + (+new Date) + '/' + this._index;
+ script.onerror = function(){
+ self._onDisconnect();
+ };
+ this._insertAt.parentNode.insertBefore(script, this._insertAt);
+ this._script = script;
+};
+
+JSONPPolling.prototype._ = function(){
+ this._onData.apply(this, arguments);
+ this._get();
+ return this;
+};
+
+JSONPPolling.check = function(){
+ return true;
+};
+
+JSONPPolling.xdomainCheck = function(){
+ return true;
+};
View
65 public/socket.io/lib/transports/websocket.js
@@ -0,0 +1,65 @@
+/**
+ * Socket.IO client
+ *
+ * @author Guillermo Rauch <guillermo@learnboost.com>
+ * @license The MIT license.
+ * @copyright Copyright (c) 2010 LearnBoost <dev@learnboost.com>
+ */
+
+(function(){
+
+ var WS = io.Transport.websocket = function(){
+ io.Transport.apply(this, arguments);
+ };
+
+ io.util.inherit(WS, io.Transport);
+
+ WS.prototype.type = 'websocket';
+
+ WS.prototype.connect = function(){
+ var self = this;
+ this.socket = new WebSocket(this._prepareUrl());
+ this.socket.onmessage = function(ev){ self._onData(ev.data); };
+ this.socket.onclose = function(ev){ self._onClose(); };
+ this.socket.onerror = function(e){ self._onError(e); };
+ return this;
+ };
+
+ WS.prototype.send = function(data){
+ if (this.socket) this.socket.send(this._encode(data));
+ return this;
+ };
+
+ WS.prototype.disconnect = function(){
+ if (this.socket) this.socket.close();
+ return this;
+ };
+
+ WS.prototype._onClose = function(){
+ this._onDisconnect();
+ return this;
+ };
+
+ WS.prototype._onError = function(e){
+ this.base.emit('error', [e]);
+ };
+
+ WS.prototype._prepareUrl = function(){
+ return (this.base.options.secure ? 'wss' : 'ws')
+ + '://' + this.base.host
+ + ':' + this.base.options.port
+ + '/' + this.base.options.resource
+ + '/' + this.type
+ + (this.sessionid ? ('/' + this.sessionid) : '');
+ };
+
+ WS.check = function(){
+ // we make sure WebSocket is not confounded with a previously loaded flash WebSocket
+ return 'WebSocket' in window && WebSocket.prototype && ( WebSocket.prototype.send && !!WebSocket.prototype.send.toString().match(/native/i)) && typeof WebSocket !== "undefined";
+ };
+
+ WS.xdomainCheck = function(){
+ return true;
+ };
+
+})();
View
36 public/socket.io/lib/transports/xhr-multipart.js
@@ -0,0 +1,36 @@
+/**
+ * Socket.IO client
+ *
+ * @author Guillermo Rauch <guillermo@learnboost.com>
+ * @license The MIT license.
+ * @copyright Copyright (c) 2010 LearnBoost <dev@learnboost.com>
+ */
+
+(function(){
+
+ var XHRMultipart = io.Transport['xhr-multipart'] = function(){
+ io.Transport.XHR.apply(this, arguments);
+ };
+
+ io.util.inherit(XHRMultipart, io.Transport.XHR);
+
+ XHRMultipart.prototype.type = 'xhr-multipart';
+
+ XHRMultipart.prototype._get = function(){
+ var self = this;
+ this._xhr = this._request('', 'GET', true);
+ this._xhr.onreadystatechange = function(){
+ if (self._xhr.readyState == 4) self._onData(self._xhr.responseText);
+ };
+ this._xhr.send(null);
+ };
+
+ XHRMultipart.check = function(){
+ return 'XMLHttpRequest' in window && 'prototype' in XMLHttpRequest && 'multipart' in XMLHttpRequest.prototype;
+ };
+
+ XHRMultipart.xdomainCheck = function(){
+ return true;
+ };
+
+})();
View
61 public/socket.io/lib/transports/xhr-polling.js
@@ -0,0 +1,61 @@
+/**
+ * Socket.IO client
+ *
+ * @author Guillermo Rauch <guillermo@learnboost.com>
+ * @license The MIT license.
+ * @copyright Copyright (c) 2010 LearnBoost <dev@learnboost.com>
+ */
+
+(function(){
+
+ var empty = new Function(),
+
+ XHRPolling = io.Transport['xhr-polling'] = function(){
+ io.Transport.XHR.apply(this, arguments);
+ };
+
+ io.util.inherit(XHRPolling, io.Transport.XHR);
+
+ XHRPolling.prototype.type = 'xhr-polling';
+
+ XHRPolling.prototype.connect = function(){
+ if (io.util.ios || io.util.android){
+ var self = this;
+ io.util.load(function(){
+ setTimeout(function(){
+ io.Transport.XHR.prototype.connect.call(self);
+ }, 10);
+ });
+ } else {
+ io.Transport.XHR.prototype.connect.call(this);
+ }
+ };
+
+ XHRPolling.prototype._get = function(){
+ var self = this;
+ this._xhr = this._request(+ new Date, 'GET');
+ this._xhr.onreadystatechange = function(){
+ var status;
+ if (self._xhr.readyState == 4){
+ self._xhr.onreadystatechange = empty;
+ try { status = self._xhr.status; } catch(e){}
+ if (status == 200){
+ self._onData(self._xhr.responseText);
+ self._get();
+ } else {
+ self._onDisconnect();
+ }
+ }
+ };
+ this._xhr.send(null);
+ };
+
+ XHRPolling.check = function(){
+ return io.Transport.XHR.check();
+ };
+
+ XHRPolling.xdomainCheck = function(){
+ return io.Transport.XHR.xdomainCheck();
+ };
+
+})();
View
135 public/socket.io/lib/transports/xhr.js
@@ -0,0 +1,135 @@
+/**
+ * Socket.IO client
+ *
+ * @author Guillermo Rauch <guillermo@learnboost.com>
+ * @license The MIT license.
+ * @copyright Copyright (c) 2010 LearnBoost <dev@learnboost.com>
+ */
+
+(function(){
+
+ var empty = new Function,
+
+ XMLHttpRequestCORS = (function(){
+ if (!('XMLHttpRequest' in window)) return false;
+ // CORS feature detection
+ var a = new XMLHttpRequest();
+ return a.withCredentials != undefined;
+ })(),
+
+ request = function(xdomain){
+ if ('XDomainRequest' in window && xdomain) return new XDomainRequest();
+ if ('XMLHttpRequest' in window && (!xdomain || XMLHttpRequestCORS)) return new XMLHttpRequest();
+ if (!xdomain){
+ try {
+ var a = new ActiveXObject('MSXML2.XMLHTTP');
+ return a;
+ } catch(e){}
+
+ try {
+ var b = new ActiveXObject('Microsoft.XMLHTTP');
+ return b;
+ } catch(e){}
+ }
+ return false;
+ },
+
+ XHR = io.Transport.XHR = function(){
+ io.Transport.apply(this, arguments);
+ this._sendBuffer = [];
+ };
+
+ io.util.inherit(XHR, io.Transport);
+
+ XHR.prototype.connect = function(){
+ this._get();
+ return this;
+ };
+
+ XHR.prototype._checkSend = function(){
+ if (!this._posting && this._sendBuffer.length){
+ var encoded = this._encode(this._sendBuffer);
+ this._sendBuffer = [];
+ this._send(encoded);
+ }
+ };
+
+ XHR.prototype.send = function(data){
+ if (io.util.isArray(data)){
+ this._sendBuffer.push.apply(this._sendBuffer, data);
+ } else {
+ this._sendBuffer.push(data);
+ }
+ this._checkSend();
+ return this;
+ };
+
+ XHR.prototype._send = function(data){
+ var self = this;
+ this._posting = true;
+ this._sendXhr = this._request('send', 'POST');
+ this._sendXhr.onreadystatechange = function(){
+ var status;
+ if (self._sendXhr.readyState == 4){
+ self._sendXhr.onreadystatechange = empty;
+ try { status = self._sendXhr.status; } catch(e){}
+ self._posting = false;
+ if (status == 200){
+ self._checkSend();
+ } else {
+ self._onDisconnect();
+ }
+ }
+ };
+ this._sendXhr.send('data=' + encodeURIComponent(data));
+ };
+
+ XHR.prototype.disconnect = function(){
+ // send disconnection signal
+ this._onDisconnect();
+ return this;
+ };
+
+ XHR.prototype._onDisconnect = function(){
+ if (this._xhr){
+ this._xhr.onreadystatechange = empty;
+ try {
+ this._xhr.abort();
+ } catch(e){}
+ this._xhr = null;
+ }
+ if (this._sendXhr){
+ this._sendXhr.onreadystatechange = empty;
+ try {
+ this._sendXhr.abort();
+ } catch(e){}
+ this._sendXhr = null;
+ }
+ this._sendBuffer = [];
+ io.Transport.prototype._onDisconnect.call(this);
+ };
+
+ XHR.prototype._request = function(url, method, multipart){
+ var req = request(this.base._isXDomain());
+ if (multipart) req.multipart = true;
+ req.open(method || 'GET', this._prepareUrl() + (url ? '/' + url : ''));
+ if (method == 'POST' && 'setRequestHeader' in req){
+ req.setRequestHeader('Content-type', 'application/x-www-form-urlencoded; charset=utf-8');
+ }
+ return req;
+ };
+
+ XHR.check = function(xdomain){
+ try {
+ if (request(xdomain)) return true;
+ } catch(e){}
+ return false;
+ };
+
+ XHR.xdomainCheck = function(){
+ return XHR.check(true);
+ };
+
+ XHR.request = request;
+
+})();
View
60 public/socket.io/lib/util.js
@@ -0,0 +1,60 @@
+/**
+ * Socket.IO client
+ *
+ * @author Guillermo Rauch <guillermo@learnboost.com>
+ * @license The MIT license.
+ * @copyright Copyright (c) 2010 LearnBoost <dev@learnboost.com>
+ */
+
+(function(){
+
+ var _pageLoaded = false;
+
+ io.util = {
+
+ ios: false,
+
+ load: function(fn){
+ if (/loaded|complete/.test(document.readyState) || _pageLoaded) return fn();
+ if ('attachEvent' in window){
+ window.attachEvent('onload', fn);
+ } else {
+ window.addEventListener('load', fn, false);
+ }
+ },
+
+ inherit: function(ctor, superCtor){
+ // no support for `instanceof` for now
+ for (var i in superCtor.prototype){
+ ctor.prototype[i] = superCtor.prototype[i];
+ }
+ },
+
+ indexOf: function(arr, item, from){
+ for (var l = arr.length, i = (from < 0) ? Math.max(0, l + from) : from || 0; i < l; i++){
+ if (arr[i] === item) return i;
+ }
+ return -1;
+ },
+
+ isArray: function(obj){
+ return Object.prototype.toString.call(obj) === '[object Array]';
+ },
+
+ merge: function(target, additional){
+ for (var i in additional)
+ if (additional.hasOwnProperty(i))
+ target[i] = additional[i];
+ }
+
+ };
+
+ io.util.ios = /iphone|ipad/i.test(navigator.userAgent);
+ io.util.android = /android/i.test(navigator.userAgent);
+ io.util.opera = /opera/i.test(navigator.userAgent);
+
+ io.util.load(function(){
+ _pageLoaded = true;
+ });
+
+})();
View
1 public/socket.io/lib/vendor/web-socket-js/.gitignore
@@ -0,0 +1 @@
+test.html
View
604 public/socket.io/lib/vendor/web-socket-js/FABridge.js
@@ -0,0 +1,604 @@
+/*
+/*
+Copyright 2006 Adobe Systems Incorporated
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+*/
+
+
+/*
+ * The Bridge class, responsible for navigating AS instances
+ */
+function FABridge(target,bridgeName)
+{
+ this.target = target;
+ this.remoteTypeCache = {};
+ this.remoteInstanceCache = {};
+ this.remoteFunctionCache = {};
+ this.localFunctionCache = {};
+ this.bridgeID = FABridge.nextBridgeID++;
+ this.name = bridgeName;
+ this.nextLocalFuncID = 0;
+ FABridge.instances[this.name] = this;
+ FABridge.idMap[this.bridgeID] = this;
+
+ return this;
+}
+
+// type codes for packed values
+FABridge.TYPE_ASINSTANCE = 1;
+FABridge.TYPE_ASFUNCTION = 2;
+
+FABridge.TYPE_JSFUNCTION = 3;
+FABridge.TYPE_ANONYMOUS = 4;
+
+FABridge.initCallbacks = {};
+FABridge.userTypes = {};
+
+FABridge.addToUserTypes = function()
+{
+ for (var i = 0; i < arguments.length; i++)
+ {
+ FABridge.userTypes[arguments[i]] = {
+ 'typeName': arguments[i],
+ 'enriched': false
+ };
+ }
+}
+
+FABridge.argsToArray = function(args)
+{
+ var result = [];
+ for (var i = 0; i < args.length; i++)
+ {
+ result[i] = args[i];
+ }
+ return result;
+}
+
+function instanceFactory(objID)
+{
+ this.fb_instance_id = objID;
+ return this;
+}
+
+function FABridge__invokeJSFunction(args)
+{
+ var funcID = args[0];
+ var throughArgs = args.concat();//FABridge.argsToArray(arguments);
+ throughArgs.shift();
+
+ var bridge = FABridge.extractBridgeFromID(funcID);
+ return bridge.invokeLocalFunction(funcID, throughArgs);
+}
+
+FABridge.addInitializationCallback = function(bridgeName, callback)
+{
+ var inst = FABridge.instances[bridgeName];
+ if (inst != undefined)
+ {
+ callback.call(inst);
+ return;
+ }
+
+ var callbackList = FABridge.initCallbacks[bridgeName];
+ if(callbackList == null)
+ {
+ FABridge.initCallbacks[bridgeName] = callbackList = [];
+ }
+
+ callbackList.push(callback);
+}
+
+// updated for changes to SWFObject2
+function FABridge__bridgeInitialized(bridgeName) {
+ var objects = document.getElementsByTagName("object");
+ var ol = objects.length;
+ var activeObjects = [];
+ if (ol > 0) {
+ for (var i = 0; i < ol; i++) {
+ if (typeof objects[i].SetVariable != "undefined") {
+ activeObjects[activeObjects.length] = objects[i];
+ }
+ }
+ }
+ var embeds = document.getElementsByTagName("embed");
+ var el = embeds.length;
+ var activeEmbeds = [];
+ if (el > 0) {
+ for (var j = 0; j < el; j++) {
+ if (typeof embeds[j].SetVariable != "undefined") {
+ activeEmbeds[activeEmbeds.length] = embeds[j];
+ }
+ }
+ }
+ var aol = activeObjects.length;
+ var ael = activeEmbeds.length;
+ var searchStr = "bridgeName="+ bridgeName;
+ if ((aol == 1 && !ael) || (aol == 1 && ael == 1)) {
+ FABridge.attachBridge(activeObjects[0], bridgeName);
+ }
+ else if (ael == 1 && !aol) {
+ FABridge.attachBridge(activeEmbeds[0], bridgeName);
+ }
+ else {
+ var flash_found = false;
+ if (aol > 1) {
+ for (var k = 0; k < aol; k++) {
+ var params = activeObjects[k].childNodes;
+ for (var l = 0; l < params.length; l++) {
+ var param = params[l];
+ if (param.nodeType == 1 && param.tagName.toLowerCase() == "param" && param["name"].toLowerCase() == "flashvars" && param["value"].indexOf(searchStr) >= 0) {
+ FABridge.attachBridge(activeObjects[k], bridgeName);
+ flash_found = true;
+ break;
+ }
+ }
+ if (flash_found) {
+ break;
+ }
+ }
+ }
+ if (!flash_found && ael > 1) {
+ for (var m = 0; m < ael; m++) {
+ var flashVars = activeEmbeds[m].attributes.getNamedItem("flashVars").nodeValue;
+ if (flashVars.indexOf(searchStr) >= 0) {
+ FABridge.attachBridge(activeEmbeds[m], bridgeName);
+ break;
+ }
+ }
+ }
+ }
+ return true;
+}
+
+// used to track multiple bridge instances, since callbacks from AS are global across the page.
+
+FABridge.nextBridgeID = 0;
+FABridge.instances = {};
+FABridge.idMap = {};
+FABridge.refCount = 0;
+
+FABridge.extractBridgeFromID = function(id)
+{
+ var bridgeID = (id >> 16);
+ return FABridge.idMap[bridgeID];
+}
+
+FABridge.attachBridge = function(instance, bridgeName)
+{
+ var newBridgeInstance = new FABridge(instance, bridgeName);
+
+ FABridge[bridgeName] = newBridgeInstance;
+
+/* FABridge[bridgeName] = function() {
+ return newBridgeInstance.root();
+ }
+*/
+ var callbacks = FABridge.initCallbacks[bridgeName];
+ if (callbacks == null)
+ {
+ return;
+ }
+ for (var i = 0; i < callbacks.length; i++)
+ {
+ callbacks[i].call(newBridgeInstance);
+ }
+ delete FABridge.initCallbacks[bridgeName]
+}
+
+// some methods can't be proxied. You can use the explicit get,set, and call methods if necessary.
+
+FABridge.blockedMethods =
+{
+ toString: true,
+ get: true,
+ set: true,
+ call: true
+};
+
+FABridge.prototype =
+{
+
+
+// bootstrapping
+
+ root: function()
+ {
+ return this.deserialize(this.target.getRoot());
+ },
+//clears all of the AS objects in the cache maps
+ releaseASObjects: function()
+ {
+ return this.target.releaseASObjects();
+ },
+//clears a specific object in AS from the type maps
+ releaseNamedASObject: function(value)
+ {
+ if(typeof(value) != "object")
+ {
+ return false;
+ }
+ else
+ {
+ var ret = this.target.releaseNamedASObject(value.fb_instance_id);
+ return ret;
+ }
+ },
+//create a new AS Object
+ create: function(className)
+ {
+ return this.deserialize(this.target.create(className));
+ },
+
+
+ // utilities
+
+ makeID: function(token)
+ {
+ return (this.bridgeID << 16) + token;
+ },
+
+
+ // low level access to the flash object
+
+//get a named property from an AS object
+ getPropertyFromAS: function(objRef, propName)
+ {
+ if (FABridge.refCount > 0)
+ {
+ throw new Error("You are trying to call recursively into the Flash Player which is not allowed. In most cases the JavaScript setTimeout function, can be used as a workaround.");
+ }
+ else
+ {
+ FABridge.refCount++;
+ retVal = this.target.getPropFromAS(objRef, propName);
+ retVal = this.handleError(retVal);
+ FABridge.refCount--;
+ return retVal;
+ }
+ },
+//set a named property on an AS object
+ setPropertyInAS: function(objRef,propName, value)
+ {
+ if (FABridge.refCount > 0)
+ {
+ throw new Error("You are trying to call recursively into the Flash Player which is not allowed. In most cases the JavaScript setTimeout function, can be used as a workaround.");
+ }
+ else
+ {
+ FABridge.refCount++;
+ retVal = this.target.setPropInAS(objRef,propName, this.serialize(value));
+ retVal = this.handleError(retVal);
+ FABridge.refCount--;
+ return retVal;
+ }
+ },
+
+//call an AS function
+ callASFunction: function(funcID, args)
+ {
+ if (FABridge.refCount > 0)
+ {
+ throw new Error("You are trying to call recursively into the Flash Player which is not allowed. In most cases the JavaScript setTimeout function, can be used as a workaround.");
+ }
+ else
+ {
+ FABridge.refCount++;
+ retVal = this.target.invokeASFunction(funcID, this.serialize(args));
+ retVal = this.handleError(retVal);
+ FABridge.refCount--;
+ return retVal;
+ }
+ },
+//call a method on an AS object
+ callASMethod: function(objID, funcName, args)
+ {
+ if (FABridge.refCount > 0)
+ {
+ throw new Error("You are trying to call recursively into the Flash Player which is not allowed. In most cases the JavaScript setTimeout function, can be used as a workaround.");
+ }
+ else
+ {
+ FABridge.refCount++;
+ args = this.serialize(args);
+ retVal = this.target.invokeASMethod(objID, funcName, args);
+ retVal = this.handleError(retVal);
+ FABridge.refCount--;
+ return retVal;
+ }
+ },
+
+ // responders to remote calls from flash
+
+ //callback from flash that executes a local JS function
+ //used mostly when setting js functions as callbacks on events
+ invokeLocalFunction: function(funcID, args)
+ {
+ var result;
+ var func = this.localFunctionCache[funcID];
+
+ if(func != undefined)
+ {
+ result = this.serialize(func.apply(null, this.deserialize(args)));
+ }
+
+ return result;
+ },
+
+ // Object Types and Proxies
+
+ // accepts an object reference, returns a type object matching the obj reference.
+ getTypeFromName: function(objTypeName)
+ {
+ return this.remoteTypeCache[objTypeName];
+ },
+ //create an AS proxy for the given object ID and type
+ createProxy: function(objID, typeName)
+ {
+ var objType = this.getTypeFromName(typeName);
+ instanceFactory.prototype = objType;
+ var instance = new instanceFactory(objID);
+ this.remoteInstanceCache[objID] = instance;
+ return instance;
+ },
+ //return the proxy associated with the given object ID
+ getProxy: function(objID)
+ {
+ return this.remoteInstanceCache[objID];
+ },
+
+ // accepts a type structure, returns a constructed type
+ addTypeDataToCache: function(typeData)
+ {
+ var newType = new ASProxy(this, typeData.name);
+ var accessors = typeData.accessors;
+ for (var i = 0; i < accessors.length; i++)
+ {
+ this.addPropertyToType(newType, accessors[i]);
+ }
+
+ var methods = typeData.methods;
+ for (var i = 0; i < methods.length; i++)
+ {
+ if (FABridge.blockedMethods[methods[i]] == undefined)
+ {
+ this.addMethodToType(newType, methods[i]);
+ }
+ }
+
+
+ this.remoteTypeCache[newType.typeName] = newType;
+ return newType;
+ },
+
+ //add a property to a typename; used to define the properties that can be called on an AS proxied object
+ addPropertyToType: function(ty, propName)
+ {
+ var c = propName.charAt(0);
+ var setterName;
+ var getterName;
+ if(c >= "a" && c <= "z")
+ {
+ getterName = "get" + c.toUpperCase() + propName.substr(1);
+ setterName = "set" + c.toUpperCase() + propName.substr(1);
+ }
+ else
+ {
+ getterName = "get" + propName;
+ setterName = "set" + propName;
+ }
+ ty[setterName] = function(val)
+ {
+ this.bridge.setPropertyInAS(this.fb_instance_id, propName, val);
+ }
+ ty[getterName] = function()
+ {
+ return this.bridge.deserialize(this.bridge.getPropertyFromAS(this.fb_instance_id, propName));
+ }
+ },
+
+ //add a method to a typename; used to define the methods that can be callefd on an AS proxied object
+ addMethodToType: function(ty, methodName)
+ {
+ ty[methodName] = function()
+ {
+ return this.bridge.deserialize(this.bridge.callASMethod(this.fb_instance_id, methodName, FABridge.argsToArray(arguments)));
+ }
+ },
+
+ // Function Proxies
+
+ //returns the AS proxy for the specified function ID
+ getFunctionProxy: function(funcID)
+ {
+ var bridge = this;
+ if (this.remoteFunctionCache[funcID] == null)
+ {
+ this.remoteFunctionCache[funcID] = function()
+ {
+ bridge.callASFunction(funcID, FABridge.argsToArray(arguments));
+ }
+ }
+ return this.remoteFunctionCache[funcID];
+ },
+
+ //reutrns the ID of the given function; if it doesnt exist it is created and added to the local cache
+ getFunctionID: function(func)
+ {
+ if (func.__bridge_id__ == undefined)
+ {
+ func.__bridge_id__ = this.makeID(this.nextLocalFuncID++);
+ this.localFunctionCache[func.__bridge_id__] = func;
+ }
+ return func.__bridge_id__;
+ },
+
+ // serialization / deserialization
+
+ serialize: function(value)
+ {
+ var result = {};
+
+ var t = typeof(value);
+ //primitives are kept as such
+ if (t == "number" || t == "string" || t == "boolean" || t == null || t == undefined)
+ {
+ result = value;
+ }
+ else if (value instanceof Array)
+ {
+ //arrays are serializesd recursively
+ result = [];
+ for (var i = 0; i < value.length; i++)
+ {
+ result[i] = this.serialize(value[i]);
+ }
+ }
+ else if (t == "function")
+ {
+ //js functions are assigned an ID and stored in the local cache
+ result.type = FABridge.TYPE_JSFUNCTION;
+ result.value = this.getFunctionID(value);
+ }
+ else if (value instanceof ASProxy)
+ {
+ result.type = FABridge.TYPE_ASINSTANCE;
+ result.value = value.fb_instance_id;
+ }
+ else
+ {
+ result.type = FABridge.TYPE_ANONYMOUS;
+ result.value = value;
+ }
+
+ return result;
+ },
+
+ //on deserialization we always check the return for the specific error code that is used to marshall NPE's into JS errors
+ // the unpacking is done by returning the value on each pachet for objects/arrays
+ deserialize: function(packedValue)
+ {
+
+ var result;
+
+ var t = typeof(packedValue);
+ if (t == "number" || t == "string" || t == "boolean" || packedValue == null || packedValue == undefined)
+ {
+ result = this.handleError(packedValue);
+ }
+ else if (packedValue instanceof Array)
+ {
+ result = [];
+ for (var i = 0; i < packedValue.length; i++)
+ {
+ result[i] = this.deserialize(packedValue[i]);
+ }
+ }
+ else if (t == "object")
+ {
+ for(var i = 0; i < packedValue.newTypes.length; i++)
+ {
+ this.addTypeDataToCache(packedValue.newTypes[i]);
+ }
+ for (var aRefID in packedValue.newRefs)
+ {
+ this.createProxy(aRefID, packedValue.newRefs[aRefID]);
+ }
+ if (packedValue.type == FABridge.TYPE_PRIMITIVE)
+ {
+ result = packedValue.value;
+ }
+ else if (packedValue.type == FABridge.TYPE_ASFUNCTION)
+ {
+ result = this.getFunctionProxy(packedValue.value);
+ }
+ else if (packedValue.type == FABridge.TYPE_ASINSTANCE)
+ {
+ result = this.getProxy(packedValue.value);
+ }
+ else if (packedValue.type == FABridge.TYPE_ANONYMOUS)
+ {
+ result = packedValue.value;
+ }
+ }
+ return result;
+ },
+ //increases the reference count for the given object
+ addRef: function(obj)
+ {
+ this.target.incRef(obj.fb_instance_id);
+ },
+ //decrease the reference count for the given object and release it if needed
+ release:function(obj)
+ {
+ this.target.releaseRef(obj.fb_instance_id);
+ },
+
+ // check the given value for the components of the hard-coded error code : __FLASHERROR
+ // used to marshall NPE's into flash
+
+ handleError: function(value)
+ {
+ if (typeof(value)=="string" && value.indexOf("__FLASHERROR")==0)
+ {
+ var myErrorMessage = value.split("||");
+ if(FABridge.refCount > 0 )
+ {
+ FABridge.refCount--;
+ }
+ throw new Error(myErrorMessage[1]);
+ return value;
+ }
+ else
+ {
+ return value;
+ }
+ }
+};
+
+// The root ASProxy class that facades a flash object
+
+ASProxy = function(bridge, typeName)
+{
+ this.bridge = bridge;
+ this.typeName = typeName;
+ return this;
+};
+//methods available on each ASProxy object
+ASProxy.prototype =
+{
+ get: function(propName)
+ {
+ return this.bridge.deserialize(this.bridge.getPropertyFromAS(this.fb_instance_id, propName));
+ },
+
+ set: function(propName, value)
+ {
+ this.bridge.setPropertyInAS(this.fb_instance_id, propName, value);
+ },
+
+ call: function(funcName, args)
+ {
+ this.bridge.callASMethod(this.fb_instance_id, funcName, args);
+ },
+
+ addRef: function() {
+ this.bridge.addRef(this);
+ },
+
+ release: function() {
+ this.bridge.release(this);
+ }
+};
View
109 public/socket.io/lib/vendor/web-socket-js/README.txt
@@ -0,0 +1,109 @@
+* How to try
+
+Assuming you have Web server (e.g. Apache) running at http://example.com/ .
+
+- Download web_socket.rb from:
+ http://github.com/gimite/web-socket-ruby/tree/master
+- Run sample Web Socket server (echo server) in example.com with: (#1)
+ $ ruby web-socket-ruby/samples/echo_server.rb example.com 10081
+- If your server already provides socket policy file at port 843, modify the file to allow access to port 10081. Otherwise you can skip this step. See below for details.
+- Publish the web-socket-js directory with your Web server (e.g. put it in ~/public_html).
+- Change ws://localhost:10081 to ws://example.com:10081 in sample.html.
+- Open sample.html in your browser.
+- After "onopen" is shown, input something, click [Send] and confirm echo back.
+
+#1: First argument of echo_server.rb means that it accepts Web Socket connection from HTML pages in example.com.
+
+
+* Troubleshooting
+
+If it doesn't work, try these:
+
+1. Try Chrome and Firefox 3.x.
+- It doesn't work on Chrome:
+-- It's likely an issue of your code or the server. Debug your code as usual e.g. using console.log.
+- It works on Chrome but it doesn't work on Firefox:
+-- It's likely an issue of web-socket-js specific configuration (e.g. 3 and 4 below).
+- It works on both Chrome and Firefox, but it doesn't work on your browser:
+-- Check "Supported environment" section below. Your browser may not be supported by web-socket-js.
+
+2. Add this line before your code:
+ WEB_SOCKET_DEBUG = true;
+and use Developer Tools (Chrome/Safari) or Firebug (Firefox) to see if console.log outputs any errors.
+
+3. Make sure you do NOT open your HTML page as local file e.g. file:///.../sample.html. web-socket-js doesn't work on local file. Open it via Web server e.g. http:///.../sample.html.
+
+4. If you are NOT using web-socket-ruby as your WebSocket server, you need to place Flash socket policy file on your server. See "Flash socket policy file" section below for details.
+
+5. Check if sample.html bundled with web-socket-js works.
+
+6. Make sure the port used for WebSocket (10081 in example above) is not blocked by your server/client's firewall.
+
+7. Install debugger version of Flash Player available here to see Flash errors:
+http://www.adobe.com/support/flashplayer/downloads.html
+
+
+* Supported environments
+
+It should work on:
+- Google Chrome 4 or later (just uses native implementation)
+- Firefox 3.x, Internet Explorer 8 + Flash Player 9 or later
+
+It may or may not work on other browsers such as Safari, Opera or IE 6. Patch for these browsers are appreciated, but I will not work on fixing issues specific to these browsers by myself.
+
+
+* Flash socket policy file
+
+This implementation uses Flash's socket, which means that your server must provide Flash socket policy file to declare the server accepts connections from Flash.
+
+If you use web-socket-ruby available at
+http://github.com/gimite/web-socket-ruby/tree/master
+, you don't need anything special, because web-socket-ruby handles Flash socket policy file request. But if you already provide socket policy file at port 843, you need to modify the file to allow access to Web Socket port, because it precedes what web-socket-ruby provides.
+
+If you use other Web Socket server implementation, you need to provide socket policy file yourself. See
+http://www.lightsphere.com/dev/articles/flash_socket_policy.html
+for details and sample script to run socket policy file server. node.js implementation is available here:
+http://github.com/LearnBoost/Socket.IO-node/blob/master/lib/socket.io/transports/flashsocket.js
+
+Actually, it's still better to provide socket policy file at port 843 even if you use web-socket-ruby. Flash always try to connect to port 843 first, so providing the file at port 843 makes startup faster.
+
+
+* Cookie considerations
+
+Cookie is sent if Web Socket host is the same as the origin of JavaScript. Otherwise it is not sent, because I don't know way to send right Cookie (which is Cookie of the host of Web Socket, I heard).
+
+Note that it's technically possible that client sends arbitrary string as Cookie and any other headers (by modifying this library for example) once you place Flash socket policy file in your server. So don't trust Cookie and other headers if you allow connection from untrusted origin.
+
+
+* Proxy considerations
+
+The WebSocket spec (http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol) specifies instructions for User Agents to support proxied connections by implementing the HTTP CONNECT method.
+
+The AS3 Socket class doesn't implement this mechanism, which renders it useless for the scenarios where the user trying to open a socket is behind a proxy.
+
+The class RFC2817Socket (by Christian Cantrell) effectively lets us implement this, as long as the proxy settings are known and provided by the interface that instantiates the WebSocket. As such, if you want to support proxied conncetions, you'll have to supply this information to the WebSocket constructor when Flash is being used. One way to go about it would be to ask the user for proxy settings information if the initial connection fails.
+
+
+* How to host HTML file and SWF file in different domains
+
+By default, HTML file and SWF file must be in the same domain. You can follow steps below to allow hosting them in different domain.
+
+WARNING: If you use the method below, HTML files in ANY domains can send arbitrary TCP data to your WebSocket server, regardless of configuration in Flash socket policy file. Arbitrary TCP data means that they can even fake request headers including Origin and Cookie.
+
+- Unzip WebSocketMainInsecure.zip to extract WebSocketMainInsecure.swf.
+- Put WebSocketMainInsecure.swf on your server, instead of WebSocketMain.swf.
+- In JavaScript, set WEB_SOCKET_SWF_LOCATION to URL of your WebSocketMainInsecure.swf.
+
+
+* How to build WebSocketMain.swf
+
+Install Flex 4 SDK:
+http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+4