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
@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.
@ws.onopen = =>

View file

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