Permalink
Browse files

Merge branch 'ping'

* ping:
  meep
  my ping example, poorly named
  • Loading branch information...
2 parents 764ad1d + 7384356 commit c577e97951b673eeeb6e2c1e938d3dedf8c6ca00 @CodeOfficer committed Feb 26, 2010
Showing with 18,785 additions and 0 deletions.
  1. +65 −0 experiments/ping/application.js
  2. +402 −0 experiments/ping/lib/redis.js
  3. +68 −0 experiments/ping/log.js
  4. +8 −0 experiments/ping/modules/_default.js
  5. +156 −0 experiments/ping/modules/chat.js
  6. +8 −0 experiments/ping/modules/echo.js
  7. +58 −0 experiments/ping/modules/ping.js
  8. +21 −0 experiments/ping/modules/processes.js
  9. +14 −0 experiments/ping/modules/time.js
  10. +56 −0 experiments/ping/ping.html
  11. +4 −0 experiments/ping/runserver.js
  12. +41 −0 experiments/ping/tools.js
  13. +236 −0 experiments/ping/websocket.js
  14. +89 −0 vendor/application.css
  15. BIN vendor/base/images/ui-anim_basic_16x16.gif
  16. BIN vendor/base/images/ui-bg_flat_0_aaaaaa_40x100.png
  17. BIN vendor/base/images/ui-bg_flat_75_ffffff_40x100.png
  18. BIN vendor/base/images/ui-bg_glass_55_fbf9ee_1x400.png
  19. BIN vendor/base/images/ui-bg_glass_65_ffffff_1x400.png
  20. BIN vendor/base/images/ui-bg_glass_75_dadada_1x400.png
  21. BIN vendor/base/images/ui-bg_glass_75_e6e6e6_1x400.png
  22. BIN vendor/base/images/ui-bg_glass_95_fef1ec_1x400.png
  23. BIN vendor/base/images/ui-bg_highlight-soft_75_cccccc_1x100.png
  24. BIN vendor/base/images/ui-icons_222222_256x240.png
  25. BIN vendor/base/images/ui-icons_2e83ff_256x240.png
  26. BIN vendor/base/images/ui-icons_454545_256x240.png
  27. BIN vendor/base/images/ui-icons_888888_256x240.png
  28. BIN vendor/base/images/ui-icons_cd0a0a_256x240.png
  29. +477 −0 vendor/base/jquery-ui.css
  30. 0 vendor/base/jquery-ui.sass
  31. +6,240 −0 vendor/jquery-1.4.2.js
  32. +10,691 −0 vendor/jquery-ui.js
  33. +151 −0 vendor/jquery.rails.js
@@ -0,0 +1,65 @@
+// https://developer.mozilla.org/en/Canvas_tutorial
+
+var NodeSocket = {
+ ws: null,
+ windowClosing: false,
+ connect: function() {
+ console.log('trying to connect ...');
+ NodeSocket.ws = new WebSocket("ws://localhost:8080/ping");
+ NodeSocket.ws.onmessage = NodeSocket.onmessage;
+ NodeSocket.ws.onclose = NodeSocket.onclose;
+ NodeSocket.ws.onopen = NodeSocket.onopen;
+ },
+ onmessage: function(e) {
+ var jsonData = JSON.parse(e.data);
+ var action = jsonData[0];
+ var data = jsonData[1];
+ if (NodeSocket.handlers[action]) {
+ NodeSocket.handlers[action](data);
+ } else {
+ console.log('handler not found');
+ };
+ },
+ onclose: function() {
+ if (!NodeSocket.windowClosing) {
+ NodeSocket.ws.send('STOP');
+ console.log('connection terminating?', NodeSocket.windowClosing);
+ };
+ },
+ onopen: function() {
+ NodeSocket.ws.send('START');
+ console.log('Connected...');
+ },
+ ping: function(data) {
+ var jsonData = JSON.stringify(data);
+ if (NodeSocket.ws) {
+ NodeSocket.ws.send(jsonData);
+ } else {
+ console.log('trying to send, but not connected');
+ };
+ }
+
+};
+
+NodeSocket.handlers = {
+ pong: function(data) {
+ $("#mark").stop(true, true).animate({"left": data.pageX, "top": data.pageY}, "fast");
+ }
+};
+
+;(function($) {
+ $(function() {
+
+ NodeSocket.connect();
+
+ $('body').click(function(e) {
+ NodeSocket.ping(['pong', { pageX: e.pageX, pageY: e.pageY} ]);
+ });
+
+ $('window').unload(function () {
+ if (NodeSocket.ws) NodeSocket.ws.close();
+ NodeSocket.windowClosing = true;
+ });
+
+ });
+})(jQuery);
Oops, something went wrong.

0 comments on commit c577e97

Please sign in to comment.