Module: MPD::Plugins::Channels

Included in:
MPD
Defined in:
lib/ruby-mpd/plugins/channels.rb

Overview

Client to client commands

Clients can communicate with each others over “channels”. A channel is created by a client subscribing to it. More than one client can be subscribed to a channel at a time; all of them will receive the messages which get sent to it.

Each time a client subscribes or unsubscribes, the global idle event subscription is generated. In conjunction with the channels command, this may be used to auto-detect clients providing additional services.

New messages are indicated by the message idle event.

Instance Method Summary collapse

Instance Method Details

#channelsArray<String>

Obtain a list of all channels.

Returns:

  • (Array<String>)

    a list of channels



35
36
37
# File 'lib/ruby-mpd/plugins/channels.rb', line 35

def channels
  send_command :channels
end

#readmessagesArray<Hash>

Reads messages for this client. The response is an array of hashes with :channel and :message keys or true if no messages.

Returns:

  • (Array<Hash>)

    Messages recieved.



42
43
44
# File 'lib/ruby-mpd/plugins/channels.rb', line 42

def readmessages
  send_command :readmessages
end

#sendmessage(channel, message) ⇒ Boolean

Send a message to the specified channel.

Parameters:

  • channel (Symbol, String)

    The channel to send to.

  • message (String)

    The message to send.

Returns:

  • (Boolean)

    returns true if successful.



50
51
52
# File 'lib/ruby-mpd/plugins/channels.rb', line 50

def sendmessage(channel, message)
  send_command :sendmessage, channel, message
end

#subscribe(channel) ⇒ Boolean

Subscribe to a channel. The channel is created if it does not exist already. The name may consist of alphanumeric ASCII characters plus underscore, dash, dot and colon.

Parameters:

  • channel (Symbol, String)

    The channel to subscribe to.

Returns:

  • (Boolean)

    returns true if successful.



22
23
24
# File 'lib/ruby-mpd/plugins/channels.rb', line 22

def subscribe(channel)
  send_command :subscribe, channel
end

#unsubscribe(channel) ⇒ Boolean

Unsubscribe from a channel.

Parameters:

  • channel (Symbol, String)

    The channel to unsibscribe from.

Returns:

  • (Boolean)

    returns true if successful.



29
30
31
# File 'lib/ruby-mpd/plugins/channels.rb', line 29

def unsubscribe(channel)
  send_command :unsubscribe, channel
end