blob: afb18cd724855cf0c1033aaa15fba8c5d3655fe2 [file] [log] [blame]
Alexandre Lision67916dd2014-01-24 13:33:04 -05001
2
3Calls
4=====
5Calls are represented by Call class.
6
7Subclassing the Call Class
8------------------------------------
9To use the Call class, normally application SHOULD create its own subclass, such as::
10
11 class MyCall : public Call
12 {
13 public:
14 MyCall(Account &acc, int call_id = PJSUA_INVALID_ID)
15 : Call(acc, call_id)
16 { }
17
18 ~MyCall()
19 { }
20
21 // Notification when call's state has changed.
22 virtual void onCallState(OnCallStateParam &prm);
23
24 // Notification when call's media state has changed.
25 virtual void onCallMediaState(OnCallMediaStateParam &prm);
26 };
27
28In its subclass, application can implement the call callbacks, which is basically used to process events related to the call, such as call state change or incoming call transfer request.
29
30Making Outgoing Calls
31--------------------------------------
32Making outgoing call is simple, just invoke makeCall() method of the Call object. Assuming you have the Account object as acc variable and destination URI string in dst_uri, you can initiate outgoing call with the snippet below::
33
34 Call *call = new MyCall(*acc);
35 CallOpParam prm(true); // Use default call settings
36 try {
37 call->makeCall(dest_uri, prm);
38 } catch(Error& err) {
39 }
40
41The snippet above creates a Call object and initiates outgoing call to dst_uri using the default call settings. Subsequent operations to the call can use the method in the call instance, and events to the call will be reported to the callback. More on the callback will be explained a bit later.
42
43Receiving Incoming Calls
44--------------------------------------
45Incoming calls are reported as onIncomingCall() of the Account class. You must derive a class from the Account class to handle incoming calls.
46
47Below is a sample code of the callback implementation::
48
49 void MyAccount::onIncomingCall(OnIncomingCallParam &iprm)
50 {
51 Call *call = new MyCall(*this, iprm.callId);
52 CallOpParam prm;
53 prm.statusCode = (pjsip_status_code)200;
54 call->answer(prm);
55 }
56
57For incoming calls, the call instance is created in the callback parameter as shown above. Application should make sure to store the call instance during the lifetime of the call (that is until the call is disconnected).
58
59Call Properties
60-------------------
61All call properties such as state, media state, remote peer information, etc. are stored as CallInfo class, which can be retrieved from the call object with using getInfo() method of the Call.
62
63Call Disconnection
64--------------------------------------
65Call disconnection event is a special event since once the callback that reports this event returns, the call is no longer valid and any operations invoked to the call object will raise error exception. Thus, it is recommended to delete the call object inside the callback.
66
67The call disconnection is reported in onCallState() method of Call and it can be detected as follows::
68
69 void MyCall::onCallState(OnCallStateParam &prm)
70 {
71 CallInfo ci = getInfo();
72 if (ci.state == PJSIP_INV_STATE_DISCONNECTED) {
73 /* Delete the call */
74 delete this;
75 }
76 }
77
78Working with Call's Audio Media
79-------------------------------------------------
80You can only operate with the call's audio media (e.g. connecting the call to the sound device in the conference bridge) when the call's audio media is ready (or active). The changes to the call's media state is reported in onCallMediaState() callback, and if the calls audio media is ready (or active) the function getMedia() will return a valid audio media.
81
82Below is a sample code to connect the call to the sound device when the media is active::
83
84 void MyCall::onCallMediaState(OnCallMediaStateParam &prm)
85 {
86 CallInfo ci = getInfo();
87 // Iterate all medias
88 for (unsigned i = 0; i < ci.media.size(); i++) {
89 if (getMedia(i)) { // Check if the media is valid
90 AudioMedia *aud_med = getMedia(i);
91 // Connect the call audio media to sound device
92 aud_med->startTransmit();
93 ->startTransmit(*aud_med);
94 }
95 }
96 }
97
98When the audio media becomes inactive (for example when the call is put on hold), there is no need to stop the audio media's transmission to/from the sound device since the call's audio media will be removed automatically from the conference bridge when it's no longer valid, and this will automatically remove all connections to/from the call.
99
100Call Operations
101--------------------------------------
102Some of the operations to the Call object, such as making outgoing call, answering, holding, sending re-INVITE, etc. Please see the reference documentation of Call for more info.
103