From ef2e393ac8a898610b80c0fba4842bc1f7bee5fc Mon Sep 17 00:00:00 2001 From: Michael Nutt Date: Thu, 16 Sep 2010 02:32:16 -0400 Subject: [PATCH 1/3] Add bin directory to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 89b33da60..bf8a0e240 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ gpg/diaspora-production/*.gpg gpg/*/random_seed public/uploads/* .rvmrc +/bin From 46a83324ab63b67fa3f85fcefa705aef9ab1b77b Mon Sep 17 00:00:00 2001 From: Michael Nutt Date: Thu, 16 Sep 2010 02:34:11 -0400 Subject: [PATCH 2/3] Warn if can't attach to websocket port --- config/initializers/socket.rb | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/config/initializers/socket.rb b/config/initializers/socket.rb index 1fd09fd93..a806e2553 100644 --- a/config/initializers/socket.rb +++ b/config/initializers/socket.rb @@ -9,18 +9,26 @@ 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 { + begin + 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) + sid = Diaspora::WebSocket.subscribe(ws.request['Path'].gsub('/',''), ws) - ws.onmessage { |msg| SocketsController.new.incoming(msg) } + ws.onmessage { |msg| SocketsController.new.incoming(msg) } - ws.onclose { Diaspora::WebSocket.unsubscribe(ws.request['Path'].gsub('/',''), sid) } - } + ws.onclose { Diaspora::WebSocket.unsubscribe(ws.request['Path'].gsub('/',''), sid) } + } + end + rescue RuntimeError => e + if e.message =~ /no acceptor/ + raise RuntimeError, "Could not listen on port #{APP_CONFIG[:socket_port]}, perhaps another process is already using it?" + else + raise + end end } From aa6b2425638ccbf2884df53f2674b69833d73d0a Mon Sep 17 00:00:00 2001 From: Michael Nutt Date: Thu, 16 Sep 2010 03:07:39 -0400 Subject: [PATCH 3/3] websocket js should honor app socket port configuration --- app/views/js/_websocket_js.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/js/_websocket_js.haml b/app/views/js/_websocket_js.haml index 483621625..33af68cce 100644 --- a/app/views/js/_websocket_js.haml +++ b/app/views/js/_websocket_js.haml @@ -9,7 +9,7 @@ $(document).ready(function(){ function debug(str){ $("#debug").append("

" + str); }; - ws = new WebSocket("ws://#{request.host}:8080/#{CGI::escape(current_user.id.to_s)}"); + ws = new WebSocket("ws://#{request.host}:#{APP_CONFIG[:socket_port]}/#{CGI::escape(current_user.id.to_s)}"); //Attach onmessage to websocket ws.onmessage = function(evt) {