-
Notifications
You must be signed in to change notification settings - Fork 133
Adding ability to specify per-trunk media timeouts #1534
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
alexlivekit
merged 5 commits into
main
from
alexmigolin/tel-565-allow-customers-to-specify-media-timeout
May 12, 2026
+799
−622
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| "github.com/livekit/protocol": minor | ||
| --- | ||
|
|
||
| Adding ability to specify media timeout per CreateSIPParticipant request and per Dispatch Rule. | ||
|
|
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ import ( | |
| "slices" | ||
| "strconv" | ||
| "strings" | ||
| "time" | ||
|
|
||
| "golang.org/x/text/language" | ||
| "google.golang.org/grpc/codes" | ||
|
|
@@ -16,6 +17,10 @@ import ( | |
| "github.com/livekit/protocol/utils/xtwirp" | ||
| ) | ||
|
|
||
| // MaxSIPMediaTimeout is the maximum allowed trunk / API value for media_timeout | ||
| // (no incoming RTP before the RTP path is torn down) | ||
| const MaxSIPMediaTimeout = 10 * time.Minute | ||
|
|
||
| var ( | ||
| _ xtwirp.ErrorMeta = (*SIPStatus)(nil) | ||
| _ error = (*SIPStatus)(nil) | ||
|
|
@@ -686,13 +691,19 @@ func (p *SIPDispatchRuleInfo) Validate() error { | |
| if p.Rule == nil { | ||
| return errors.New("missing rule") | ||
| } | ||
| if err := p.Media.Validate(); err != nil { | ||
| return err | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func (p *SIPDispatchRuleUpdate) Validate() error { | ||
| if err := p.TrunkIds.Validate(); err != nil { | ||
| return err | ||
| } | ||
| if err := p.Media.Validate(); err != nil { | ||
| return err | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
|
|
@@ -702,7 +713,7 @@ func (p *SIPDispatchRuleUpdate) Apply(info *SIPDispatchRuleInfo) error { | |
| } | ||
| applyListUpdate(&info.TrunkIds, p.TrunkIds) | ||
| applyUpdatePtr(&info.Rule, p.Rule) | ||
| applyUpdatePtr(&info.Media, p.Media) | ||
| applyUpdatePtr(&info.Media, p.Media) // TODO: Consider applying partial updates | ||
| applyUpdate(&info.Name, p.Name) | ||
| applyUpdate(&info.Metadata, p.Metadata) | ||
| applyUpdate(&info.MediaEncryption, p.MediaEncryption) | ||
|
|
@@ -777,16 +788,16 @@ func (p *CreateSIPParticipantRequest) Validate() error { | |
| return fmt.Errorf("DisplayName must be a valid quoted string: %w", err) | ||
| } | ||
| } | ||
|
|
||
| // Validate destination if provided | ||
| if err := p.Destination.Validate(); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if err := validateHeaders(p.Headers); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if err := p.Media.Validate(); err != nil { | ||
| return err | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
|
|
@@ -1061,20 +1072,33 @@ func (p *CreateSIPParticipantRequest) Upgrade() { | |
| p.Media = p.Media.UpgradeWith(p.MediaEncryption) | ||
| } | ||
|
|
||
| func (p *SIPMediaEncryption) Deref() SIPMediaEncryption { | ||
| if p == nil { | ||
| return SIPMediaEncryption_SIP_MEDIA_ENCRYPT_DISABLE | ||
| } | ||
| return *p | ||
| } | ||
|
Comment on lines
+1075
to
+1080
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved as-is. |
||
|
|
||
| func (p *SIPMediaConfig) Validate() error { | ||
| if p == nil { // When optional, p can be nil | ||
| return nil | ||
| } | ||
| for _, c := range p.Codecs { | ||
| if err := c.Validate(); err != nil { | ||
| return err | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func (p *SIPMediaEncryption) Deref() SIPMediaEncryption { | ||
| if p == nil { | ||
| return SIPMediaEncryption_SIP_MEDIA_ENCRYPT_DISABLE | ||
| if p.MediaTimeout != nil { | ||
| dur := p.MediaTimeout.AsDuration() | ||
| if dur < 0 { | ||
| return errors.New("media_timeout must not be negative") | ||
| } | ||
| // Zero means use default | ||
| if dur > MaxSIPMediaTimeout { | ||
| return fmt.Errorf("media_timeout must not exceed %v", MaxSIPMediaTimeout) | ||
| } | ||
| } | ||
| return *p | ||
| return nil | ||
| } | ||
|
|
||
| func (p *SIPMediaConfig) UpgradeWith(enc SIPMediaEncryption) *SIPMediaConfig { | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dennwc , we might need to revisit this to avoid it being a pain long term