Skip to content

Commit

Permalink
Add Record-Route support (#77)
Browse files Browse the repository at this point in the history
* add Record-Rotte support

* add Record-Rotte support

* delete .idea

Co-authored-by: duxiangbin <[email protected]>
  • Loading branch information
bean-du and duxiangbin authored Jan 24, 2022
1 parent 1b0f995 commit cc7be03
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
certs

# Binaries for programs and plugins
.idea
*.exe
*.exe~
*.dll
Expand Down
18 changes: 14 additions & 4 deletions pkg/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,9 @@ func (s *Session) ReInvite() {
}

//Bye send Bye request.
func (s *Session) Bye() {
method := sip.BYE
req := s.makeRequest(s.uaType, method, sip.MessageID(s.callID), s.request, s.response)
s.sendRequest(req)
func (s *Session) Bye() (sip.Response, error) {
req := s.makeRequest(s.uaType, sip.BYE, sip.MessageID(s.callID), s.request, s.response)
return s.sendRequest(req)
}

func (s *Session) sendRequest(req sip.Request) (sip.Response, error) {
Expand Down Expand Up @@ -363,6 +362,8 @@ func (s *Session) Provisional(statusCode sip.StatusCode, reason string) {
}

func (s *Session) makeRequest(uaType string, method sip.RequestMethod, msgID sip.MessageID, inviteRequest sip.Request, inviteResponse sip.Response) sip.Request {
var rh *sip.RouteHeader

newRequest := sip.NewRequest(
msgID,
method,
Expand All @@ -385,6 +386,15 @@ func (s *Session) makeRequest(uaType string, method sip.RequestMethod, msgID sip
newRequest.AppendHeader(s.contact)

if uaType == "UAC" {
for _, header := range s.response.Headers() {
if header.Name() == "Record-Route" {
h := header.(*sip.RecordRouteHeader)
rh = &sip.RouteHeader{
Addresses: h.Addresses,
}
}
}
newRequest.AppendHeader(rh)
if len(inviteRequest.GetHeaders("Route")) > 0 {
sip.CopyHeaders("Route", inviteRequest, newRequest)
}
Expand Down

0 comments on commit cc7be03

Please sign in to comment.