Class: Orator::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/orator/server.rb

Overview

Handles the server connections and passing stuff to the event handler.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ void

Initialize the server.



25
26
27
28
# File 'lib/orator/server.rb', line 25

def initialize(options)
  @options = options
  @clients = Set.new
end

Instance Attribute Details

#clientsSet<Client> (readonly)

The list of clients that are connected.

Returns:



14
15
16
# File 'lib/orator/server.rb', line 14

def clients
  @clients
end

#event_handlerEventHandler (readonly)

The event handler that is duplicated for every client. This is to reduce the overhead of reinitializing the event handler for every client.

Returns:



20
21
22
# File 'lib/orator/server.rb', line 20

def event_handler
  @event_handler
end

#optionsHash (readonly)

The options defined for the server.

Returns:

  • (Hash)


9
10
11
# File 'lib/orator/server.rb', line 9

def options
  @options
end

Instance Method Details

#run(&block) ⇒ Object

Runs the server with the given options.



31
32
33
34
# File 'lib/orator/server.rb', line 31

def run(&block)
  @event_handler = EventHandler.new(&block)
  EM::WebSocket.start(@options, &method(:handle_socket))
end