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
This commit is contained in:
CORNIERE Rémi
2020-01-09 07:11:35 +01:00
parent 6e2ba9ca57
commit 00ceeeb5d4
27 changed files with 3397 additions and 46 deletions

View File

@@ -171,7 +171,7 @@ func handleDelegation(s xmpp.Sender, p stanza.Packet) {
return
}
pubsub, ok := forwardedIQ.Payload.(*stanza.PubSub)
pubsub, ok := forwardedIQ.Payload.(*stanza.PubSubGeneric)
if !ok {
// We only support pubsub delegation
return
@@ -180,7 +180,7 @@ func handleDelegation(s xmpp.Sender, p stanza.Packet) {
if pubsub.Publish.XMLName.Local == "publish" {
// Prepare pubsub IQ reply
iqResp := stanza.NewIQ(stanza.Attrs{Type: "result", From: forwardedIQ.To, To: forwardedIQ.From, Id: forwardedIQ.Id})
payload := stanza.PubSub{
payload := stanza.PubSubGeneric{
XMLName: xml.Name{
Space: "http://jabber.org/protocol/pubsub",
Local: "pubsub",

View File

@@ -8,6 +8,7 @@ import (
"fmt"
"log"
"os"
"strings"
"gosrc.io/xmpp"
"gosrc.io/xmpp/stanza"
@@ -28,7 +29,7 @@ func main() {
router := xmpp.NewRouter()
router.HandleFunc("message", handleMessage)
client, err := xmpp.NewClient(config, router)
client, err := xmpp.NewClient(config, router, errorHandler)
if err != nil {
log.Fatalf("%+v", err)
}
@@ -50,3 +51,7 @@ func handleMessage(s xmpp.Sender, p stanza.Packet) {
reply := stanza.Message{Attrs: stanza.Attrs{To: msg.From}, Body: msg.Body}
_ = s.Send(reply)
}
func errorHandler(err error) {
fmt.Println(err.Error())
}

View File

@@ -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()
@@ -108,11 +109,28 @@ 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())
}
_ = s.Send(rq)
}
func playSCURL(p *mpg123.Player, rawURL string) {