7 Call Calls
Calls are handled by the call class
7.1 Sub-Class call class
To use the call class, the application should create subclasses such as:
classMycall: Publiccall{ Public: Mycall ( account&ACC,intcall_id =pjsua_invalid_id): Call (ACC, call_id) {}~Mycall () {}//Notification when the call's state had changed. Virtual voidOncallstate (Oncallstateparam &PRM); //Notification when Call's media state has changed. Virtual voidOncallmediastate (Oncallmediastateparam &PRM);};
In its subclasses, applications can implement call callbacks, which are basically used to handle call-related events, such as call state changes or call forwarding requests.
7.2 exhaled Making outgoing Calls
The outgoing call is simple, just call the MakeCall () method of the calling object. Assuming that the account object is used as an ACC variable and a target URI string in "Dest_uri", you can use the following code snippet to initiate the outbound call:
New Mycall (*ACC); Callopparam PRM (true// Use the default call settingstry { call- >catch(error& err) { << err.info () << Endl;}
The preceding code snippet creates a call object and starts the outbound to Dest_uri using the default calling settings. Subsequent operations on the call can use the methods in the call instance and report the call's events to the callback. More information about callbacks will be explained later.
7.3 Receiving incoming calls receiving Incoming Calls
Incoming calls will be reported as Onincomingcall () for the account class. You must derive a class from the account class to handle incoming calls.
The following is a sample code for the callback implementation:
void myaccount::onincomingcall ( onincomingcallparam &iprm)
< Span class= "P" >{call *call = new span class= "n" >mycall (*this. Callid); callopparam prmprm. StatusCode = pjsip_sc_okcall->answer (prm ); /span>
for incoming calls, create a call instance in the callback function, as shown above. the application should ensure that the call instance is stored during the call life cycle (until the call is disconnected).
7.4 Call Properties
All call properties, such as status, media status, remote peer information, and so on, are stored as Callinfo classes, which can be obtained using the GetInfo () method of calls.
7.5 Call Disconnect
A call disconnect event is a special event, because once the callback that reports this event returns, the call is no longer valid, and any action that invokes the object throws an error exception. Therefore, it is recommended that you remove the calling object from the callback.
The Oncallstate () method of call reports that calls are disconnected and can be detected as follows:
void Mycall::oncallstate (Oncallstateparam &prm) { = getInfo (); if (Ci.state = = pjsip_inv_state_disconnected) {/**/ Delete this; }}
7.6 Working with audio media for calls
When the audio media for the call is ready (or activated), only the audio media for the call (for example, a call to the sound device in the conference phone) can be used. Changes to the call media state are reported in the Oncallmediastate () callback, and the Call.getmedia () function returns valid audio media if the call to audio media is ready (or active).
The following is a sample code that connects a call to a sound device when the media is active:
voidMycall::oncallmediastate (Oncallmediastateparam &PRM) {Callinfo ci=GetInfo (); //Iterate all the call medias for(Unsigned i =0; I < ci.media.size (); i++) { if(Ci.media[i].type==pjmedia_type_audio &&Getmedia (i)) {Audiomedia*aud_med = (Audiomedia *) Getmedia (i); //Connect The call audio media to sound deviceauddevmanager& mgr =endpoint::instance (). Auddevmanager (); Aud_med-Starttransmit (Mgr.getplaybackdevmedia ()); Mgr.getcapturedevmedia (). Starttransmit (*aud_med); } }}
When the audio media becomes inactive (for example, when a call is held), there is no need to stop the audio media transfer to/from the sound device because the audio media that is called when the audio media is no longer active is automatically removed from the meeting bridge, which also automatically removes all connections from or connected to the call.
7.7 Call Operation
You can invoke the action of the call object, such as hang up, hold the call, send Re-invite, and so on. Refer to Call's reference documentation for more information.
7.8 Instant messaging (IM)
You can use Call.sendinstantmessage () to send im in a call. The Call.oninstantmessagestatus () callback method reports the transmission status of outgoing instant messages.
In addition to sending instant messages, you can also use Call.sendtypingindication () to send typing instructions.
The IM and typing instructions received in the call will be reported in the callback function Call.oninstantmessage () and Call.ontypingindication ().
Alternatively, you can send IM and phone-out instructions by using buddy.sendinstantmessage () and Buddy.sendtypingindication (). For more information, see the documentation.
Class 7.9 Reference 7.9.1 call
Class Pj::call call.
Public Functions
Call (account & acc, int call_id = pjsua_invalid_id)
PJSUA2 Development Documentation-seventh chapter call calls Class