Skip to content

Commit b22ab7c

Browse files
authored
Send SDP with 200 OK for a reinvite. (#519)
1 parent 5f2c72c commit b22ab7c

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

pkg/sip/inbound.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ func (s *Server) processInvite(req *sip.Request, tx sip.ServerTransaction) (retE
351351
if existing != nil && existing.cc.InviteCSeq() < cc.InviteCSeq() {
352352
log.Infow("accepting reinvite", "sipCallID", existing.cc.ID(), "content-type", req.ContentType(), "content-length", req.ContentLength())
353353
existing.log().Infow("reinvite", "content-type", req.ContentType(), "content-length", req.ContentLength(), "cseq", cc.InviteCSeq())
354-
cc.AcceptAsKeepAlive()
354+
cc.AcceptAsKeepAlive(existing.cc.OwnSDP())
355355
return nil
356356
}
357357

@@ -1394,6 +1394,7 @@ type sipInbound struct {
13941394
referDone chan error
13951395

13961396
mu sync.RWMutex
1397+
lastSDP []byte
13971398
inviteOk *sip.Response
13981399
nextRequestCSeq uint32
13991400
referCseq uint32
@@ -1436,11 +1437,18 @@ func (c *sipInbound) drop() {
14361437
}
14371438

14381439
func (c *sipInbound) respond(status sip.StatusCode, reason string) {
1440+
c.respondWithData(status, reason, "", nil)
1441+
}
1442+
1443+
func (c *sipInbound) respondWithData(status sip.StatusCode, reason string, contentType string, body []byte) {
14391444
if c.inviteTx == nil {
14401445
return
14411446
}
14421447

1443-
r := sip.NewResponseFromRequest(c.invite, status, reason, nil)
1448+
r := sip.NewResponseFromRequest(c.invite, status, reason, body)
1449+
if typ := sip.ContentTypeHeader(contentType); typ != "" {
1450+
r.AppendHeader(&typ)
1451+
}
14441452
r.AppendHeader(sip.NewHeader("Allow", "INVITE, ACK, CANCEL, BYE, NOTIFY, REFER, MESSAGE, OPTIONS, INFO, SUBSCRIBE"))
14451453
if status >= 200 {
14461454
// For an ACK to error statuses.
@@ -1583,8 +1591,14 @@ func (c *sipInbound) accepted(inviteOK *sip.Response) {
15831591
c.inviteTx = nil
15841592
}
15851593

1586-
func (c *sipInbound) AcceptAsKeepAlive() {
1587-
c.RespondAndDrop(sip.StatusOK, "OK")
1594+
func (c *sipInbound) AcceptAsKeepAlive(sdp []byte) {
1595+
c.respondWithData(sip.StatusOK, "OK", "application/sdp", sdp)
1596+
}
1597+
1598+
func (c *sipInbound) OwnSDP() []byte {
1599+
c.mu.RLock()
1600+
defer c.mu.RUnlock()
1601+
return c.lastSDP
15881602
}
15891603

15901604
func (c *sipInbound) Accept(ctx context.Context, sdpData []byte, headers map[string]string) error {
@@ -1595,6 +1609,7 @@ func (c *sipInbound) Accept(ctx context.Context, sdpData []byte, headers map[str
15951609
if c.inviteTx == nil {
15961610
return errors.New("call already rejected")
15971611
}
1612+
c.lastSDP = sdpData
15981613
r := sip.NewResponseFromRequest(c.invite, sip.StatusOK, "OK", sdpData)
15991614

16001615
// This will effectively redirect future SIP requests to this server instance (if host address is not LB).

0 commit comments

Comments
 (0)