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>)
  • (String)

    if only one channel exists.

  • (true)

    if no channels exist.



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

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.

  • (Hash)

    if only one message recieved

  • (true)

    if no messages.



45
46
47
# File 'lib/ruby-mpd/plugins/channels.rb', line 45

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.



53
54
55
# File 'lib/ruby-mpd/plugins/channels.rb', line 53

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.



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

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.



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

def unsubscribe(channel)
  send_command :unsubscribe, channel
end