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

#encoderObject (readonly)

Returns the value of attribute encoder.



14
15
16
# File 'lib/discordrb/voice/voice_bot.rb', line 14

def encoder
  @encoder
end

#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



42
43
44
# File 'lib/discordrb/voice/voice_bot.rb', line 42

def continue
  @paused = false
end

#destroyObject



59
60
61
62
63
# File 'lib/discordrb/voice/voice_bot.rb', line 59

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

#pauseObject

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

#stop_playingObject



51
52
53
54
55
56
57
# File 'lib/discordrb/voice/voice_bot.rb', line 51

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

#volumeObject



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