telegabber/xmpp/jingle/stanzas.go
2026-05-25 06:27:20 -07:00

210 lines
8 KiB
Go

package jingle
import (
"encoding/xml"
"gosrc.io/xmpp/stanza"
)
// supported Jingle actions; content-*, security-info, transport-*,
// description-info are intentionally not supported
const (
ActionSessionInitiate = "session-initiate"
ActionSessionAccept = "session-accept"
ActionSessionTerminate = "session-terminate"
ActionTransportInfo = "transport-info"
)
const (
ReasonSuccess = "success"
ReasonBusy = "busy"
ReasonDecline = "decline"
ReasonCancel = "cancel"
ReasonGone = "gone"
ReasonFailedTransport = "failed-transport"
ReasonFailedApplication = "failed-application"
ReasonIncompatibleParameters = "incompatible-parameters"
ReasonUnsupportedTransports = "unsupported-transports"
ReasonUnsupportedApplications = "unsupported-applications"
ReasonGeneralError = "general-error"
ReasonTimeout = "timeout"
ReasonConnectivityError = "connectivity-error"
)
type JingleIQ struct {
XMLName xml.Name `xml:"urn:xmpp:jingle:1 jingle"`
Action string `xml:"action,attr"`
Initiator string `xml:"initiator,attr,omitempty"`
Responder string `xml:"responder,attr,omitempty"`
SID string `xml:"sid,attr"`
Contents []Content `xml:"urn:xmpp:jingle:1 content"`
Group *Group `xml:"urn:xmpp:jingle:apps:grouping:0 group,omitempty"`
Reason *Reason `xml:"urn:xmpp:jingle:1 reason,omitempty"`
}
func (j JingleIQ) Namespace() string { return j.XMLName.Space }
func (j JingleIQ) GetSet() *stanza.ResultSet { return nil }
type Content struct {
XMLName xml.Name `xml:"urn:xmpp:jingle:1 content"`
Creator string `xml:"creator,attr"`
Senders string `xml:"senders,attr,omitempty"`
Name string `xml:"name,attr"`
Disposition string `xml:"disposition,attr,omitempty"`
Description *Description `xml:"urn:xmpp:jingle:apps:rtp:1 description,omitempty"`
Transport *Transport `xml:"urn:xmpp:jingle:transports:ice-udp:1 transport,omitempty"`
}
type Group struct {
XMLName xml.Name `xml:"urn:xmpp:jingle:apps:grouping:0 group"`
Semantics string `xml:"semantics,attr"`
Contents []GroupContent `xml:"urn:xmpp:jingle:apps:grouping:0 content"`
}
type GroupContent struct {
XMLName xml.Name `xml:"urn:xmpp:jingle:apps:grouping:0 content"`
Name string `xml:"name,attr"`
}
// preserves the inner condition element name and optional text;
// semantics handled in callers
type Reason struct {
XMLName xml.Name `xml:"urn:xmpp:jingle:1 reason"`
Condition *ReasonCondition `xml:",any"`
Text string `xml:"urn:xmpp:jingle:1 text,omitempty"`
}
// whichever element appears under <reason>; local name is the condition
type ReasonCondition struct {
XMLName xml.Name
}
type Description struct {
XMLName xml.Name `xml:"urn:xmpp:jingle:apps:rtp:1 description"`
Media string `xml:"media,attr"`
SSRC string `xml:"ssrc,attr,omitempty"`
PayloadTypes []PayloadType `xml:"urn:xmpp:jingle:apps:rtp:1 payload-type"`
RTPHdrexts []RTPHdrext `xml:"urn:xmpp:jingle:apps:rtp:rtp-hdrext:0 rtp-hdrext"`
ExtmapAllowMixed *ExtmapAllowMixed `xml:"urn:xmpp:jingle:apps:rtp:rtp-hdrext:0 extmap-allow-mixed,omitempty"`
RtcpMux *RtcpMux `xml:"urn:xmpp:jingle:apps:rtp:1 rtcp-mux,omitempty"`
RTCPFbs []RTCPFb `xml:"urn:xmpp:jingle:apps:rtp:rtcp-fb:0 rtcp-fb"`
RTCPFbTrrInts []RTCPFbTrrInt `xml:"urn:xmpp:jingle:apps:rtp:rtcp-fb:0 rtcp-fb-trr-int"`
Sources []Source `xml:"urn:xmpp:jingle:apps:rtp:ssma:0 source"`
SSRCGroups []SSRCGroup `xml:"urn:xmpp:jingle:apps:rtp:ssma:0 ssrc-group"`
}
type PayloadType struct {
XMLName xml.Name `xml:"urn:xmpp:jingle:apps:rtp:1 payload-type"`
ID string `xml:"id,attr"`
Name string `xml:"name,attr,omitempty"`
Clockrate string `xml:"clockrate,attr,omitempty"`
Channels string `xml:"channels,attr,omitempty"`
Ptime string `xml:"ptime,attr,omitempty"`
Maxptime string `xml:"maxptime,attr,omitempty"`
Parameters []Parameter `xml:"urn:xmpp:jingle:apps:rtp:1 parameter"`
RTCPFbs []RTCPFb `xml:"urn:xmpp:jingle:apps:rtp:rtcp-fb:0 rtcp-fb"`
RTCPFbTrrInts []RTCPFbTrrInt `xml:"urn:xmpp:jingle:apps:rtp:rtcp-fb:0 rtcp-fb-trr-int"`
}
// name/value pair used under <payload-type> (rtp:1) and <source> (ssma);
// namespace is governed by the parent's tag, so XMLName has none
type Parameter struct {
XMLName xml.Name `xml:"parameter"`
Name string `xml:"name,attr"`
Value string `xml:"value,attr,omitempty"`
}
type RTCPFb struct {
XMLName xml.Name `xml:"urn:xmpp:jingle:apps:rtp:rtcp-fb:0 rtcp-fb"`
Type string `xml:"type,attr"`
Subtype string `xml:"subtype,attr,omitempty"`
}
type RTCPFbTrrInt struct {
XMLName xml.Name `xml:"urn:xmpp:jingle:apps:rtp:rtcp-fb:0 rtcp-fb-trr-int"`
Value string `xml:"value,attr"`
}
type RTPHdrext struct {
XMLName xml.Name `xml:"urn:xmpp:jingle:apps:rtp:rtp-hdrext:0 rtp-hdrext"`
ID string `xml:"id,attr"`
URI string `xml:"uri,attr"`
Senders string `xml:"senders,attr,omitempty"`
}
// presence flag, RFC 8285 §6
type ExtmapAllowMixed struct {
XMLName xml.Name `xml:"urn:xmpp:jingle:apps:rtp:rtp-hdrext:0 extmap-allow-mixed"`
}
// presence flag for RTCP mux
type RtcpMux struct {
XMLName xml.Name `xml:"urn:xmpp:jingle:apps:rtp:1 rtcp-mux"`
}
type Source struct {
XMLName xml.Name `xml:"urn:xmpp:jingle:apps:rtp:ssma:0 source"`
SSRC string `xml:"ssrc,attr"`
Parameters []Parameter `xml:"urn:xmpp:jingle:apps:rtp:ssma:0 parameter"`
}
type SSRCGroup struct {
XMLName xml.Name `xml:"urn:xmpp:jingle:apps:rtp:ssma:0 ssrc-group"`
Semantics string `xml:"semantics,attr"`
Sources []SSRCGroupSource `xml:"urn:xmpp:jingle:apps:rtp:ssma:0 source"`
}
type SSRCGroupSource struct {
XMLName xml.Name `xml:"urn:xmpp:jingle:apps:rtp:ssma:0 source"`
SSRC string `xml:"ssrc,attr"`
}
type Transport struct {
XMLName xml.Name `xml:"urn:xmpp:jingle:transports:ice-udp:1 transport"`
Ufrag string `xml:"ufrag,attr,omitempty"`
Pwd string `xml:"pwd,attr,omitempty"`
Candidates []Candidate `xml:"urn:xmpp:jingle:transports:ice-udp:1 candidate"`
Fingerprint *Fingerprint `xml:"urn:xmpp:jingle:apps:dtls:0 fingerprint,omitempty"`
// well-known ICE options under gultsch.de namespace
Trickle *ICEOptionTrickle `xml:"http://gultsch.de/xmpp/drafts/jingle/transports/ice-udp/option trickle,omitempty"`
Renomination *ICEOptionRenomination `xml:"http://gultsch.de/xmpp/drafts/jingle/transports/ice-udp/option renomination,omitempty"`
}
type Candidate struct {
XMLName xml.Name `xml:"urn:xmpp:jingle:transports:ice-udp:1 candidate"`
Foundation string `xml:"foundation,attr"`
Component string `xml:"component,attr"`
Protocol string `xml:"protocol,attr"`
Priority string `xml:"priority,attr"`
IP string `xml:"ip,attr"`
Port string `xml:"port,attr"`
Type string `xml:"type,attr,omitempty"`
Network string `xml:"network,attr,omitempty"`
Generation string `xml:"generation,attr,omitempty"`
ID string `xml:"id,attr,omitempty"`
RelAddr string `xml:"rel-addr,attr,omitempty"`
RelPort string `xml:"rel-port,attr,omitempty"`
}
type Fingerprint struct {
XMLName xml.Name `xml:"urn:xmpp:jingle:apps:dtls:0 fingerprint"`
Hash string `xml:"hash,attr"`
Setup string `xml:"setup,attr,omitempty"`
Text string `xml:",chardata"`
}
type ICEOptionTrickle struct {
XMLName xml.Name `xml:"http://gultsch.de/xmpp/drafts/jingle/transports/ice-udp/option trickle"`
}
type ICEOptionRenomination struct {
XMLName xml.Name `xml:"http://gultsch.de/xmpp/drafts/jingle/transports/ice-udp/option renomination"`
}
func init() {
stanza.TypeRegistry.MapExtension(stanza.PKTIQ, xml.Name{
Space: NSJingle,
Local: "jingle",
}, JingleIQ{})
}