Module: TeamspeakHelper

Defined in:
app/helpers/teamspeak_helper.rb

Instance Method Summary collapse

Instance Method Details

#render_teamspeak_channel(channel, options = {}, depth = 0) ⇒ Object


2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/helpers/teamspeak_helper.rb', line 2

def render_teamspeak_channel(channel, options = {}, depth = 0)

  children = ''
  channel.channels.each {|c|
    children += render_teamspeak_channel(c, options, depth + 1)
  } if channel.channels.any?

  clients = ''
  channel.clients.each {|client|
    clients += render(:partial => options[:partials][:client], :locals => {:client => client}) unless client.nickname.match(/[\d\.]{7}/)
  } if channel.clients.any?

  render(:partial => options[:partials][:channel], :locals => {
    :channel => channel,
    :children => children,
    :clients => clients
  })
end

#render_teamspeak_server(options = {}) ⇒ Object


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/helpers/teamspeak_helper.rb', line 21

def render_teamspeak_server(options = {})
  options.reverse_merge!({
    :server => Teamspeak.servers.first,
    :partials => {
      :channel => 'teamspeak/channel',
      :client => 'teamspeak/client'
    }
  })

  output = ''
  options[:server].channels.each {|channel|
    output += render_teamspeak_channel(channel, options) if channel.pid == 0
  }

  # Make sure the socket is closed, otherwise mongrel/passenger instances will keep the connection alive
  Teamspeak.disconnect

  return output
end