Class: Discordrb::Voice::VoiceUDP
- Inherits:
-
Object
- Object
- Discordrb::Voice::VoiceUDP
- Defined in:
- lib/discordrb/voice/network.rb
Overview
Represents a UDP connection to a voice server
Instance Method Summary collapse
-
#connect(endpoint, port, ssrc) ⇒ Object
Initializes the data from opcode 2.
-
#initialize ⇒ VoiceUDP
constructor
Only creates a socket as the discovery reply may come before the data is initialized.
- #receive_discovery_reply ⇒ Object
- #send_audio(buf, sequence, time) ⇒ Object
- #send_discovery ⇒ Object
Constructor Details
#initialize ⇒ VoiceUDP
Only creates a socket as the discovery reply may come before the data is initialized.
10 11 12 |
# File 'lib/discordrb/voice/network.rb', line 10 def initialize @socket = UDPSocket.new end |
Instance Method Details
#connect(endpoint, port, ssrc) ⇒ Object
Initializes the data from opcode 2
15 16 17 18 19 20 21 22 23 |
# File 'lib/discordrb/voice/network.rb', line 15 def connect(endpoint, port, ssrc) @endpoint = endpoint @endpoint = @endpoint[6..-1] if @endpoint.start_with? 'wss://' @endpoint.gsub!(':80', '') # The endpoint may contain a port, we don't want that @endpoint = Resolv.getaddress @endpoint @port = port @ssrc = ssrc end |
#receive_discovery_reply ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/discordrb/voice/network.rb', line 25 def receive_discovery_reply # Wait for a UDP message = @socket.recv(70) ip = [4..-3].delete("\0") port = [-2..-1].to_i [ip, port] end |
#send_audio(buf, sequence, time) ⇒ Object
33 34 35 36 |
# File 'lib/discordrb/voice/network.rb', line 33 def send_audio(buf, sequence, time) packet = [0x80, 0x78, sequence, time, @ssrc].pack('CCnNN') + buf send_packet(packet) end |
#send_discovery ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/discordrb/voice/network.rb', line 38 def send_discovery discovery_packet = [@ssrc].pack('N') # Add 66 zeroes so the packet is 70 bytes long discovery_packet += "\0" * 66 send_packet(discovery_packet) end |