websocket secure params in app_config

This commit is contained in:
zhitomirskiyi 2010-11-15 17:44:10 -08:00
parent de1fed70f0
commit c5ae73f96d
3 changed files with 22 additions and 6 deletions

View file

@ -8,9 +8,9 @@
$(document).ready(function(){ $(document).ready(function(){
function debug(str){ $("#debug").append("<p>" + str); }; function debug(str){ $("#debug").append("<p>" + str); };
ws = new WebSocket("ws://#{request.host}:#{APP_CONFIG[:socket_port]}/"); ws = new WebSocket("#{(APP_CONFIG[:socket_secure])?'wss':'ws'}://#{request.host}:#{APP_CONFIG[:socket_port]}/");
//Attach onmessage to websocket //Attach onmessage to websocket
ws.onmessage = function(evt) { ws.onmessage = function(evt) {
var obj = jQuery.parseJSON(evt.data); var obj = jQuery.parseJSON(evt.data);

View file

@ -28,6 +28,12 @@ default:
socket_port: 8080 socket_port: 8080
socket_collection_name: 'websocket' socket_collection_name: 'websocket'
# Secure websocket confguration (wss://)
# requires SSL cert and key
socket_secure: false
socket_private_key_location: '/full/path/to/file.key'
socket_cert_chain_location: '/full/path/to/cert_chain.crt'
# Diaspora is only tested against this default pubsub server. # Diaspora is only tested against this default pubsub server.
pubsub_server: 'https://pubsubhubbub.appspot.com/' pubsub_server: 'https://pubsubhubbub.appspot.com/'

View file

@ -45,10 +45,20 @@ begin
EM.run { EM.run {
Diaspora::WebSocket.initialize_channels Diaspora::WebSocket.initialize_channels
EventMachine::WebSocket.start( socket_params = { :host => APP_CONFIG[:socket_host],
:host => APP_CONFIG[:socket_host], :port => APP_CONFIG[:socket_port],
:port => APP_CONFIG[:socket_port], :debug =>APP_CONFIG[:socket_debug] }
:debug =>APP_CONFIG[:socket_debug]) do |ws|
if APP_CONFIG[:socket_secure] && APP_CONFIG[:socket_private_key_location] && APP_CONFIG[:socket_cert_chain_location]
socket_params[:secure] = true;
socket_params[:tls_options] = {
:private_key_file => APP_CONFIG[:socket_private_key_location],
:cert_chain_file => APP_CONFIG[:socket_cert_chain_location]
}
end
EventMachine::WebSocket.start( socket_params ) do |ws|
ws.onopen { ws.onopen {
begin begin
debug_pp ws.request debug_pp ws.request