Class: Restforce::Concerns::Streaming::ReplayExtension
- Inherits:
-
Object
- Object
- Restforce::Concerns::Streaming::ReplayExtension
- Defined in:
- lib/restforce/concerns/streaming.rb
Instance Method Summary collapse
- #incoming(message, callback) ⇒ Object
-
#initialize(replay_handlers) ⇒ ReplayExtension
constructor
A new instance of ReplayExtension.
- #outgoing(message, callback) ⇒ Object
Constructor Details
#initialize(replay_handlers) ⇒ ReplayExtension
Returns a new instance of ReplayExtension.
61 62 63 |
# File 'lib/restforce/concerns/streaming.rb', line 61 def initialize(replay_handlers) @replay_handlers = replay_handlers end |
Instance Method Details
#incoming(message, callback) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/restforce/concerns/streaming.rb', line 65 def incoming(, callback) callback.call().tap do channel = .fetch('channel') replay_id = .fetch('data', {}).fetch('event', {})['replayId'] handler = @replay_handlers[channel] if !replay_id.nil? && !handler.nil? && handler.respond_to?(:[]=) # remember the last replay_id for this channel handler[channel] = replay_id end end end |
#outgoing(message, callback) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/restforce/concerns/streaming.rb', line 78 def outgoing(, callback) # Leave non-subscribe messages alone return callback.call() unless ['channel'] == '/meta/subscribe' channel = ['subscription'] # Set the replay value for the channel ['ext'] ||= {} ['ext']['replay'] = { channel => replay_id(channel) } # Carry on and send the message to the server callback.call end |