eventd 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,7 +18,7 @@ class EventdClient < EventdObject
18
18
  # em-websocket socket object
19
19
  attr_accessor :socket
20
20
 
21
- def initialize(socket, server)
21
+ def initialize(socket, server = nil)
22
22
  super()
23
23
  @socket = socket
24
24
  @server = server
@@ -60,6 +60,10 @@ class EventdClient < EventdObject
60
60
  end
61
61
 
62
62
  def broadcast(channel, data = nil)
63
- @server.clients.each do |client| client.emit channel, data end
63
+ if @server.broadcast_channel_allowed? channel
64
+ @server.clients.each do |client| client.emit channel, data end
65
+ else
66
+ self.emit 'error', "Broadcasts are not allowed on channel: #{channel}"
67
+ end
64
68
  end
65
69
  end
@@ -24,6 +24,12 @@ class EventdServer < EventdObject
24
24
  # List of active clients on the server
25
25
  attr_accessor :clients
26
26
 
27
+ # List of allowed broadcast channels
28
+ attr_accessor :allowed_broadcast_channels
29
+
30
+ # Broadcast restriction
31
+ attr_accessor :broadcasts_restricted
32
+
27
33
  # Initialize the EventdServer with configuration options
28
34
  #
29
35
  # == Attributes
@@ -32,7 +38,10 @@ class EventdServer < EventdObject
32
38
  def initialize(options = { :host => '127.0.0.1', :port => 8080 })
33
39
  super()
34
40
  @options = options
41
+
35
42
  @clients = []
43
+ @broadcasts_restricted = false
44
+ @allowed_broadcast_channels = []
36
45
  end
37
46
 
38
47
  # Add to the EventdServer configuration
@@ -66,6 +75,54 @@ class EventdServer < EventdObject
66
75
  @run_callback = callback
67
76
  end
68
77
 
78
+ # Allow any broadcast
79
+
80
+ def allow_broadcasts
81
+ @broadcasts_restricted = false
82
+ end
83
+
84
+ # Restrict broadcasts
85
+
86
+ def restrict_broadcasts
87
+ @broadcasts_restricted = true
88
+ end
89
+
90
+ # Add an allowed broadcast channel
91
+
92
+ def add_allowed_broadcast(channel)
93
+ @allowed_broadcast_channels.push channel
94
+ end
95
+
96
+ # Remove an allowed broadcast channel
97
+
98
+ def remove_allowed_broadcast(channel)
99
+ @allowed_broadcast_channels.delete_if do |c| c == channel end
100
+ end
101
+
102
+ # Check if broadcasts are allowed
103
+
104
+ def broadcasts_allowed?
105
+ !@broadcasts_restricted
106
+ end
107
+
108
+ # Check if broadcasts are restricted
109
+
110
+ def broadcasts_restricted?
111
+ @broadcasts_restricted
112
+ end
113
+
114
+ # Check if a specific broadcast channel is allowed
115
+
116
+ def broadcast_channel_allowed?(channel)
117
+ !@broadcasts_restricted or @allowed_broadcast_channels.include? channel
118
+ end
119
+
120
+ # Check if a specific broadcast channel is restricted
121
+
122
+ def broadcast_channel_restricted?(channel)
123
+ @allowed_broadcast_channels.find_index channel == nil and @broadcasts_restricted
124
+ end
125
+
69
126
  private
70
127
 
71
128
  def handle_disconnection_for(client)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eventd
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: