class EventdServer
Attributes
List of allowed broadcast channels
Broadcast restriction
List of active clients on the server
Configuration options for em-websocket and the EventdServer
Callback block which is called when the server starts for threading purposed
Public Class Methods
Initialize the EventdServer
with configuration options
Attributes¶ ↑
-
options
- Configuration hash which will be used as the initialEventdServer
configuration
EventdObject::new
# File lib/eventd/eventd_server.rb, line 38 def initialize(options = { :host => '127.0.0.1', :port => 8080 }) super() @options = options @clients = [] @broadcasts_restricted = false @allowed_broadcast_channels = [] end
Public Instance Methods
Add an allowed broadcast channel
# File lib/eventd/eventd_server.rb, line 98 def add_allowed_broadcast(channel) @allowed_broadcast_channels.push channel end
Allow any broadcast
# File lib/eventd/eventd_server.rb, line 86 def allow_broadcasts @broadcasts_restricted = false end
Check if a specific broadcast channel is allowed
# File lib/eventd/eventd_server.rb, line 122 def broadcast_channel_allowed?(channel) !@broadcasts_restricted or @allowed_broadcast_channels.include? channel end
Check if a specific broadcast channel is restricted
# File lib/eventd/eventd_server.rb, line 128 def broadcast_channel_restricted?(channel) @allowed_broadcast_channels.find_index channel == nil and @broadcasts_restricted end
Check if broadcasts are allowed
# File lib/eventd/eventd_server.rb, line 110 def broadcasts_allowed? !@broadcasts_restricted end
Check if broadcasts are restricted
# File lib/eventd/eventd_server.rb, line 116 def broadcasts_restricted? @broadcasts_restricted end
Add to the EventdServer
configuration
Attributes¶ ↑
-
options
- Configuration hash to merge with the existing configuration
# File lib/eventd/eventd_server.rb, line 52 def configure(options) @options.merge! options end
Allows you to extend the functionality of a server, through a plugin
# File lib/eventd/eventd_server.rb, line 80 def plugin(&callback) callback.call self end
Remove an allowed broadcast channel
# 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
# File lib/eventd/eventd_server.rb, line 92 def restrict_broadcasts @broadcasts_restricted = true end
Special event listener which is triggered when the server runs
# File lib/eventd/eventd_server.rb, line 74 def run(&callback) @run_callback = callback end
Start the server
# 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
Private Instance Methods
# File lib/eventd/eventd_server.rb, line 134 def handle_disconnection_for(client) client.on 'disconnect' do @clients.delete_if do |c| c == client end self.emit 'disconnection', client end end