diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..198e411 --- /dev/null +++ b/Gemfile @@ -0,0 +1,4 @@ +source 'https://www.rubygems.org' + +gem 'sinatra-websocket', path: File.expand_path("../", __FILE__) +gem 'sinatra' diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..230411e --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,39 @@ +PATH + remote: . + specs: + sinatra-websocket (0.3.1) + em-websocket (~> 0.3.6) + eventmachine + thin (>= 1.3.1, < 2.0.0) + +GEM + remote: https://www.rubygems.org/ + specs: + addressable (2.3.8) + daemons (1.2.3) + em-websocket (0.3.8) + addressable (>= 2.1.1) + eventmachine (>= 0.12.9) + eventmachine (1.0.8) + rack (1.6.4) + rack-protection (1.5.3) + rack + sinatra (1.4.6) + rack (~> 1.4) + rack-protection (~> 1.4) + tilt (>= 1.3, < 3) + thin (1.6.4) + daemons (~> 1.0, >= 1.0.9) + eventmachine (~> 1.0, >= 1.0.4) + rack (~> 1.0) + tilt (2.0.1) + +PLATFORMS + ruby + +DEPENDENCIES + sinatra + sinatra-websocket! + +BUNDLED WITH + 1.10.6 diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..58361e4 --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +web: bundle exec thin start -p $PORT diff --git a/config.ru b/config.ru new file mode 100644 index 0000000..f03f3ef --- /dev/null +++ b/config.ru @@ -0,0 +1,4 @@ +require 'rubygems' +require_relative 'examples/echochat' + +run Sinatra::Application diff --git a/examples/echochat.rb b/examples/echochat.rb index ccfa3f2..05ec932 100755 --- a/examples/echochat.rb +++ b/examples/echochat.rb @@ -46,7 +46,8 @@ return function(msg){ el.innerHTML = msg + '
' + el.innerHTML; } }(document.getElementById('msgs')); - var ws = new WebSocket('ws://' + window.location.host + window.location.pathname); + var proto = location.protocol === 'https:' ? 'wss' : 'ws' + var ws = new WebSocket(proto + '://' + window.location.host + window.location.pathname); ws.onopen = function() { show('websocket opened'); }; ws.onclose = function() { show('websocket closed'); } ws.onmessage = function(m) { show('websocket message: ' + m.data); };