-
-
Save imanel/a00d6b65561ebba43b9a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Socket < Rack::WebSocket::Application | |
def self.connections | |
@connections ||= [] | |
end | |
def self.send_to_all(message) | |
@connections.each {|connection| connection.send_data(message) | |
end | |
def on_open(env) | |
self.class.connections << self | |
end | |
def on_close(env) | |
self.class.connection.delete(self) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment