Class: Mumble::Client

Inherits:
Object
  • Object
show all
Includes:
ThreadTools
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
# 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] = [] }

  @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

#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

#cert_managerObject



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

def cert_manager
  @cert_manager ||= CertManager.new @config.username, @config.ssl_cert_opts
end

#connectObject



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

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

  init_callbacks
  version_exchange
  authenticate

  spawn_threads :read, :ping
  connected? # just to get a nice return value
end

#connected?Boolean

Returns:

  • (Boolean)


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

def connected?
  @connected ||= false
end

#disconnectObject



39
40
41
42
43
# File 'lib/mumble-ruby/client.rb', line 39

def disconnect
  kill_threads
  @conn.disconnect
  @connected = false
end

#find_channel(name) ⇒ Object



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

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

#find_user(name) ⇒ Object



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

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

#join_channel(channel) ⇒ Object



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

def join_channel(channel)
  id = channel_id channel
  send_user_state(session: @session, channel_id: id)
  channels[id]
end

#meObject



63
64
65
# File 'lib/mumble-ruby/client.rb', line 63

def me
  users[@session]
end

#move_user(user, channel) ⇒ Object



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

def move_user(user, channel)
  cid = channel_id channel
  uid = user_session user
  send_user_state(session: uid, channel_id: cid)
  channels[cid]
end

#on_connected(&block) ⇒ Object



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

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

#playerObject

Raises:



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

def player
  raise NoSupportedCodec unless @codec
  @audio_streamer ||= AudioPlayer.new @codec, @conn, @config.sample_rate, @config.bitrate
end

#recorderObject

Raises:



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

def recorder
  raise NoSupportedCodec unless @codec
  @recorder ||= AudioRecorder.new self, @config.sample_rate
end

#remove_callback(symbol, callback) ⇒ Object



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

def remove_callback(symbol, callback)
  @callbacks[symbol].delete callback
end

#set_comment(comment = "") ⇒ Object



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

def set_comment(comment="")
  send_user_state(comment: comment)
end

#text_channel(channel, string) ⇒ Object



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

def text_channel(channel, string)
  id = channel_id channel
  send_text_message(channel_id: [id], message: string)
  channels[id]
end

#text_channel_img(channel, file) ⇒ Object



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

def text_channel_img(channel, file)
  text_channel(channel, ImgReader.msg_from_file(file))
end

#text_user(user, string) ⇒ Object



84
85
86
87
88
# File 'lib/mumble-ruby/client.rb', line 84

def text_user(user, string)
  session = user_session user
  send_text_message(session: [user_session(user)], message: string)
  users[session]
end

#text_user_img(user, file) ⇒ Object



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

def text_user_img(user, file)
  text_user(user, ImgReader.msg_from_file(file))
end