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
-
#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=(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
#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
38 39 40 |
# File 'lib/discordrb/voice/voice_bot.rb', line 38 def continue @paused = false end |
#destroy ⇒ Object
55 56 57 58 59 |
# File 'lib/discordrb/voice/voice_bot.rb', line 55 def destroy @ws.destroy @encoder.destroy end |
#pause ⇒ Object
Pause playback
33 34 35 |
# File 'lib/discordrb/voice/voice_bot.rb', line 33 def pause @paused = true end |
#play(encoded_io) ⇒ Object
61 62 63 64 65 |
# File 'lib/discordrb/voice/voice_bot.rb', line 61 def play(encoded_io) if @io = encoded_io play_internal end |
#play_file(file) ⇒ Object
67 68 69 |
# File 'lib/discordrb/voice/voice_bot.rb', line 67 def play_file(file) play @encoder.encode_file(file) end |
#play_io(io) ⇒ Object Also known as: play_stream
71 72 73 |
# File 'lib/discordrb/voice/voice_bot.rb', line 71 def play_io(io) play @encoder.encode_io(io) end |
#speaking=(value) ⇒ Object
42 43 44 45 |
# File 'lib/discordrb/voice/voice_bot.rb', line 42 def speaking=(value) = value @ws.send_speaking(value) end |
#stop_playing ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/discordrb/voice/voice_bot.rb', line 47 def = @speaking = false @io.close if @io @io = nil sleep IDEAL_LENGTH / 1000.0 if 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 |