emiago / sipgox

Extra libs for sipgo
BSD 2-Clause "Simplified" License
63 stars 9 forks source link

Having problem trying to set UAS to decline calls. #17

Open amzara opened 3 weeks ago

amzara commented 3 weeks ago

Hi, i'm trying to setup a loopback test. What I'm trying to achieve is have the UAS decline calls after the OnInvite handler receives an Invite. Idea is: 1) I setup a UAS and register an extension (in this case, let's say 209) to FreePBX. 2) Make a call using another extension in MicroSip (210 in this case) to FreePBX and have it redirect to the UAS 3) UAS receives the SIP invite and rejects the call (I'm using Status Code "603" to do this).

My problem is that if UAS OnInvite handler responds with "200", then everything works fine and I can receive call, but since I'm trying to decline the call I set it to 603. But if i check SNGREP on the server it receives thousands of SIP invite still eventhough I responded with "603". Any guidance on how do I do this?

My listener OnInvite =

// Handle SIP INVITE
sipServer.OnInvite(func(req *sip.Request, tx sip.ServerTransaction) {
    res := sip.NewResponseFromRequest(req, 603, "Decline", nil) // Send "Busy Here" response
    res.AppendHeader(&sip.ContactHeader{Address: sip.Uri{Host: unicastAddress, Port: sipPort}})
    res.AppendHeader(&contentTypeHeaderSDP)

    if err = tx.Respond(res); err != nil {
        panic(err)
    }
    fmt.Printf("Rejecting SIP Invite: %s\n", req.From())

})

Sample of log in the UAS: image

To reiterate, I'm trying to have the UAS reject calls. The register is working fine as I can get the call going if i set status to "200", but looking for advice on how to make the UAS reject the call upon triggering the OnInvite handler.

emiago commented 3 weeks ago

@amzara First I suggest that you use either sipgo Dialog managment or go with diago project.

The problem of handling on bare SIP can be challenging, so that is why I provided this things. Diago extends dialog managment further but you can avoid it if you do not need media handling.