Class: EventdServer
- Inherits:
-
EventdObject
- Object
- EventdObject
- EventdServer
- Defined in:
- lib/eventd/eventd_server.rb
Instance Attribute Summary collapse
-
#allowed_broadcast_channels ⇒ Object
List of allowed broadcast channels.
-
#broadcasts_restricted ⇒ Object
Broadcast restriction.
-
#clients ⇒ Object
List of active clients on the server.
-
#options ⇒ Object
Configuration options for em-websocket and the EventdServer.
-
#run_callback ⇒ Object
Callback block which is called when the server starts for threading purposed.
Attributes inherited from EventdObject
Instance Method Summary collapse
-
#add_allowed_broadcast(channel) ⇒ Object
Add an allowed broadcast channel.
-
#allow_broadcasts ⇒ Object
Allow any broadcast.
-
#broadcast_channel_allowed?(channel) ⇒ Boolean
Check if a specific broadcast channel is allowed.
-
#broadcast_channel_restricted?(channel) ⇒ Boolean
Check if a specific broadcast channel is restricted.
-
#broadcasts_allowed? ⇒ Boolean
Check if broadcasts are allowed.
-
#broadcasts_restricted? ⇒ Boolean
Check if broadcasts are restricted.
-
#configure(options) ⇒ Object
Add to the EventdServer configuration.
-
#initialize(options = { :host => '127.0.0.1', :port => 8080 }) ⇒ EventdServer
constructor
Initialize the EventdServer with configuration options.
-
#plugin(&callback) ⇒ Object
Allows you to extend the functionality of a server, through a plugin.
-
#remove_allowed_broadcast(channel) ⇒ Object
Remove an allowed broadcast channel.
-
#restrict_broadcasts ⇒ Object
Restrict broadcasts.
-
#run(&callback) ⇒ Object
Special event listener which is triggered when the server runs.
-
#start ⇒ Object
Start the server.
Methods inherited from EventdObject
Constructor Details
#initialize(options = { :host => '127.0.0.1', :port => 8080 }) ⇒ EventdServer
Initialize the EventdServer with configuration options
Attributes
-
options
- Configuration hash which will be used as the initial EventdServer configuration
38 39 40 41 42 43 44 45 |
# File 'lib/eventd/eventd_server.rb', line 38 def initialize( = { :host => '127.0.0.1', :port => 8080 }) super() @options = @clients = [] @broadcasts_restricted = false @allowed_broadcast_channels = [] end |
Instance Attribute Details
#allowed_broadcast_channels ⇒ Object
List of allowed broadcast channels
28 29 30 |
# File 'lib/eventd/eventd_server.rb', line 28 def allowed_broadcast_channels @allowed_broadcast_channels end |
#broadcasts_restricted ⇒ Object
Broadcast restriction
31 32 33 |
# File 'lib/eventd/eventd_server.rb', line 31 def broadcasts_restricted @broadcasts_restricted end |
#clients ⇒ Object
List of active clients on the server
25 26 27 |
# File 'lib/eventd/eventd_server.rb', line 25 def clients @clients end |
#options ⇒ Object
Configuration options for em-websocket and the EventdServer
19 20 21 |
# File 'lib/eventd/eventd_server.rb', line 19 def @options end |
#run_callback ⇒ Object
Callback block which is called when the server starts for threading purposed
22 23 24 |
# File 'lib/eventd/eventd_server.rb', line 22 def run_callback @run_callback end |
Instance Method Details
#add_allowed_broadcast(channel) ⇒ Object
Add an allowed broadcast channel
98 99 100 |
# File 'lib/eventd/eventd_server.rb', line 98 def add_allowed_broadcast(channel) @allowed_broadcast_channels.push channel end |
#allow_broadcasts ⇒ Object
Allow any broadcast
86 87 88 |
# File 'lib/eventd/eventd_server.rb', line 86 def allow_broadcasts @broadcasts_restricted = false end |
#broadcast_channel_allowed?(channel) ⇒ Boolean
Check if a specific broadcast channel is allowed
122 123 124 |
# File 'lib/eventd/eventd_server.rb', line 122 def broadcast_channel_allowed?(channel) !@broadcasts_restricted or @allowed_broadcast_channels.include? channel end |
#broadcast_channel_restricted?(channel) ⇒ Boolean
Check if a specific broadcast channel is restricted
128 129 130 |
# File 'lib/eventd/eventd_server.rb', line 128 def broadcast_channel_restricted?(channel) @allowed_broadcast_channels.find_index channel == nil and @broadcasts_restricted end |
#broadcasts_allowed? ⇒ Boolean
Check if broadcasts are allowed
110 111 112 |
# File 'lib/eventd/eventd_server.rb', line 110 def broadcasts_allowed? !@broadcasts_restricted end |
#broadcasts_restricted? ⇒ Boolean
Check if broadcasts are restricted
116 117 118 |
# File 'lib/eventd/eventd_server.rb', line 116 def broadcasts_restricted? @broadcasts_restricted end |
#configure(options) ⇒ Object
Add to the EventdServer configuration
Attributes
-
options
- Configuration hash to merge with the existing configuration
52 53 54 |
# File 'lib/eventd/eventd_server.rb', line 52 def configure() @options.merge! end |
#plugin(&callback) ⇒ Object
Allows you to extend the functionality of a server, through a plugin
80 81 82 |
# File 'lib/eventd/eventd_server.rb', line 80 def plugin(&callback) callback.call self end |
#remove_allowed_broadcast(channel) ⇒ Object
Remove an allowed broadcast channel
104 105 106 |
# File 'lib/eventd/eventd_server.rb', line 104 def remove_allowed_broadcast(channel) @allowed_broadcast_channels.delete_if do |c| c == channel end end |
#restrict_broadcasts ⇒ Object
Restrict broadcasts
92 93 94 |
# File 'lib/eventd/eventd_server.rb', line 92 def restrict_broadcasts @broadcasts_restricted = true end |
#run(&callback) ⇒ Object
Special event listener which is triggered when the server runs
74 75 76 |
# File 'lib/eventd/eventd_server.rb', line 74 def run(&callback) @run_callback = callback end |
#start ⇒ Object
Start the server
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/eventd/eventd_server.rb', line 58 def start EM.run do @run_callback.call EM::WebSocket.run @options do |socket| client = EventdClient.new socket, self self.emit 'connection', client self.clients.push client handle_disconnection_for client end end end |