Added ssl support for web sockets.

This commit is contained in:
Martin Edenhofer 2012-08-02 11:30:30 +02:00
parent 0e938ffb2e
commit 4e67df9573
2 changed files with 9 additions and 7 deletions

View file

@ -57,7 +57,11 @@ class _Singleton extends Spine.Controller
) )
return return
@ws = new window.WebSocket( "ws://" + window.location.hostname + ":6042/" ) protocol = 'ws://'
if window.location.protocol is 'https:'
protocol = 'wss://'
@ws = new window.WebSocket( protocol + window.location.hostname + ":6042/" )
# Set event handlers. # Set event handlers.
@ws.onopen = => @ws.onopen = =>

View file

@ -15,6 +15,7 @@ options = {
:k => '/path/to/server.key', :k => '/path/to/server.key',
:c => '/path/to/server.crt', :c => '/path/to/server.crt',
} }
tls_options = {}
OptionParser.new do |opts| OptionParser.new do |opts|
opts.banner = "Usage: websocket-server.rb [options]" opts.banner = "Usage: websocket-server.rb [options]"
@ -28,10 +29,10 @@ OptionParser.new do |opts|
options[:s] = s options[:s] = s
end end
opts.on("-k", "--private-key [OPT]", "/path/to/server.key for secure connections") do |k| opts.on("-k", "--private-key [OPT]", "/path/to/server.key for secure connections") do |k|
options[:k] = k tls_options[:private_key_file] = k
end end
opts.on("-c", "--certificate [OPT]", "/path/to/server.crt for secure connections") do |c| opts.on("-c", "--certificate [OPT]", "/path/to/server.crt for secure connections") do |c|
options[:c] = c tls_options[:cert_chain_file] = c
end end
end.parse! end.parse!
@ -40,10 +41,7 @@ puts "Starting websocket server on #{ options[:b] }:#{ options[:p] } (secure:#{
@clients = {} @clients = {}
EventMachine.run { EventMachine.run {
EventMachine::WebSocket.start( :host => options[:b], :port => options[:p], :secure => options[:s], :tls_options => { EventMachine::WebSocket.start( :host => options[:b], :port => options[:p], :secure => options[:s], :tls_options => tls_options ) do |ws|
:private_key_file => options[:p],
:cert_chain_file => options[:c],
}) do |ws|
# register client connection # register client connection
ws.onopen { ws.onopen {