Skip to content

Commit

Permalink
Common interface for update requests.
Browse files Browse the repository at this point in the history
  • Loading branch information
dennwc committed Nov 4, 2024
1 parent bd563b4 commit 6cab604
Showing 1 changed file with 92 additions and 0 deletions.
92 changes: 92 additions & 0 deletions livekit/sip.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"fmt"
"slices"
"strings"

"google.golang.org/protobuf/proto"
)

// ToProto implements DataPacket in Go SDK.
Expand Down Expand Up @@ -287,6 +289,36 @@ func (p *SIPInboundTrunkUpdate) Apply(info *SIPInboundTrunkInfo) error {
return info.Validate()
}

type UpdateSIPOutboundTrunkRequestAction interface {
isUpdateSIPOutboundTrunkRequest_Action
Apply(info *SIPOutboundTrunkInfo) error
}

var (
_ UpdateSIPOutboundTrunkRequestAction = (*UpdateSIPOutboundTrunkRequest_Replace)(nil)
_ UpdateSIPOutboundTrunkRequestAction = (*UpdateSIPOutboundTrunkRequest_Update)(nil)
)

func (p *UpdateSIPOutboundTrunkRequest_Replace) Apply(info *SIPOutboundTrunkInfo) error {
val := p.Replace
if val == nil {
return errors.New("missing trunk")
}
if info.SipTrunkId != "" {
val.SipTrunkId = info.SipTrunkId
}
proto.Merge(info, val)
return val.Validate()
}

func (p *UpdateSIPOutboundTrunkRequest_Update) Apply(info *SIPOutboundTrunkInfo) error {
diff := p.Update
if diff == nil {
return errors.New("missing trunk update")
}
return diff.Apply(info)
}

func (p *SIPOutboundTrunkInfo) Validate() error {
if len(p.Numbers) == 0 {
return errors.New("no trunk numbers specified")
Expand Down Expand Up @@ -326,6 +358,36 @@ func (p *SIPOutboundTrunkUpdate) Apply(info *SIPOutboundTrunkInfo) error {
return info.Validate()
}

type UpdateSIPInboundTrunkRequestAction interface {
isUpdateSIPInboundTrunkRequest_Action
Apply(info *SIPInboundTrunkInfo) error
}

var (
_ UpdateSIPInboundTrunkRequestAction = (*UpdateSIPInboundTrunkRequest_Replace)(nil)
_ UpdateSIPInboundTrunkRequestAction = (*UpdateSIPInboundTrunkRequest_Update)(nil)
)

func (p *UpdateSIPInboundTrunkRequest_Replace) Apply(info *SIPInboundTrunkInfo) error {
val := p.Replace
if val == nil {
return errors.New("missing trunk")
}
if info.SipTrunkId != "" {
val.SipTrunkId = info.SipTrunkId
}
proto.Merge(info, val)
return val.Validate()
}

func (p *UpdateSIPInboundTrunkRequest_Update) Apply(info *SIPInboundTrunkInfo) error {
diff := p.Update
if diff == nil {
return errors.New("missing trunk update")
}
return diff.Apply(info)
}

func (p *CreateSIPDispatchRuleRequest) DispatchRuleInfo() *SIPDispatchRuleInfo {
if p == nil {
return nil
Expand Down Expand Up @@ -409,6 +471,36 @@ func (p *SIPDispatchRuleUpdate) Apply(info *SIPDispatchRuleInfo) error {
return info.Validate()
}

type UpdateSIPDispatchRuleRequestAction interface {
isUpdateSIPDispatchRuleRequest_Action
Apply(info *SIPDispatchRuleInfo) error
}

var (
_ UpdateSIPDispatchRuleRequestAction = (*UpdateSIPDispatchRuleRequest_Replace)(nil)
_ UpdateSIPDispatchRuleRequestAction = (*UpdateSIPDispatchRuleRequest_Update)(nil)
)

func (p *UpdateSIPDispatchRuleRequest_Replace) Apply(info *SIPDispatchRuleInfo) error {
val := p.Replace
if val == nil {
return errors.New("missing dispatch rule")
}
if info.SipDispatchRuleId != "" {
val.SipDispatchRuleId = info.SipDispatchRuleId
}
proto.Merge(info, val)
return val.Validate()
}

func (p *UpdateSIPDispatchRuleRequest_Update) Apply(info *SIPDispatchRuleInfo) error {
diff := p.Update
if diff == nil {
return errors.New("missing dispatch rule update")
}
return diff.Apply(info)
}

func (p *CreateSIPParticipantRequest) Validate() error {
if p.SipTrunkId == "" {
return errors.New("missing sip trunk id")
Expand Down

0 comments on commit 6cab604

Please sign in to comment.