Class: Mumble::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/mumble-ruby/client.rb

Constant Summary collapse

CODEC_OPUS =
4

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, port = 64738, username = "RubyClient", password = "") {|@config| ... } ⇒ Client

Returns a new instance of Client.

Yields:

  • (@config)


14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/mumble-ruby/client.rb', line 14

def initialize(host, port=64738, username="RubyClient", password="")
  @users, @channels = {}, {}
  @callbacks = Hash.new { |h, k| h[k] = [] }
  @connected = false

  @config = Mumble.configuration.dup.tap do |c|
    c.host = host
    c.port = port
    c.username = username
    c.password = password
  end
  yield(@config) if block_given?
end

Instance Attribute Details

#channelsObject (readonly)

Returns the value of attribute channels.



10
11
12
# File 'lib/mumble-ruby/client.rb', line 10

def channels
  @channels
end

#connectedObject (readonly)

Returns the value of attribute connected.



10
11
12
# File 'lib/mumble-ruby/client.rb', line 10

def connected
  @connected
end

#usersObject (readonly)

Returns the value of attribute users.



10
11
12
# File 'lib/mumble-ruby/client.rb', line 10

def users
  @users
end

Instance Method Details

#connectObject



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/mumble-ruby/client.rb', line 28

def connect
  cert_manager = CertManager.new(@config.username, @config.ssl_cert_opts)
  @conn = Connection.new @config.host, @config.port, cert_manager
  @conn.connect

  create_encoder
  version_exchange
  authenticate
  init_callbacks

  @read_thread = spawn_thread :read
  @ping_thread = spawn_thread :ping
end

#current_channelObject



54
55
56
# File 'lib/mumble-ruby/client.rb', line 54

def current_channel
  channels[me.channel_id]
end

#deafen(bool = true) ⇒ Object



77
78
79
# File 'lib/mumble-ruby/client.rb', line 77

def deafen(bool=true)
  send_user_state self_deaf: bool
end

#disconnectObject



42
43
44
45
46
47
48
# File 'lib/mumble-ruby/client.rb', line 42

def disconnect
  @encoder.destroy
  @read_thread.kill
  @ping_thread.kill
  @conn.disconnect
  @connected = false
end

#find_channel(name) ⇒ Object



120
121
122
# File 'lib/mumble-ruby/client.rb', line 120

def find_channel(name)
  channels.values.find { |c| c.name == name }
end

#find_user(name) ⇒ Object



116
117
118
# File 'lib/mumble-ruby/client.rb', line 116

def find_user(name)
  users.values.find { |u| u.name == name }
end

#join_channel(channel) ⇒ Object



81
82
83
84
85
86
# File 'lib/mumble-ruby/client.rb', line 81

def join_channel(channel)
  send_user_state({
    session: me.session,
    channel_id: channel_id(channel)
  })
end

#meObject



50
51
52
# File 'lib/mumble-ruby/client.rb', line 50

def me
  users[@session]
end

#mute(bool = true) ⇒ Object



73
74
75
# File 'lib/mumble-ruby/client.rb', line 73

def mute(bool=true)
  send_user_state self_mute: bool
end

#on_connected(&block) ⇒ Object



124
125
126
# File 'lib/mumble-ruby/client.rb', line 124

def on_connected(&block)
  @callbacks[:connected] << block
end

#stream_raw_audio(file) ⇒ Object

Raises:



58
59
60
61
# File 'lib/mumble-ruby/client.rb', line 58

def stream_raw_audio(file)
  raise NoSupportedCodec unless @codec
  AudioStream.new(@codec, 0, @encoder, file, @conn)
end

#text_channel(channel, string) ⇒ Object



100
101
102
103
104
105
# File 'lib/mumble-ruby/client.rb', line 100

def text_channel(channel, string)
  send_text_message({
    channel_id: [channel_id(channel)],
    message: string
  })
end

#text_channel_img(channel, file) ⇒ Object



107
108
109
110
# File 'lib/mumble-ruby/client.rb', line 107

def text_channel_img(channel, file)
  img = ImgReader.new file
  text_channel(channel, img.to_msg)
end

#text_user(user, string) ⇒ Object



88
89
90
91
92
93
# File 'lib/mumble-ruby/client.rb', line 88

def text_user(user, string)
  send_text_message({
    session: [user_session(user)],
    message: string
  })
end

#text_user_img(user, file) ⇒ Object



95
96
97
98
# File 'lib/mumble-ruby/client.rb', line 95

def text_user_img(user, file)
  img = ImgReader.new file
  text_user(user, img.to_msg)
end

#user_stats(user) ⇒ Object



112
113
114
# File 'lib/mumble-ruby/client.rb', line 112

def user_stats(user)
  send_user_stats session: user_session(user)
end