Class: Roda::Component::Faye
- Includes:
- Native
- Defined in:
- lib/roda/component/faye.rb,
lib/roda/component/faye.rb
Defined Under Namespace
Classes: ChannelManager, CsrfProtection
Instance Attribute Summary collapse
-
#disconnected ⇒ Object
Returns the value of attribute disconnected.
-
#online ⇒ Object
Returns the value of attribute online.
Instance Method Summary collapse
- #incoming(message, block) ⇒ Object
-
#initialize(url) ⇒ Faye
constructor
A new instance of Faye.
- #outgoing(message, block) ⇒ Object
- #private_id ⇒ Object
- #public_id ⇒ Object
Constructor Details
#initialize(url) ⇒ Faye
Returns a new instance of Faye.
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/roda/component/faye.rb', line 21 def initialize url return false unless `(typeof Faye === 'function')` super `new Faye.Client(#{url})` set_header 'X-CSRF-TOKEN', Element.find('meta[name=_csrf]').attr('content') add_extension({ incoming: ->(, block) { incoming , block }, outgoing: ->(, block) { outgoing , block } }) end |
Instance Attribute Details
#disconnected ⇒ Object
Returns the value of attribute disconnected.
19 20 21 |
# File 'lib/roda/component/faye.rb', line 19 def disconnected @disconnected end |
#online ⇒ Object
Returns the value of attribute online.
19 20 21 |
# File 'lib/roda/component/faye.rb', line 19 def online @online end |
Instance Method Details
#incoming(message, block) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/roda/component/faye.rb', line 40 def incoming , block # puts '====INCOMING====' # `console.log(#{message})` # puts '================' if (!@public_id && !@private_id) && [:channel] == '/meta/handshake' subscribe "/components/incoming/#{private_id}/#{public_id}" do |data| data = Native(data) event_id = data[:event_id] body = Element['body'] body.trigger(event_id, data[:local], data) body.off event_id end end block.call end |
#outgoing(message, block) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/roda/component/faye.rb', line 59 def outgoing , block = %x{ message = #{} message.ext = message.ext || {}; message.ext.csrfToken = $('meta[name=_csrf]').attr('content'); message.ext.public_id = #{public_id}; message.ext.private_id = #{private_id}; } # puts '====OUTGOING====' # `console.log(#{message})` # puts '================' block.call end |
#private_id ⇒ Object
36 37 38 |
# File 'lib/roda/component/faye.rb', line 36 def private_id @private_id ||= generate_id end |
#public_id ⇒ Object
32 33 34 |
# File 'lib/roda/component/faye.rb', line 32 def public_id @public_id ||= generate_id end |