2017-07-16 13:10:15 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-01-15 19:07:18 -05:00
|
|
|
class SuccessAdapter < ActionCable::SubscriptionAdapter::Base
|
2016-01-15 17:11:30 -05:00
|
|
|
def broadcast(channel, payload)
|
|
|
|
end
|
|
|
|
|
|
|
|
def subscribe(channel, callback, success_callback = nil)
|
2020-01-17 16:39:06 -05:00
|
|
|
subscriber_map[channel] << callback
|
2018-05-31 11:32:52 -04:00
|
|
|
@@subscribe_called = { channel: channel, callback: callback, success_callback: success_callback }
|
2016-01-15 17:11:30 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def unsubscribe(channel, callback)
|
2020-01-17 16:39:06 -05:00
|
|
|
subscriber_map[channel].delete(callback)
|
|
|
|
subscriber_map.delete(channel) if subscriber_map[channel].empty?
|
2018-05-31 11:32:52 -04:00
|
|
|
@@unsubscribe_called = { channel: channel, callback: callback }
|
2016-01-15 17:11:30 -05:00
|
|
|
end
|
2020-01-17 16:39:06 -05:00
|
|
|
|
|
|
|
def subscriber_map
|
|
|
|
@subscribers ||= Hash.new { |h, k| h[k] = [] }
|
|
|
|
end
|
2016-01-15 17:11:30 -05:00
|
|
|
end
|