Sha256: 10899e8d8a7e10e6a6c7bd6fa527d53069791022f0fcfcf99347d5971cbceec2

Contents?: true

Size: 1.84 KB

Versions: 2

Compression:

Stored size: 1.84 KB

Contents

# Toplevel Pubnub module.
module Pubnub
  # Pubnub client Class
  class Client
    # Module that holds generator for all events
    module Events
      EVENTS = %w[publish subscribe presence leave history fetch_messages here_now audit grant
                  grant_token revoke_token delete_messages revoke time heartbeat where_now
                  set_state state channel_registration message_counts signal add_message_action
                  get_message_actions remove_message_action add_channels_to_push
                  list_push_provisions remove_channels_from_push remove_device_from_push
                  set_uuid_metadata set_channel_metadata remove_uuid_metadata
                  remove_channel_metadata get_uuid_metadata get_all_uuid_metadata
                  get_channel_metadata get_all_channels_metadata get_channel_members
                  get_memberships set_channel_members set_memberships remove_memberships
                  remove_channel_members].freeze

      EVENTS.each do |event_name|
        define_method event_name do |options = {}, &block|
          options[:callback] = block if options[:callback].nil?
          # Use constructor-provided :callback if nothing passed to method call.
          options[:callback] = self.env[:callback] if options[:callback].nil?
          event = Pubnub.const_get(
            Formatter.classify_method(event_name)
          ).new(options, self)

          if event.sync?
            event.fire
          elsif event.is_a? SubscribeEvent
            @subscriber.add_subscription(event)
            @subscriber.reset
          else
            Concurrent::Future.execute { event.fire }
          end
        end
      end

      alias unsubscribe leave
      alias get_state state

      def fire(options, &block)
        publish(options.merge(store: false, replicate: false), &block)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pubnub-5.5.0 lib/pubnub/client/events.rb
pubnub-5.4.0 lib/pubnub/client/events.rb