Class: Caldera::Node
- Inherits:
-
Object
- Object
- Caldera::Node
- Includes:
- EventEmitter
- Defined in:
- lib/caldera/node.rb
Constant Summary collapse
- LOGGER =
Logging.logger[self]
Instance Attribute Summary collapse
- #client ⇒ Caldera::Client readonly
- #http ⇒ Net::HTTP readonly
- #stats ⇒ Caldera::Model::Stats readonly
- #websocket ⇒ Caldera::WebSocket readonly
Instance Method Summary collapse
- #create_player(guild_id, session_id, event) ⇒ Object
-
#initialize(rest_uri, ws_uri, auth, client) ⇒ Node
constructor
A new instance of Node.
- #load_tracks(id) ⇒ Object
- #send_json(data) ⇒ Object
- #soundcloud_search(search_string) ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
- #youtube_search(search_string) ⇒ Object
Constructor Details
#initialize(rest_uri, ws_uri, auth, client) ⇒ Node
Returns a new instance of Node.
27 28 29 30 31 32 33 34 35 |
# File 'lib/caldera/node.rb', line 27 def initialize(rest_uri, ws_uri, auth, client) @client = client @authorization = auth @websocket = WebSocket.new(ws_uri, auth, @client.num_shards, @client.user_id) register_handlers @stats = nil @available = false @http = Net::HTTP.new(rest_uri.host, rest_uri.port) end |
Instance Attribute Details
#client ⇒ Caldera::Client (readonly)
16 17 18 |
# File 'lib/caldera/node.rb', line 16 def client @client end |
#http ⇒ Net::HTTP (readonly)
22 23 24 |
# File 'lib/caldera/node.rb', line 22 def http @http end |
#stats ⇒ Caldera::Model::Stats (readonly)
25 26 27 |
# File 'lib/caldera/node.rb', line 25 def stats @stats end |
#websocket ⇒ Caldera::WebSocket (readonly)
19 20 21 |
# File 'lib/caldera/node.rb', line 19 def websocket @websocket end |
Instance Method Details
#create_player(guild_id, session_id, event) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/caldera/node.rb', line 47 def create_player(guild_id, session_id, event) LOGGER.info { "Creating player for #{guild_id}" } @websocket.send_json({ op: :voiceUpdate, guildId: guild_id, sessionId: session_id, event: event }) player = Player.new(guild_id, self, client) @client.players[guild_id] = player end |
#load_tracks(id) ⇒ Object
60 61 62 63 |
# File 'lib/caldera/node.rb', line 60 def load_tracks(id) resp = get('/loadtracks', query: { identifier: id }) Model::LoadTracks.new(resp) end |
#send_json(data) ⇒ Object
73 74 75 |
# File 'lib/caldera/node.rb', line 73 def send_json(data) @websocket.send_json(data) end |
#soundcloud_search(search_string) ⇒ Object
69 70 71 |
# File 'lib/caldera/node.rb', line 69 def soundcloud_search(search_string) load_tracks("scsearch:#{search_string}") end |
#start ⇒ Object
37 38 39 40 |
# File 'lib/caldera/node.rb', line 37 def start LOGGER.info { "Connecting to #{@websocket.url}" } @websocket.start end |
#stop ⇒ Object
42 43 44 45 |
# File 'lib/caldera/node.rb', line 42 def stop LOGGER.info { "Disconnecting from #{@websocket.url}" } @websocket.close end |
#youtube_search(search_string) ⇒ Object
65 66 67 |
# File 'lib/caldera/node.rb', line 65 def youtube_search(search_string) load_tracks("ytsearch:#{search_string}") end |