diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index c785e5d03..4b2ab3880 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -19,12 +19,29 @@ WebSocket.__swfLocation = "/javascripts/WebSocketMain.swf"; - = javascript_include_tag 'socket' if user_signed_in? = csrf_meta_tag = yield(:head) + - if user_signed_in? + :javascript + $(document).ready(function(){ + function debug(str){ $("#debug").append("
" + str); }; + + ws = new WebSocket("ws://#{request.host}:8080/"); + ws.onmessage = function(evt) { + $("#stream").prepend($(evt.data).fadeIn("fast")); + }; + ws.onclose = function() { debug("socket closed"); }; + ws.onopen = function() { + debug("connected..."); + //ws.send("hello server"); + // ws.send("hello again"); + }; + }); + :javascript $(document).ready(function(){ + $('a').hover(function(){ $(this).fadeTo(60, 0.5); }, function(){ diff --git a/public/javascripts/socket.js b/public/javascripts/socket.js index 6f66507f3..7db6c9130 100644 --- a/public/javascripts/socket.js +++ b/public/javascripts/socket.js @@ -1,4 +1,4 @@ - $(document).ready(function(){ +$(document).ready(function(){ function debug(str){ $("#debug").append("
" + str); }; ws = new WebSocket("ws://localhost:8080/");