Class: Streamforce::Extension::Replay
- Inherits:
-
Object
- Object
- Streamforce::Extension::Replay
- Defined in:
- lib/streamforce/extension/replay.rb
Instance Method Summary collapse
- #incoming(message, callback) ⇒ Object
-
#initialize(log_level = Logger::INFO) ⇒ Replay
constructor
A new instance of Replay.
- #outgoing(message, callback) ⇒ Object
- #replay_id(channel) ⇒ Object
- #store(channel, replay_id) ⇒ Object
Constructor Details
#initialize(log_level = Logger::INFO) ⇒ Replay
Returns a new instance of Replay.
4 5 6 7 8 |
# File 'lib/streamforce/extension/replay.rb', line 4 def initialize(log_level = Logger::INFO) @logger = Logger.new($stdout) @logger.level = log_level @redis = Redis.new end |
Instance Method Details
#incoming(message, callback) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/streamforce/extension/replay.rb', line 10 def incoming(, callback) replay_id = .dig "data", "event", "replayId" channel = ["channel"] store(channel, replay_id) callback.call() end |
#outgoing(message, callback) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/streamforce/extension/replay.rb', line 18 def outgoing(, callback) return callback.call() unless ["channel"] == "/meta/subscribe" channel = ["subscription"] ["ext"] = { "replay" => { channel => replay_id(channel).to_i } } callback.call() end |
#replay_id(channel) ⇒ Object
33 34 35 |
# File 'lib/streamforce/extension/replay.rb', line 33 def replay_id(channel) @redis.get(channel) || -1 end |
#store(channel, replay_id) ⇒ Object
27 28 29 30 31 |
# File 'lib/streamforce/extension/replay.rb', line 27 def store(channel, replay_id) return if channel.nil? || replay_id.nil? @redis.set channel, replay_id, ex: 86400 end |