-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
47 lines (40 loc) · 996 Bytes
/
app.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
require "eventmachine"
require "em-synchrony"
require "faye/websocket"
require "sinatra"
require "common"
require "server/websocket_server_connection"
module Rack
class Lint
def call(env = nil)
@app.call(env)
end
end
end
DEBUG = ENV["DEBUGXX"]&.downcase == "true"
get "/" do
send_file File.join(settings.public_folder, "index.html")
end
get "/cable" do
404 unless Faye::WebSocket.websocket?(env)
c = WebsocketServerConnection.new(env)
c.ws.rack_response
end
get "/reset" do
$connections.each do |conn|
dbg ["SERVER", "Calling conn.close", conn]
conn.close
end
$connections = []
if EM.reactor_running?
dbg ["SERVER", "the EM reactor is running, so we will stop it"]
EM.stop
max_iterations = 30
while EM.reactor_running? && max_iterations > 0
dbg ["SERVER", "Waiting for EM reactor to stop"]
sleep 0.1
max_iterations = max_iterations - 1
end
raise "reactor is stil running" if EM.reactor_running?
end
end