Class: Discordrb::Voice::VoiceBot
- Inherits:
-
Object
- Object
- Discordrb::Voice::VoiceBot
- Defined in:
- lib/discordrb/voice/voice_bot.rb
Overview
A voice connection consisting of a UDP socket and a websocket client
Instance Attribute Summary collapse
-
#encoder ⇒ Object
readonly
Returns the value of attribute encoder.
-
#stream_time ⇒ Object
readonly
Returns the value of attribute stream_time.
Instance Method Summary collapse
-
#continue ⇒ Object
Continue playback.
- #destroy ⇒ Object
-
#initialize(channel, bot, token, session, endpoint) ⇒ VoiceBot
constructor
A new instance of VoiceBot.
-
#pause ⇒ Object
Pause playback.
- #play(encoded_io) ⇒ Object
- #play_file(file) ⇒ Object
- #play_io(io) ⇒ Object (also: #play_stream)
- #speaking=(value) ⇒ Object
- #stop_playing ⇒ Object
- #volume ⇒ Object
-
#volume=(value) ⇒ Object
Set the volume.
Constructor Details
#initialize(channel, bot, token, session, endpoint) ⇒ VoiceBot
Returns a new instance of VoiceBot.
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/discordrb/voice/voice_bot.rb', line 16 def initialize(channel, bot, token, session, endpoint) @bot = bot @ws = VoiceWS.new(channel, bot, token, session, endpoint) @udp = @ws.udp @sequence = @time = 0 @encoder = Encoder.new @ws.connect end |
Instance Attribute Details
#encoder ⇒ Object (readonly)
Returns the value of attribute encoder.
14 15 16 |
# File 'lib/discordrb/voice/voice_bot.rb', line 14 def encoder @encoder end |
#stream_time ⇒ Object (readonly)
Returns the value of attribute stream_time.
14 15 16 |
# File 'lib/discordrb/voice/voice_bot.rb', line 14 def stream_time @stream_time end |
Instance Method Details
#continue ⇒ Object
Continue playback
42 43 44 |
# File 'lib/discordrb/voice/voice_bot.rb', line 42 def continue @paused = false end |
#destroy ⇒ Object
59 60 61 62 63 |
# File 'lib/discordrb/voice/voice_bot.rb', line 59 def destroy @ws.destroy @encoder.destroy end |
#pause ⇒ Object
Pause playback
37 38 39 |
# File 'lib/discordrb/voice/voice_bot.rb', line 37 def pause @paused = true end |
#play(encoded_io) ⇒ Object
65 66 67 68 69 |
# File 'lib/discordrb/voice/voice_bot.rb', line 65 def play(encoded_io) if @io = encoded_io play_internal end |
#play_file(file) ⇒ Object
71 72 73 |
# File 'lib/discordrb/voice/voice_bot.rb', line 71 def play_file(file) play @encoder.encode_file(file) end |
#play_io(io) ⇒ Object Also known as: play_stream
75 76 77 |
# File 'lib/discordrb/voice/voice_bot.rb', line 75 def play_io(io) play @encoder.encode_io(io) end |
#speaking=(value) ⇒ Object
46 47 48 49 |
# File 'lib/discordrb/voice/voice_bot.rb', line 46 def speaking=(value) = value @ws.send_speaking(value) end |
#stop_playing ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/discordrb/voice/voice_bot.rb', line 51 def = @speaking = false @io.close if @io @io = nil sleep IDEAL_LENGTH / 1000.0 if end |
#volume ⇒ Object
32 33 34 |
# File 'lib/discordrb/voice/voice_bot.rb', line 32 def volume @encoder.volume end |
#volume=(value) ⇒ Object
Set the volume. Only applies to future playbacks
28 29 30 |
# File 'lib/discordrb/voice/voice_bot.rb', line 28 def volume=(value) @encoder.volume = value end |