mirror of
https://github.com/FluuxIO/go-xmpp.git
synced 2025-11-28 20:13:42 -08:00
PubSub protocol support (#142)
* PubSub protocol support Added support for : - XEP-0050 (Command)) - XEP-0060 (PubSub) - XEP-0004 (Forms) Fixed the NewClient function by adding parsing of the domain from the JID if no domain is provided in transport config. Updated xmpp_jukebox example * Delete useless pubsub errors * README.md update Fixed import in echo example * Typo * Fixed raw send on client example * Fixed jukebox example and added a README.md
This commit is contained in:
committed by
Jérôme Sautret
parent
6e2ba9ca57
commit
947fcf0432
37
_examples/xmpp_jukebox/README.md
Normal file
37
_examples/xmpp_jukebox/README.md
Normal file
@@ -0,0 +1,37 @@
|
||||
# Jukebox example
|
||||
|
||||
## Requirements
|
||||
- You need mpg123 installed on your computer because the example runs it as a command :
|
||||
[Official MPG123 website](https://mpg123.de/)
|
||||
Most linux distributions have a package for it.
|
||||
- You need a soundcloud ID to play a music from the website through mpg123. You currently cannot play music files with this example.
|
||||
Your user ID is available in your account settings on the [soundcloud website](https://soundcloud.com/)
|
||||
**One is provided for convenience.**
|
||||
- You need a running jabber server. You can run your local instance of [ejabberd](https://www.ejabberd.im/) for example.
|
||||
- You need a registered user on the running jabber server.
|
||||
|
||||
## Run
|
||||
You can edit the soundcloud ID in the example file with your own, or use the provided one :
|
||||
```go
|
||||
const scClientID = "dde6a0075614ac4f3bea423863076b22"
|
||||
```
|
||||
|
||||
To run the example, build it with (while in the example directory) :
|
||||
```
|
||||
go build xmpp_jukebox.go
|
||||
```
|
||||
|
||||
then run it with (update the command arguments accordingly):
|
||||
```
|
||||
./xmpp_jukebox -jid=MY_USERE@MY_DOMAIN/jukebox -password=MY_PASSWORD -address=MY_SERVER:MY_SERVER_PORT
|
||||
```
|
||||
Make sure to have a resource, for instance "/jukebox", on your jid.
|
||||
|
||||
Then you can send the following stanza to "MY_USERE@MY_DOMAIN/jukebox" (with the resource) to play a song (update the soundcloud URL accordingly) :
|
||||
```xml
|
||||
<iq id="1" to="MY_USERE@MY_DOMAIN/jukebox" type="set">
|
||||
<set xml:lang="en" xmlns="urn:xmpp:iot:control">
|
||||
<string name="url" value="https://soundcloud.com/UPDATE/ME"/>
|
||||
</set>
|
||||
</iq>
|
||||
```
|
||||
@@ -3,6 +3,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
@@ -19,7 +20,7 @@ import (
|
||||
const scClientID = "dde6a0075614ac4f3bea423863076b22"
|
||||
|
||||
func main() {
|
||||
jid := flag.String("jid", "", "jukebok XMPP JID, resource is optional")
|
||||
jid := flag.String("jid", "", "jukebok XMPP Jid, resource is optional")
|
||||
password := flag.String("password", "", "XMPP account password")
|
||||
address := flag.String("address", "", "If needed, XMPP server DNSName or IP and optional port (ie myserver:5222)")
|
||||
flag.Parse()
|
||||
@@ -48,7 +49,7 @@ func main() {
|
||||
handleMessage(s, p, player)
|
||||
})
|
||||
router.NewRoute().
|
||||
Packet("message").
|
||||
Packet("iq").
|
||||
HandlerFunc(func(s xmpp.Sender, p stanza.Packet) {
|
||||
handleIQ(s, p, player)
|
||||
})
|
||||
@@ -108,11 +109,29 @@ func handleIQ(s xmpp.Sender, p stanza.Packet, player *mpg123.Player) {
|
||||
}
|
||||
|
||||
func sendUserTune(s xmpp.Sender, artist string, title string) {
|
||||
tune := stanza.Tune{Artist: artist, Title: title}
|
||||
iq := stanza.NewIQ(stanza.Attrs{Type: stanza.IQTypeSet, Id: "usertune-1", Lang: "en"})
|
||||
payload := stanza.PubSub{Publish: &stanza.Publish{Node: "http://jabber.org/protocol/tune", Item: stanza.Item{Tune: &tune}}}
|
||||
iq.Payload = &payload
|
||||
_ = s.Send(iq)
|
||||
rq, err := stanza.NewPublishItemRq("localhost",
|
||||
"http://jabber.org/protocol/tune",
|
||||
"",
|
||||
stanza.Item{
|
||||
XMLName: xml.Name{Space: "http://jabber.org/protocol/tune", Local: "tune"},
|
||||
Any: &stanza.Node{
|
||||
Nodes: []stanza.Node{
|
||||
{
|
||||
XMLName: xml.Name{Local: "artist"},
|
||||
Content: artist,
|
||||
},
|
||||
{
|
||||
XMLName: xml.Name{Local: "title"},
|
||||
Content: title,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Printf("failed to build the publish request : %s", err.Error())
|
||||
return
|
||||
}
|
||||
_ = s.Send(rq)
|
||||
}
|
||||
|
||||
func playSCURL(p *mpg123.Player, rawURL string) {
|
||||
@@ -120,7 +139,7 @@ func playSCURL(p *mpg123.Player, rawURL string) {
|
||||
// TODO: Maybe we need to check the track itself to get the stream URL from reply ?
|
||||
url := soundcloud.FormatStreamURL(songID)
|
||||
|
||||
_ = p.Play(url)
|
||||
_ = p.Play(strings.ReplaceAll(url, "YOUR_SOUNDCLOUD_CLIENTID", scClientID))
|
||||
}
|
||||
|
||||
// TODO
|
||||
|
||||
Reference in New Issue
Block a user