on client connect, websockets now tell the server where the user is. nothing more

This commit is contained in:
maxwell 2010-06-28 01:12:21 -07:00
parent b017f1b0f9
commit 60091012bf
2 changed files with 19 additions and 9 deletions

View file

@ -34,11 +34,12 @@
if((location.href.indexOf(obj['class']) != -1 ) || (location.pathname == '/')) { if((location.href.indexOf(obj['class']) != -1 ) || (location.pathname == '/')) {
$("#stream").prepend($(obj['html']).fadeIn("fast")); $("#stream").prepend($(obj['html']).fadeIn("fast"));
}; };
} }
ws.onclose = function() { debug("socket closed"); }; ws.onclose = function() { debug("socket closed"); };
ws.onopen = function() { ws.onopen = function() {
debug("connected..."); ws.send(location.pathname);
}; debug("connected...");
};
}); });
%body %body

View file

@ -13,11 +13,12 @@ module WebSocket
end end
end end
EventMachine::WebSocket.start(:host => "0.0.0.0", :port => 8080, :debug => true) do |ws| EventMachine::WebSocket.start(:host => "0.0.0.0", :port => 8080, :debug =>false) do |ws|
ws.onopen { ws.onopen {
sid = @channel.subscribe { |msg| ws.send msg } sid = @channel.subscribe { |msg| ws.send msg }
ws.onmessage { |msg| @channel.push msg} ws.onmessage { |msg| @channel.push msg; puts msg}
ws.onclose { @channel.unsubscribe(sid) } ws.onclose { @channel.unsubscribe(sid) }
} }
@ -29,10 +30,18 @@ module WebSocket
end end
def self.view_hash(object) def self.view_hash(object)
{:class =>object.class.to_s.underscore.pluralize, :html => WebSocket.view_for(object)} #begin
# puts "I be working hard"
v = WebSocket.view_for(object)
#puts view.inspect
#rescue
# puts "in failzord " + view.inspect
# raise "i suck"
#end
{:class =>object.class.to_s.underscore.pluralize, :html => v}
end end
def self.view_for(object) def self.view_for(object)
@view.render(:partial => @view.type_partial(object), :locals => {:post => object}) @view.render @view.type_partial(object), :post => object
end end
end end