diff --git a/app/views/js/_websocket_js.haml b/app/views/js/_websocket_js.haml index ec9854bb6..33fb0e971 100644 --- a/app/views/js/_websocket_js.haml +++ b/app/views/js/_websocket_js.haml @@ -8,7 +8,7 @@ $(document).ready(function(){ function debug(str){ $("#debug").append("

" + str); }; - ws = new WebSocket("ws://#{request.host}:#{APP_CONFIG[:socket_port]}/#{CGI::escape(current_user.id.to_s)}"); + ws = new WebSocket("ws://#{request.host}:#{APP_CONFIG[:socket_port]}/"); //Attach onmessage to websocket ws.onmessage = function(evt) { diff --git a/lib/diaspora/websocket.rb b/lib/diaspora/websocket.rb index 09c553e20..2fec38d39 100644 --- a/lib/diaspora/websocket.rb +++ b/lib/diaspora/websocket.rb @@ -15,7 +15,7 @@ module Diaspora def self.push_to_user(uid, data) Rails.logger.debug "Websocketing to #{uid}" - @channels[uid.to_s][0].push(data) if @channels[uid.to_s] + @channels[uid][0].push(data) if @channels[uid] end def self.subscribe(uid, ws) diff --git a/script/websocket_server.rb b/script/websocket_server.rb index 3b458118b..cc788e734 100644 --- a/script/websocket_server.rb +++ b/script/websocket_server.rb @@ -48,11 +48,15 @@ begin :debug =>APP_CONFIG[:socket_debug]) do |ws| ws.onopen { - sid = Diaspora::WebSocket.subscribe(ws.request['Path'].gsub('/',''), ws) + encoded_cookie = ws.request["Cookie"].gsub("_diaspora_session=","") + cookie = Marshal.load(encoded_cookie.unpack("m*").first) + user_id = cookie["warden.user.user.key"].last + + sid = Diaspora::WebSocket.subscribe(user_id, ws) ws.onmessage { |msg| SocketsController.new.incoming(msg) } - ws.onclose { Diaspora::WebSocket.unsubscribe(ws.request['Path'].gsub('/',''), sid) } + ws.onclose { Diaspora::WebSocket.unsubscribe(user_id, sid) } } end PID_FILE = APP_CONFIG[:socket_pidfile]