Class: Mumble::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, port = 64738, username = "Ruby Client", password = "") ⇒ Client

Returns a new instance of Client.



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

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

Instance Attribute Details

#channelsObject (readonly)

Returns the value of attribute channels.



12
13
14
# File 'lib/mumble-ruby/client.rb', line 12

def channels
  @channels
end

#hostObject (readonly)

Returns the value of attribute host.



12
13
14
# File 'lib/mumble-ruby/client.rb', line 12

def host
  @host
end

#passwordObject (readonly)

Returns the value of attribute password.



12
13
14
# File 'lib/mumble-ruby/client.rb', line 12

def password
  @password
end

#portObject (readonly)

Returns the value of attribute port.



12
13
14
# File 'lib/mumble-ruby/client.rb', line 12

def port
  @port
end

#usernameObject (readonly)

Returns the value of attribute username.



12
13
14
# File 'lib/mumble-ruby/client.rb', line 12

def username
  @username
end

#usersObject (readonly)

Returns the value of attribute users.



12
13
14
# File 'lib/mumble-ruby/client.rb', line 12

def users
  @users
end

Instance Method Details

#connectObject



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/mumble-ruby/client.rb', line 23

def connect
  @conn = Connection.new @host, @port
  @conn.connect

  create_encoder
  version_exchange
  authenticate
  init_callbacks

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

#current_channelObject



47
48
49
# File 'lib/mumble-ruby/client.rb', line 47

def current_channel
  @channels[me.channel_id]
end

#deafen(bool = true) ⇒ Object



70
71
72
# File 'lib/mumble-ruby/client.rb', line 70

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

#disconnectObject



36
37
38
39
40
41
# File 'lib/mumble-ruby/client.rb', line 36

def disconnect
  @encoder.destroy
  @read_thread.kill
  @ping_thread.kill
  @conn.disconnect
end

#find_channel(name) ⇒ Object



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

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

#find_user(name) ⇒ Object



99
100
101
# File 'lib/mumble-ruby/client.rb', line 99

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

#join_channel(channel) ⇒ Object



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

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

#meObject



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

def me
  @users[@session]
end

#mute(bool = true) ⇒ Object



66
67
68
# File 'lib/mumble-ruby/client.rb', line 66

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

#stream_raw_audio(file) ⇒ Object

Raises:



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

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

#text_channel(channel, string) ⇒ Object



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

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

#text_user(user, string) ⇒ Object



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

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

#user_stats(user) ⇒ Object



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

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