diaspora/config/initializers/socket.rb
2010-09-15 17:56:18 -07:00

26 lines
780 B
Ruby

# Copyright (c) 2010, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3. See
# the COPYRIGHT file.
require 'em-websocket'
require 'eventmachine'
require "lib/diaspora/websocket"
EM.next_tick {
Diaspora::WebSocket.initialize_channels
EventMachine::WebSocket.start(
:host => "0.0.0.0",
:port => APP_CONFIG[:socket_port],
:debug =>APP_CONFIG[:socket_debug]) do |ws|
ws.onopen {
sid = Diaspora::WebSocket.subscribe(ws.request['Path'].gsub('/',''), ws)
ws.onmessage { |msg| SocketsController.new.incoming(msg) }
ws.onclose { Diaspora::WebSocket.unsubscribe(ws.request['Path'].gsub('/',''), sid) }
}
end
}