Skip to content
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

Add on_rejected_incoming_call() callback #3683

Merged
merged 10 commits into from
Oct 3, 2023
65 changes: 65 additions & 0 deletions pjsip/include/pjsua-lib/pjsua.h
Original file line number Diff line number Diff line change
Expand Up @@ -1080,6 +1080,56 @@ typedef struct pjsua_call_setting
} pjsua_call_setting;


/**
* This will contain the information passed from the callback
* \a pjsua_on_rejected_incoming_call_cb.
*/
typedef struct pjsua_on_rejected_incoming_call_param {
/**
* Local URI.
*/
pj_str_t local_info;

/**
* Remote URI.
*/
pj_str_t remote_info;

/**
* Rejection code.
*/
int st_code;

/**
* Rejection text.
*/
pj_str_t st_text;

/**
* The original INVITE message.
*/
pjsip_rx_data *rdata;

/**
* Internal.
*/
struct {
char local_info[PJSIP_MAX_URL_SIZE];
char remote_info[PJSIP_MAX_URL_SIZE];
} buf_;

} pjsua_on_rejected_incoming_call_param;

/**
* Type of callback to be called when incoming call is rejected.
*
* @param param The rejected call information.
*
*/
typedef void (*pjsua_on_rejected_incoming_call_cb)(
const pjsua_on_rejected_incoming_call_param *param);


/**
* This structure describes application callback to receive various event
* notification from PJSUA-API. All of these callbacks are OPTIONAL,
Expand Down Expand Up @@ -1967,6 +2017,21 @@ typedef struct pjsua_callback
*/
void (*on_media_event)(pjmedia_event *event);

/**
* This callback is called when an incoming call is rejected.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix the doc.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The callback is now called only when it's internally rejected by the library, right? Will using pjsua_call_answer() also trigger the callback?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor:
make it clear in the doc that the callback is only called for calls that are internally rejected by the library. And the callback won't be called if user rejects the call using pjsua_call_answer/answer2().

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the callback will not trigger when pjsua_call_answer() is used to reject the call

* In addition to being declined explicitly using the
* #pjsua_call_answer()/#pjsua_call_answer2() method,
* the library may also automatically reject the incoming call due
* to different scenarios, e.g:
* - no available call slot.
* - no available account to handle the call.
* - when an incoming INVITE is received with, for instance, a message
* containing invalid SDP.
*
* See also #pjsua_on_rejected_incoming_call_cb.
*/
pjsua_on_rejected_incoming_call_cb on_rejected_incoming_call;

} pjsua_callback;


Expand Down
50 changes: 50 additions & 0 deletions pjsip/include/pjsua2/endpoint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,37 @@ struct OnMediaEventParam
MediaEvent ev;
};

/**
* Parameter of Endpoint::onRejectedIncomingCall() callback.
*/
struct OnRejectedIncomingCallParam
{
/**
* Local URI.
*/
std::string localInfo;

/**
* Remote URI.
*/
std::string remoteInfo;

/**
sauwming marked this conversation as resolved.
Show resolved Hide resolved
* Rejection code.
*/
int statusCode;

/**
* Rejection text.
*/
std::string reason;

/**
* The original INVITE message.
*/
SipRxData rdata;
};

/**
* This structure describes authentication challenge used in Proxy-Authenticate
* or WWW-Authenticate for digest authentication scheme.
Expand Down Expand Up @@ -1898,6 +1929,21 @@ class Endpoint
*/
virtual pj_status_t onCredAuth(OnCredAuthParam &prm);

/**
* This callback is called when an incoming call is rejected.
* In addition to being declined explicitly using the Call::answer()
* method, the library may also automatically reject the incoming call
* due to different scenarios, e.g:
* - no available call slot.
* - no available account to handle the call.
* - when an incoming INVITE is received with, for instance, a message
* containing invalid SDP.
*
* @param prm Callback parameters.
*/
virtual void onRejectedIncomingCall(OnRejectedIncomingCallParam &prm)
{ PJ_UNUSED_ARG(prm); }

private:
static Endpoint *instance_; // static instance
LogWriter *writer; // Custom writer, if any
Expand Down Expand Up @@ -2078,6 +2124,10 @@ class Endpoint
const pjsip_cred_info *cred,
const pj_str_t *method,
pjsip_digest_credential *auth);

static void on_rejected_incoming_call(
const pjsua_on_rejected_incoming_call_param *param);

friend class Account;


Expand Down
Loading
Loading