Websocket now uses cookie to authenticate
This commit is contained in:
parent
153265aae8
commit
ae039442c3
3 changed files with 8 additions and 4 deletions
|
|
@ -8,7 +8,7 @@
|
|||
$(document).ready(function(){
|
||||
function debug(str){ $("#debug").append("<p>" + 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) {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
|
|
|||
Loading…
Reference in a new issue