Class: Mumbletune::MumbleClient

Inherits:
Object
  • Object
show all
Defined in:
lib/mumbletune/mumble_client.rb

Instance Method Summary collapse

Constructor Details

#initializeMumbleClient

Returns a new instance of MumbleClient.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/mumbletune/mumble_client.rb', line 6

def initialize
  m_conf = Mumbletune.config["mumble"]
  format = {rate: 44100, channels: 2} # Format used by spotify
  @cli = Mumble::Client.new(m_conf['host'], m_conf['port'], m_conf['username'], m_conf['password'], format)

  @cli.on_server_sync do |message| # Once connected.
    @cli.session = message.session # housekeeping for mumble-ruby
    connect_to = @cli.channels.select { |key, hash| hash["name"] == m_conf["channel"] }.first[1][:name]
    @cli.join_channel connect_to

    @ready = true
  end

  @cli.on_text_message do |data|
    if data[:session].include?(@cli.me[:session]) # if message was sent to us
      # interpret the message in a separate thread
      Thread.new { Message.parse(@cli, data) }
    end
  end
end

Instance Method Details

#broadcast(text) ⇒ Object



56
57
58
# File 'lib/mumbletune/mumble_client.rb', line 56

def broadcast(text)
  @cli.text_channel(@cli.me.channel_id, text)
end

#connectObject



27
28
29
30
31
32
33
34
# File 'lib/mumbletune/mumble_client.rb', line 27

def connect
  @ready = false
  @cli.connect

  @ready_wait = Thread.new do 
    sleep 0.1 until @ready
  end
end

#disconnectObject



46
47
48
49
# File 'lib/mumbletune/mumble_client.rb', line 46

def disconnect
  @audio_stream.stop if @audio_stream
  @cli.disconnect
end

#message(users, text) ⇒ Object



51
52
53
54
# File 'lib/mumbletune/mumble_client.rb', line 51

def message(users, text)
  users = Array(users) # force into array
  users.each { |u| @cli.text_user(u.session, text) }
end

#streamObject



36
37
38
39
40
41
42
43
44
# File 'lib/mumbletune/mumble_client.rb', line 36

def stream
  @ready_wait.join
  Thread.current.priority = 5
  queue = Mumbletune.player.audio_queue

  @audio_stream = @cli.stream_from_queue(queue)

  self.volume = Mumbletune.config["player"]["default_volume"]
end

#volumeObject



60
61
62
# File 'lib/mumbletune/mumble_client.rb', line 60

def volume
  (@audio_stream.volume * 100).to_i
end

#volume=(vol) ⇒ Object



64
65
66
# File 'lib/mumbletune/mumble_client.rb', line 64

def volume=(vol)
  @audio_stream.volume = vol.to_i
end