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.
150 151 152 153 |
# File 'lib/angelo/base.rb', line 150 def initialize server, context = nil @context, @server = context, server super() end |
Instance Method Details
#<<(ws) ⇒ Object
155 156 157 158 159 160 |
# File 'lib/angelo/base.rb', line 155 def << ws @@socket_context[ws] = @context if @context @@peeraddrs[ws] = ws.peeraddr @server.async.handle_websocket ws super ws end |
#[](context) ⇒ Object
183 184 185 186 |
# File 'lib/angelo/base.rb', line 183 def [] context raise ArgumentError.new "symbol required" unless Symbol === context @@websockets[context] ||= self.class.new @server, context end |
#all ⇒ Object
188 189 190 |
# File 'lib/angelo/base.rb', line 188 def all a = self + @@websockets.values.flatten end |
#each(&block) ⇒ Object
162 163 164 165 166 167 168 169 170 |
# File 'lib/angelo/base.rb', line 162 def each &block super do |ws| begin yield ws rescue Reel::SocketError remove_socket ws end end end |
#remove_socket(ws) ⇒ Object
172 173 174 175 176 177 178 179 180 181 |
# File 'lib/angelo/base.rb', line 172 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 |