Class: RenderSync::FayeExtension
- Inherits:
-
Object
- Object
- RenderSync::FayeExtension
- Defined in:
- lib/render_sync/faye_extension.rb
Instance Method Summary collapse
- #batch_incoming(message, callback) ⇒ Object
- #batch_publish?(message) ⇒ Boolean
- #handle_eror(message, callback) ⇒ Object
- #incoming(message, callback) ⇒ Object
- #message_authenticated?(message) ⇒ Boolean
-
#outgoing(message, callback) ⇒ Object
IMPORTANT: clear out the auth token so it is not leaked to the client.
- #single_incoming(message, callback) ⇒ Object
Instance Method Details
#batch_incoming(message, callback) ⇒ Object
13 14 15 16 17 |
# File 'lib/render_sync/faye_extension.rb', line 13 def batch_incoming(, callback) ["data"].each do || incoming(, callback) end end |
#batch_publish?(message) ⇒ Boolean
23 24 25 |
# File 'lib/render_sync/faye_extension.rb', line 23 def batch_publish?() ['channel'] == "/batch_publish" end |
#handle_eror(message, callback) ⇒ Object
35 36 37 38 |
# File 'lib/render_sync/faye_extension.rb', line 35 def handle_eror(, callback) ['error'] = 'Invalid authentication token' callback.call() end |
#incoming(message, callback) ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'lib/render_sync/faye_extension.rb', line 4 def incoming(, callback) return handle_eror(, callback) unless () if batch_publish?() batch_incoming(, callback) else single_incoming(, callback) end end |
#message_authenticated?(message) ⇒ Boolean
40 41 42 43 |
# File 'lib/render_sync/faye_extension.rb', line 40 def () !(['channel'] !~ %r{^/meta/} && ['ext']['auth_token'] != RenderSync.auth_token) end |
#outgoing(message, callback) ⇒ Object
IMPORTANT: clear out the auth token so it is not leaked to the client
28 29 30 31 32 33 |
# File 'lib/render_sync/faye_extension.rb', line 28 def outgoing(, callback) if ['ext'] && ['ext']['auth_token'] ['ext'] = {} end callback.call() end |
#single_incoming(message, callback) ⇒ Object
19 20 21 |
# File 'lib/render_sync/faye_extension.rb', line 19 def single_incoming(, callback) callback.call() end |