session_description.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. package sdp
  2. import (
  3. "fmt"
  4. "net/url"
  5. "strconv"
  6. )
  7. // SessionDescription is a a well-defined format for conveying sufficient
  8. // information to discover and participate in a multimedia session.
  9. type SessionDescription struct {
  10. // v=0
  11. // https://tools.ietf.org/html/rfc4566#section-5.1
  12. Version Version
  13. // o=<username> <sess-id> <sess-version> <nettype> <addrtype> <unicast-address>
  14. // https://tools.ietf.org/html/rfc4566#section-5.2
  15. Origin Origin
  16. // s=<session name>
  17. // https://tools.ietf.org/html/rfc4566#section-5.3
  18. SessionName SessionName
  19. // i=<session description>
  20. // https://tools.ietf.org/html/rfc4566#section-5.4
  21. SessionInformation *Information
  22. // u=<uri>
  23. // https://tools.ietf.org/html/rfc4566#section-5.5
  24. URI *url.URL
  25. // e=<email-address>
  26. // https://tools.ietf.org/html/rfc4566#section-5.6
  27. EmailAddress *EmailAddress
  28. // p=<phone-number>
  29. // https://tools.ietf.org/html/rfc4566#section-5.6
  30. PhoneNumber *PhoneNumber
  31. // c=<nettype> <addrtype> <connection-address>
  32. // https://tools.ietf.org/html/rfc4566#section-5.7
  33. ConnectionInformation *ConnectionInformation
  34. // b=<bwtype>:<bandwidth>
  35. // https://tools.ietf.org/html/rfc4566#section-5.8
  36. Bandwidth []Bandwidth
  37. // https://tools.ietf.org/html/rfc4566#section-5.9
  38. // https://tools.ietf.org/html/rfc4566#section-5.10
  39. TimeDescriptions []TimeDescription
  40. // z=<adjustment time> <offset> <adjustment time> <offset> ...
  41. // https://tools.ietf.org/html/rfc4566#section-5.11
  42. TimeZones []TimeZone
  43. // k=<method>
  44. // k=<method>:<encryption key>
  45. // https://tools.ietf.org/html/rfc4566#section-5.12
  46. EncryptionKey *EncryptionKey
  47. // a=<attribute>
  48. // a=<attribute>:<value>
  49. // https://tools.ietf.org/html/rfc4566#section-5.13
  50. Attributes []Attribute
  51. // https://tools.ietf.org/html/rfc4566#section-5.14
  52. MediaDescriptions []*MediaDescription
  53. }
  54. // Attribute returns the value of an attribute and if it exists
  55. func (s *SessionDescription) Attribute(key string) (string, bool) {
  56. for _, a := range s.Attributes {
  57. if a.Key == key {
  58. return a.Value, true
  59. }
  60. }
  61. return "", false
  62. }
  63. // Version describes the value provided by the "v=" field which gives
  64. // the version of the Session Description Protocol.
  65. type Version int
  66. func (v Version) String() string {
  67. return strconv.Itoa(int(v))
  68. }
  69. // Origin defines the structure for the "o=" field which provides the
  70. // originator of the session plus a session identifier and version number.
  71. type Origin struct {
  72. Username string
  73. SessionID uint64
  74. SessionVersion uint64
  75. NetworkType string
  76. AddressType string
  77. UnicastAddress string
  78. }
  79. func (o Origin) String() string {
  80. return fmt.Sprintf(
  81. "%v %d %d %v %v %v",
  82. o.Username,
  83. o.SessionID,
  84. o.SessionVersion,
  85. o.NetworkType,
  86. o.AddressType,
  87. o.UnicastAddress,
  88. )
  89. }
  90. // SessionName describes a structured representations for the "s=" field
  91. // and is the textual session name.
  92. type SessionName string
  93. func (s SessionName) String() string {
  94. return string(s)
  95. }
  96. // EmailAddress describes a structured representations for the "e=" line
  97. // which specifies email contact information for the person responsible for
  98. // the conference.
  99. type EmailAddress string
  100. func (e EmailAddress) String() string {
  101. return string(e)
  102. }
  103. // PhoneNumber describes a structured representations for the "p=" line
  104. // specify phone contact information for the person responsible for the
  105. // conference.
  106. type PhoneNumber string
  107. func (p PhoneNumber) String() string {
  108. return string(p)
  109. }
  110. // TimeZone defines the structured object for "z=" line which describes
  111. // repeated sessions scheduling.
  112. type TimeZone struct {
  113. AdjustmentTime uint64
  114. Offset int64
  115. }
  116. func (z TimeZone) String() string {
  117. return strconv.FormatUint(z.AdjustmentTime, 10) + " " + strconv.FormatInt(z.Offset, 10)
  118. }