common_description.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. package sdp
  2. import (
  3. "strconv"
  4. "strings"
  5. )
  6. // Information describes the "i=" field which provides textual information
  7. // about the session.
  8. type Information string
  9. func (i Information) String() string {
  10. return string(i)
  11. }
  12. // ConnectionInformation defines the representation for the "c=" field
  13. // containing connection data.
  14. type ConnectionInformation struct {
  15. NetworkType string
  16. AddressType string
  17. Address *Address
  18. }
  19. func (c ConnectionInformation) String() string {
  20. parts := []string{c.NetworkType, c.AddressType}
  21. if c.Address != nil && c.Address.String() != "" {
  22. parts = append(parts, c.Address.String())
  23. }
  24. return strings.Join(parts, " ")
  25. }
  26. // Address desribes a structured address token from within the "c=" field.
  27. type Address struct {
  28. Address string
  29. TTL *int
  30. Range *int
  31. }
  32. func (c *Address) String() string {
  33. var parts []string
  34. parts = append(parts, c.Address)
  35. if c.TTL != nil {
  36. parts = append(parts, strconv.Itoa(*c.TTL))
  37. }
  38. if c.Range != nil {
  39. parts = append(parts, strconv.Itoa(*c.Range))
  40. }
  41. return strings.Join(parts, "/")
  42. }
  43. // Bandwidth describes an optional field which denotes the proposed bandwidth
  44. // to be used by the session or media.
  45. type Bandwidth struct {
  46. Experimental bool
  47. Type string
  48. Bandwidth uint64
  49. }
  50. func (b Bandwidth) String() string {
  51. var output string
  52. if b.Experimental {
  53. output += "X-"
  54. }
  55. output += b.Type + ":" + strconv.FormatUint(b.Bandwidth, 10)
  56. return output
  57. }
  58. // EncryptionKey describes the "k=" which conveys encryption key information.
  59. type EncryptionKey string
  60. func (s EncryptionKey) String() string {
  61. return string(s)
  62. }
  63. // Attribute describes the "a=" field which represents the primary means for
  64. // extending SDP.
  65. type Attribute struct {
  66. Key string
  67. Value string
  68. }
  69. // NewPropertyAttribute constructs a new attribute
  70. func NewPropertyAttribute(key string) Attribute {
  71. return Attribute{
  72. Key: key,
  73. }
  74. }
  75. // NewAttribute constructs a new attribute
  76. func NewAttribute(key, value string) Attribute {
  77. return Attribute{
  78. Key: key,
  79. Value: value,
  80. }
  81. }
  82. func (a Attribute) String() string {
  83. output := a.Key
  84. if len(a.Value) > 0 {
  85. output += ":" + a.Value
  86. }
  87. return output
  88. }
  89. // IsICECandidate returns true if the attribute key equals "candidate".
  90. func (a Attribute) IsICECandidate() bool {
  91. return a.Key == "candidate"
  92. }