Class: SimplePusher::Server
- Inherits:
-
Object
- Object
- SimplePusher::Server
- Includes:
- Singleton
- Defined in:
- lib/simple_pusher/server.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Server
constructor
A new instance of Server.
Constructor Details
#initialize ⇒ Server
Returns a new instance of Server.
10 11 12 13 |
# File 'lib/simple_pusher/server.rb', line 10 def initialize @host = '0.0.0.0' @port = SimplePusher.configuration.port end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
8 9 10 |
# File 'lib/simple_pusher/server.rb', line 8 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
8 9 10 |
# File 'lib/simple_pusher/server.rb', line 8 def port @port end |
Class Method Details
.start ⇒ Object
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 |
# File 'lib/simple_pusher/server.rb', line 15 def self.start $stderr.puts 'Start SimplePusher ...' if SimplePusher.configuration.debug EM::WebSocket.run(host: instance.host, port: instance.port) do |socket| socket.onopen do |handshake| $stderr.puts 'on open:' + handshake.inspect if SimplePusher.configuration.debug Connection.add_client(socket) end socket.onclose do $stderr.puts 'on close' Connection.remove_client(socket) end socket. do || $stderr.puts 'on message: ' + if SimplePusher.configuration.debug action, * = .split(':') case action when 'broadcast' = .join(':') Connection.broadcast() when 'emit' event = [0] Connection.trigger(event) else # TODO end end end end |