Sha256: 36dc83c3a02cc4e59da81d8d411d7e074cedfee1b4ef8a94e81a8663489dfcea

Contents?: true

Size: 1.48 KB

Versions: 1

Compression:

Stored size: 1.48 KB

Contents

module XMPP
  class Client
    include Blather::DSL
    class << self
      attr_accessor :engine,
                    :ready,
                    :answers

      def start

        thread = Thread.new do
          ### config
          begin
            XMPP::Client.engine  ||= XMPP::Client.new
            XMPP::Client.answers ||= Hash.new
            jid  = XMPP::CONFIG::JID
            pwd  = XMPP::CONFIG::PWD
            host = XMPP::CONFIG::HOST
            port = XMPP::CONFIG::PORT
          end
          ### settings
          begin
            XMPP::Client.engine.setup jid,pwd,host,port
            XMPP::Client.engine.when_ready do
              XMPP::Client.ready= true
            end
            XMPP::Client.engine.subscription :request? do |s|
              XMPP::Client.engine.write_to_stream s.approve!
            end
            XMPP::Client.engine.disconnected do
              begin
                EM.run do
                  XMPP::Client.engine.run
                end
              rescue Exception
                retry
              end
            end
            XMPP::Client.engine.message :chat?, :body do |m|
              XMPP::Client.engine.say m.from, XMPP.receive(m.body)
            end
          end
          ### launch
          begin
            EM.run do
              XMPP::Client.engine.run
            end
          rescue Exception
            retry
          end
        end
        thread.abort_on_exception = true
        return true
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
clone-1.0.0.beta samples/blather/restlike/lib/blather/dsl/client.rb