commit 6c87f537549ca5125fbe7faa7cd4e9353e031e8f
parent e6908ad17804237bb7f0669edc99e86339a18d84
Author: Oliver Lowe <o@olowe.co>
Date: Sat, 10 Aug 2024 15:33:44 +1000
sdp: make the empty Origin Username useful
One less thing for users to worry about, and we'll always encode a
valid value.
Diffstat:
4 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/cmd/autx/autx.go b/cmd/autx/autx.go
@@ -73,7 +73,6 @@ func main() {
description := sdp.Session{
Origin: sdp.Origin{
- Username: sdp.NoUsername,
ID: sdp.Now(),
Version: sdp.Now(),
AddressType: ipv,
diff --git a/sdp/encode.go b/sdp/encode.go
@@ -8,6 +8,9 @@ import (
func (s Session) String() string {
buf := &strings.Builder{}
fmt.Fprintln(buf, "v=0")
+ if s.Origin.Username == "" {
+ s.Origin.Username = NoUsername
+ }
fmt.Fprintf(buf, "o=%s %d %d IN %s %s\n", s.Origin.Username, s.Origin.ID, s.Origin.Version, s.Origin.AddressType, s.Origin.Address)
fmt.Fprintf(buf, "s=%s\n", s.Name)
diff --git a/sdp/example_test.go b/sdp/example_test.go
@@ -12,7 +12,6 @@ import (
func Example() {
session := sdp.Session{
Origin: sdp.Origin{
- Username: sdp.NoUsername,
ID: 3930287268, // example only; use sdp.Now()
Version: 3930287268, // example only; use sdp.Now()
AddressType: "IP6", // or "IP4"
diff --git a/sdp/sdp.go b/sdp/sdp.go
@@ -42,9 +42,8 @@ const NoUsername string = "-"
// Origin represents the originator of the session as described in RFC 8866 section 5.2.
type Origin struct {
- // Username is a named identity on the originating host. If
- // the host does not support usernames, this value should be set
- // to NoUsername.
+ // Username is a named identity on the originating host. If unset,
+ // the encoded value will be NoUsername.
Username string
// ID is a globally unique identifier for the session.