Class: Angelo::Base::WebsocketsArray
- Inherits:
-
Array
- Object
- Array
- Angelo::Base::WebsocketsArray
- Includes:
- Celluloid::Logger
- Defined in:
- lib/angelo/base.rb
Constant Summary collapse
- @@peeraddrs =
{}
- @@socket_context =
{}
- @@websockets =
{}
Instance Method Summary collapse
- #<<(ws) ⇒ Object
- #[](context) ⇒ Object
- #all ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(server, context = nil) ⇒ WebsocketsArray
constructor
A new instance of WebsocketsArray.
- #remove_socket(ws) ⇒ Object
Constructor Details
#initialize(server, context = nil) ⇒ WebsocketsArray
Returns a new instance of WebsocketsArray.
165 166 167 168 |
# File 'lib/angelo/base.rb', line 165 def initialize server, context = nil @context, @server = context, server super() end |
Instance Method Details
#<<(ws) ⇒ Object
170 171 172 173 174 175 |
# File 'lib/angelo/base.rb', line 170 def << ws @@socket_context[ws] = @context if @context @@peeraddrs[ws] = ws.peeraddr @server.async.handle_websocket ws super ws end |
#[](context) ⇒ Object
198 199 200 201 |
# File 'lib/angelo/base.rb', line 198 def [] context raise ArgumentError.new "symbol required" unless Symbol === context @@websockets[context] ||= self.class.new @server, context end |
#all ⇒ Object
203 204 205 |
# File 'lib/angelo/base.rb', line 203 def all a = self + @@websockets.values.flatten end |
#each(&block) ⇒ Object
177 178 179 180 181 182 183 184 185 |
# File 'lib/angelo/base.rb', line 177 def each &block super do |ws| begin yield ws rescue Reel::SocketError remove_socket ws end end end |
#remove_socket(ws) ⇒ Object
187 188 189 190 191 192 193 194 195 196 |
# File 'lib/angelo/base.rb', line 187 def remove_socket ws if c = @@socket_context[ws] warn "removing socket from context ':#{c}' (#{@@peeraddrs[ws][2]})" self[c].delete ws else warn "removing socket (#{@@peeraddrs[ws][2]})" delete ws end @@peeraddrs.delete ws end |