Class: Vines::XmppServer

Inherits:
Object
  • Object
show all
Includes:
Log
Defined in:
lib/vines/xmpp_server.rb

Overview

The main starting point for the XMPP server process. Starts the EventMachine processing loop and registers the XMPP protocol handler with the ports defined in the server configuration file.

Instance Method Summary collapse

Methods included from Log

#log

Constructor Details

#initialize(config) ⇒ XmppServer

Returns a new instance of XmppServer.



11
12
13
# File 'lib/vines/xmpp_server.rb', line 11

def initialize(config)
  @config = config
end

Instance Method Details

#startObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/vines/xmpp_server.rb', line 15

def start
  log.info('XMPP server started')
  at_exit { log.fatal('XMPP server stopped') }
  EM.epoll
  EM.kqueue

  u = UPnP::UPnP.new
  log.info('UPnP started')

  EM.run do
    @config.ports.each do |port|
      forwarded = true

      begin
        u.addPortMapping(port.settings[:port], port.settings[:port], 
            "TCP", port.stream.to_s, Kit.local_ip)
      rescue UPnP::UPnPException
        log.warn("Cannot forward port #{port.settings[:port]}")  
        forwarded = false
      end

      log.info("Forwarded port #{port.settings[:port]}") if forwarded
    
      port.start
    end
  end
end