Class: Discordrb::Voice::VoiceBot

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_timeObject (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

#continueObject

Continue playback



38
39
40
# File 'lib/discordrb/voice/voice_bot.rb', line 38

def continue
  @paused = false
end

#destroyObject



55
56
57
58
59
# File 'lib/discordrb/voice/voice_bot.rb', line 55

def destroy
  stop_playing
  @ws.destroy
  @encoder.destroy
end

#pauseObject

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)
  stop_playing if @playing
  @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)
  @playing = value
  @ws.send_speaking(value)
end

#stop_playingObject



47
48
49
50
51
52
53
# File 'lib/discordrb/voice/voice_bot.rb', line 47

def stop_playing
  @was_playing_before = @playing
  @speaking = false
  @io.close if @io
  @io = nil
  sleep IDEAL_LENGTH / 1000.0 if @was_playing_before
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