Class: EventMachine::Breakout::Browser
- Inherits:
-
Connection
- Object
- WebSocket::Connection
- Connection
- EventMachine::Breakout::Browser
- Defined in:
- lib/em-breakout/browser.rb
Instance Attribute Summary collapse
-
#bid ⇒ Object
readonly
browser id.
-
#message_queue ⇒ Object
readonly
browser id.
-
#notify ⇒ Object
readonly
browser id.
-
#route ⇒ Object
readonly
browser id.
-
#wip ⇒ Object
true from when a worker gets sent a message until the worker sends :done_work, false all other times.
Attributes inherited from Connection
#grid, #grid_name, #is_closing
Instance Method Summary collapse
Methods inherited from Connection
Instance Attribute Details
#bid ⇒ Object (readonly)
browser id
6 7 8 |
# File 'lib/em-breakout/browser.rb', line 6 def bid @bid end |
#message_queue ⇒ Object (readonly)
browser id
6 7 8 |
# File 'lib/em-breakout/browser.rb', line 6 def end |
#notify ⇒ Object (readonly)
browser id
6 7 8 |
# File 'lib/em-breakout/browser.rb', line 6 def notify @notify end |
#route ⇒ Object (readonly)
browser id
6 7 8 |
# File 'lib/em-breakout/browser.rb', line 6 def route @route end |
#wip ⇒ Object
true from when a worker gets sent a message until the worker sends :done_work, false all other times
5 6 7 |
# File 'lib/em-breakout/browser.rb', line 5 def wip @wip end |
Instance Method Details
#breakout(debug = false) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/em-breakout/browser.rb', line 11 def breakout(debug=false) onopen do @grid_name = request["path"].split('?').first.gsub('/','') @grid = GRIDS[@grid_name] @route = request["query"]["route"] @bid = request["query"]["bid"] @notify = request["query"]["notify"] == "true" ? true : false @e = request["query"]["e"].to_i @gat = request["query"]["gat"] log(%|grid_name: #{@grid_name}\nroute: #{@route}\nbid: #{@bid}\ne: #{@e}\n| + %|gat: #{@gat}\nnotify: #{@notify}|) if debug catch :break do if !@grid close_websocket "unknown grid" throw :break end if @grid.browsers.has_key?(@bid) or @grid.disconnected_browsers.has_key?(@bid) close_websocket "bid in use" throw :break end if @e < Time.now.to_i close_websocket "expired" throw :break end unless @gat == ::Breakout.grid_access_token(@route, @bid, @e, @notify, @grid.grid_key) close_websocket "invalid url" throw :break end = [] @grid.browsers[@bid] = self if @notify << "/open" @grid.work_queue[self] = true EventMachine.next_tick { @grid.try_work } end end end do |msg| log("msg: #{msg}") if debug unless @is_closing if .empty? && !@wip @grid.work_queue[self] = true EventMachine.next_tick { @grid.try_work } end << msg end end onclose do log("closing") if debug if @grid.browsers.delete @bid if @notify @grid.disconnected_browsers[@bid] = self = ["/close"] unless @wip @grid.work_queue[self] = true EventMachine.next_tick { @grid.try_work } end else @grid.work_queue.delete self end end end onerror do |reason| log reason.pretty end end |