Skip to content

Commit

Permalink
Added ssl support
Browse files Browse the repository at this point in the history
  • Loading branch information
mallio committed Jan 30, 2009
1 parent 5b704e7 commit 714c034
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
11 changes: 8 additions & 3 deletions generators/orbited_config/templates/orbited.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ session.ping_timeout = 30

[listen]
http://:<%= config[:port] %>
<% if config[:morbidq] == 1 -%>stomp://:<%= config[:stomp_port] %><% end %>
<% if config[:morbidq] == 1 -%>stomp://:<%= config[:stomp_port] %><% end -%>
<% if config[:ssl_enabled] == 1 -%>https://:<%= config[:ssl_port] %><% end -%>

[access]
<%= config[:restrict_access] == 1 ? "#{config[:host]}:#{config[:port]}" : "*" %> -> <%= config[:stomp_host] %>:<%= config[:stomp_port] %>

<%= config[:restrict_access] == 1 ? "#{config[:host]}:#{config[:port]}" : "*" %> -> <%= config[:stomp_host] %>:<%= config[:stomp_port] -%>

<% if config[:ssl_enabled] == 1 -%>
[ssl]
key=<%= config[:ssl_key] %>
crt=<%= config[:ssl_crt] %>
<% end -%>
24 changes: 20 additions & 4 deletions lib/orbited.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ class Orbited
# Sends data in string form to the STOMP server, which sends it to anyone subscribed to
# the specified channel
def self.send_data(channel, data, headers = {})
user = OrbitedConfig.stomp_user || ''
password = OrbitedConfig.stomp_password || ''
host = OrbitedConfig.stomp_host || 'localhost'
port = OrbitedConfig.stomp_port || 61613
set_defaults
use_ssl = headers.delete(:use_ssl) || false
user = OrbitedConfig.stomp_user
password = OrbitedConfig.stomp_password
host = use_ssl ? OrbitedConfig.ssl_stomp_host : OrbitedConfig.stomp_host
port = use_ssl ? OrbitedConfig.ssl_stomp_port : OrbitedConfig.stomp_port
reliable = false
s = Stomp::Client.new(user, password, host, port, reliable)
s.send("/topic/#{channel}", data, headers)
Expand All @@ -17,4 +19,18 @@ def self.send_data(channel, data, headers = {})
RAILS_DEFAULT_LOGGER.error "!!! The Orbited server appears to be down!"
end

private
def self.set_defaults
OrbitedConfig.host ||= 'localhost'
OrbitedConfig.port ||= 8000
OrbitedConfig.ssl_host ||= OrbitedConfig.host
OrbitedConfig.ssl_port ||= OrbitedConfig.port
OrbitedConfig.stomp_host ||= OrbitedConfig.host
OrbitedConfig.stomp_port ||= 61613
OrbitedConfig.stomp_user ||= ''
OrbitedConfig.stomp_password ||= ''
OrbitedConfig.ssl_stomp_host ||= OrbitedConfig.stomp_host
OrbitedConfig.ssl_stomp_port ||= OrbitedConfig.stomp_port
end

end
12 changes: 8 additions & 4 deletions lib/orbited_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,18 @@ def stomp_connect(channels, options = {})
end
user = options[:user] || OrbitedConfig.stomp_user || ''
password = options[:password] || OrbitedConfig.stomp_password || ''
js += "stomp.connect('#{OrbitedConfig.stomp_host}', #{OrbitedConfig.stomp_port}, '#{user}', '#{password}');"
host = request.ssl? ? OrbitedConfig.ssl_stomp_host : OrbitedConfig.stomp_host
port = request.ssl? ? OrbitedConfig.ssl_stomp_port : OrbitedConfig.stomp_port
js += "stomp.connect('#{host}', #{port}, '#{user}', '#{password}');"
js += "});"
javascript_tag js
end

private
def orbited_server_url
"http://#{OrbitedConfig.host}:#{OrbitedConfig.port}"
request.ssl? ?
"https://#{OrbitedConfig.ssl_host}:#{OrbitedConfig.ssl_port}" :
"http://#{OrbitedConfig.host}:#{OrbitedConfig.port}"
end

def orbited_js
Expand All @@ -46,8 +50,8 @@ def protocol_js

def initialize_js
<<-EOS
Orbited.settings.hostname = '#{OrbitedConfig.host}';
Orbited.settings.port = '#{OrbitedConfig.port}';
Orbited.settings.hostname = '#{request.ssl? ? OrbitedConfig.ssl_host : OrbitedConfig.host}';
Orbited.settings.port = '#{request.ssl? ? OrbitedConfig.ssl_port : OrbitedConfig.port}';
Orbited.settings.streaming = true;
TCPSocket = Orbited.TCPSocket;
EOS
Expand Down

0 comments on commit 714c034

Please sign in to comment.