blob: bee82db493f8eb09127ffc706f3bf4e24b7c6412 [file] [log] [blame]
Alexandre Lision0e143012014-01-22 11:02:46 -05001
2
3Accounts
4=========
5​Accounts provide identity (or identities) of the user who is currently using the application. An account has one SIP Uniform Resource Identifier (URI) associated with it. In SIP terms, the identity is used as the From header in outgoing requests.
6
7Account may or may not have client registration associated with it. An account is also associated with route set and some authentication credentials, which are used when sending SIP request messages using the account. An account also has presence online status, which will be reported to remote peer when they subscribe to the account's presence, or which is published to a presence server if presence publication is enabled for the account.
8
9At least one account MUST be created in the application, since any outgoing requests require an account context. If no user association is required, application can create a userless account by calling Account.create(). A userless account identifies local endpoint instead of a particular user, and it corresponds to a particular transport ID.
10
11Also one account must be set as the default account, which will be used as the account identity when pjsua fails to match the request with any accounts using the stricter matching rules.
12
13Subclassing the Account class
14---------------------------------
15To use the Account class, normally application SHOULD create its own subclass, such as::
16
17 class MyAccount : public Account
18 {
19 public:
20 MyAccount() {}
21 ~MyAccount() {}
22
23 virtual void onRegState(OnRegStateParam &prm)
24 {
25 AccountInfo ai = getInfo();
26 cout << (ai.regIsActive? "*** Register: code=" : "*** Unregister: code=")
27 << prm.code << endl;
28
29 }
30
31 virtual void onIncomingCall(OnIncomingCallParam &iprm)
32 {
33 Call *call = new MyCall(*this, iprm.callId);
34 // Delete the call, which will also hangup the call
35 delete call;
36 }
37 };
38
39In its subclass, application can implement the account callbacks, which is basically used to process events related to the account, such as:
40
41- the status of SIP registration
42- incoming calls
43- incoming presence subscription requests
44- incoming instant message not from buddy
45
46Application needs to override the relevant callback methods in the derived class to handle these particular events.
47
48If the events are not handled, default actions will be invoked:
49
50- incoming calls will not be handled
51- incoming presence subscription requests will be accepted
52- incoming instant messages from non-buddy will be ignored
53
54Creating Userless Accounts
55--------------------------
56A userless account identifies a particular SIP endpoint rather than a particular user. Some other SIP softphones may call this peer-to-peer mode, which means that we are calling another computer via its address rather than calling a particular user ID.
57
58So for example, we might identify ourselves as "sip:192.168.0.15" (a userless account) rather than, say, "sip:bennylp@pjsip.org".
59
60In pjsua, a userless account corresponds to a particular transport. Creating userless account is very simple, all we need is the transport ID which is returned by ​Endpoint.transportCreate() method as explained in previous chapter.
61
62Here's a snippet::
63
64 AccountConfig acc_cfg;
65 acc_cfg.sipConfig.transportId = tid;
66 MyAccount *acc = new MyAccount;
67 try {
68 acc->create(acc_cfg);
69 } catch(Error& err) {
70 cout << "Account creation error: " << err.reason << endl;
71 }
72
73Once the account is created, you can use the instance as a normal account. More will be explained later.
74
75Accounts created this way will have its URI derived from the transport address. For example, if the transport address is "192.168.0.15:5080", then the account's URI for UDP transport will be "sip:192.168.0.15:5080", or "sip:192.168.0.15:5080;transport=tcp" for TCP transport.
76
77Creating Account
78----------------
79For the "normal" account, we need to configure ​AccountConfig and call ​Account.create() to create the account.
80
81At the very minimum, pjsua only requires the account's ID, which is an URI to identify the account (or in SIP terms, it's called Address of Record/AOR). Here's a snippet::
82
83 AccountConfig acc_cfg;
84 acc_cfg.idUri = "sip:test1@pjsip.org";
85 MyAccount *acc = new MyAccount;
86 try {
87 acc->create(acc_cfg);
88 } catch(Error& err) {
89 cout << "Account creation error: " << err.reason << endl;
90 }
91
92The account created above doesn't do anything except to provide identity in the "From:" header for outgoing requests. The account will not register to SIP server or anything.
93
94Typically you will want the account to authenticate and register to your SIP server so that you can receive incoming calls. To do that you will need to configure some more settings in your ​AccountConfig, something like this::
95
96 AccountConfig acc_cfg;
97 acc_cfg.idUri = "sip:test1@pjsip.org";
98 acc_cfg.regConfig.registrarUri = "sip:pjsip.org";
99 acc_cfg.sipConfig.authCreds.push_back( AuthCredInfo("digest", "*", "test1", 0, "test1") );
100 MyAccount *acc = new MyAccount;
101 try {
102 acc->create(acc_cfg);
103 } catch(Error& err) {
104 cout << "Account creation error: " << err.reason << endl;
105 }
106
107Account Configurations
108-----------------------
109There are many more settings that can be specified in ​AccountConfig, like:
110
111- AccountRegConfig, to specify registration settings, such as registrar server and retry interval.
112- AccountSipConfig, to specify SIP settings, such as credential information and proxy server.
113- AccountCallConfig, to specify call settings, such as whether reliable provisional response (SIP 100rel) is required.
114- AccountPresConfig, to specify presence settings, such as whether presence publication (PUBLISH) is enabled.
115- AccountMwiConfig, to specify MWI (Message Waiting Indication) settings.
116- AccountNatConfig, to specify NAT settings, such as whether STUN or ICE is used.
117- AccountMediaConfig, to specify media settings, such as Secure RTP (SRTP) related settings.
118- AccountVideoConfig, to specify video settings, such as default capture and render device.
119
120Please see ​AccountConfig reference documentation for more info.
121
122Account Operations
123--------------------------------------
124Some of the operations to the ​Account object:
125
126- add buddy objects
127- set account's presence online status
128- stop/start SIP registration
129
130Please see the reference documentation for Account for more info. Calls, presence, and buddy list will be explained in later sections.
131
132