Skip to content

Commit 1c83311

Browse files
Recovery Docs and rename to Wiki
1 parent 5916395 commit 1c83311

10 files changed

+521
-6
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ A [PJSIP](http://www.pjsip.org/) module for React Native.
1212

1313
## Installation
1414

15-
- [iOS](https://github.com/datso/react-native-pjsip/blob/master/docs/installation_ios.md)
16-
- [Android](https://github.com/datso/react-native-pjsip/blob/master/docs/installation_android.md)
15+
- [iOS](/wiki/installation_ios.md)
16+
- [Android](/wiki/installation_android.md)
1717

1818
## Usage
1919

@@ -92,10 +92,10 @@ endpoint.addListener("call_terminated", (newCall) => {
9292
9393
## API
9494
95-
1. [Startup](https://github.com/datso/react-native-pjsip/blob/master/docs/startup.md)
96-
2. [Accounts](https://github.com/datso/react-native-pjsip/blob/master/docs/accounts.md)
97-
3. [Calls](https://github.com/datso/react-native-pjsip/blob/master/docs/calls.md)
98-
4. [Settings](https://github.com/datso/react-native-pjsip/blob/master/docs/settings.md)
95+
1. [Startup](/wiki/startup.md)
96+
2. [Accounts](/wiki/accounts.md)
97+
3. [Calls](/wiki/calls.md)
98+
4. [Settings](/wiki/settings.md)
9999
100100
## Demo
101101
The demo project is https://github.com/datso/react-native-pjsip-app. And you will need a SIP server.

wiki/accounts.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
2+
# Events
3+
4+
All interaction from javascript to pjsip module is asynchromius.
5+
So for each action, promise will be returned.
6+
7+
# Create account
8+
9+
```
10+
let configuration = {
11+
"name": "John",
12+
"username": "sip_username",
13+
"domain": "pbx.carusto.com",
14+
"password": "****",
15+
"proxy": null,
16+
"transport": null, // Default TCP
17+
"regServer": null, // Default wildcard
18+
"regTimeout": null // Default 3600
19+
"regHeaders": {
20+
"X-Custom-Header": "Value"
21+
},
22+
"regContactParams": ";unique-device-token-id=XXXXXXXXX",
23+
"regOnAdd": false, // Default true, use false for manual REGISTRATION
24+
};
25+
26+
let endpoint = new Endpoint();
27+
let state = await endpoint.start();
28+
let account = await endpoint.createAccont(configuration);
29+
30+
// Do smth with account. For example wait until registration complete and make a call.
31+
```
32+
33+
* There is no change account method. But this functionality is easy to implement by calling delete and create account methods.
34+
35+
36+
# Remove account
37+
38+
TODO: Description
39+
40+
```
41+
let account = ...;
42+
await endpoint.deleteAccont(account);
43+
44+
await endpoint.deleteAccont(account); // There should be exception, bcs account already removed.
45+
```
46+
47+
48+
# Events
49+
50+
51+
## registration_changed
52+
53+
TODO: Answer how much times it will be executed during lifetime, with examples.
54+
55+
```
56+
57+
```
58+
59+
60+
Example: Forbidden
61+
62+
Example: Invalid host
63+
64+
65+
66+
.then((account) => {
67+
console.log("Account: ", account);
68+
69+
setTimeout(() => {
70+
endpoint.registerAccount(account, true);
71+
}, 10000);
72+
73+
setTimeout(() => {
74+
endpoint.registerAccount(account, false);
75+
}, 20000);
76+
});
77+
78+
79+
80+

wiki/android_notification_example.png

20.8 KB
Loading

wiki/android_sip_background.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Android background service
2+
3+
In order to accept incoming calls while applicaiton in background you should set `notifications` property to `true` (true by default).
4+
This will make PJSIP service run in the *foreground*, supplying the ongoing notification to be shown to the user while in this state.
5+
Without foreground notification, Android could kill PJSIP service to reclaim more memory.
6+
7+
![Android Pending Intent PjSip](android_notification_example.png)
8+
9+
```javascript
10+
let configuration = {
11+
service: {
12+
ua: Platform.select({ios: "Reachify iOS", android: "Reachify Android"}), // Default: React Native PjSip (version)
13+
notifications: true, // Creates peding notification that will allow service work while your app in background
14+
notifications: false, // Disables pending notification
15+
notifications: {
16+
account: true,
17+
call: false // Disables only call notification
18+
},
19+
notifications: {
20+
account: {
21+
title: "My cool react native app", // Default: account name
22+
text: "Here we go", // Default: account registration status
23+
info: null,
24+
ticker: null,
25+
smallIcon: null,
26+
largeIcon: null
27+
},
28+
call: {
29+
title: "Active call", // Default: "Call in Progress - %Account Name%"
30+
text: "John Doe", // Default: "%Caller Name% (%Number%)"
31+
info: null,
32+
ticker: null, // Default: "Call in Progress"
33+
smallIcon: "icon_call", // Default: R.drawable.stat_sys_phone_call
34+
largeIcon: null
35+
}
36+
}
37+
},
38+
network: {
39+
useAnyway: false, // Default: true
40+
useWifi: true, // Default: true
41+
use3g: true, // Default: false
42+
useEdge: false, // Default: false
43+
useGprs: false, // Default: false
44+
useInRoaming: false, // Default: false
45+
useOtherNetworks: true // Default: false
46+
}
47+
};
48+
let endpoint = new Endpoint();
49+
let state = await endpoint.start(configuration);
50+
// ...
51+
```
52+
53+
### smallIcon & largeIcon
54+
To use own images for nofitications, copy them into `android/app/src/main/res/mipmap-XXXX/` and set thier names into `smallIcon` and `largeIcon` without extension.
55+
For more info: [ui_guidelines/icon_design_status_bar](https://developer.android.com/guide/practices/ui_guidelines/icon_design_status_bar.html)
56+
57+
### Handle clicks to call notifications
58+
59+
Typically you should contain code that will change "route" in react-native app depending on result of `endpoint.start` command
60+
```javascript
61+
let state = await endpoint.start(configuration);
62+
let calls = state.calls; // A list of active calls
63+
64+
if (state.hasOwnProperty("notificationCallId")) {
65+
for (let c of calls) {
66+
if (c.getId() == state['notificationCallId']) {
67+
route = {name:'call', call: c};
68+
break;
69+
}
70+
}
71+
}
72+
73+
//...
74+
75+
// If true you should use slider instead of buttons for incoming call, because device was in sleep when this call comes.
76+
if (state.notificationIsFromForeground) {
77+
//...
78+
}
79+
```

wiki/calls.md

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
TODO: Introduction + links to other sections.
2+
3+
# Events
4+
5+
All interaction from javascript to pjsip module is asynchronous.
6+
So for each action, promise will be returned.
7+
8+
## call_received
9+
10+
TODO: Description
11+
12+
## call_changed
13+
14+
TODO: Description
15+
16+
## call_terminated
17+
18+
TODO: Description
19+
20+
21+
# Actions
22+
23+
## Initiate a call
24+
To be able to make a call first of all you should createAccount, and pass account instance into Endpoint.makeCall function.
25+
This function will return a promise that will be resolved when PjSIP initializes the call.
26+
27+
```
28+
let options = {
29+
headers: {
30+
"P-Assserted-Identity": "Header example",
31+
"X-UA": "React native"
32+
}
33+
}
34+
35+
let call = await endpoint.makeCall(account, destination, options);
36+
call.getId() // Use this id to detect changes and make actions
37+
38+
endpoint.addListener("call_changed", (newCall) => {
39+
if (call.getId() === newCall.getId()) {
40+
// Our call changed, do smth.
41+
}
42+
}
43+
endpoint.addListener("call_terminated", (newCall) => {
44+
if (call.getId() === newCall.getId()) {
45+
// Our call terminated
46+
}
47+
}
48+
```
49+
50+
## Answer the call
51+
52+
After answer there will be event "call_changed" that reflect the changes.
53+
If there is already active call, it will be placed on hold (so expect "call_changed" event)
54+
55+
```
56+
let options = {};
57+
let call = ...;
58+
let promise = endpoint.answerCall(call, options);
59+
promise.then(() => {
60+
// Answer complete, expect that "call_changed" will be fired.
61+
}));
62+
63+
promise.catch(() => {
64+
// Answer failed, show error
65+
});
66+
```
67+
68+
## Hangup
69+
Use this function when you have active call, and Decline for unanswered incoming calls.
70+
After successul hangup, Endpoint should fire "call_terminated" event, use it to how final call duration and status.
71+
72+
```
73+
let options = {};
74+
let call = ...;
75+
await endpoint.hangupCall(call, options);
76+
```
77+
78+
## Decline
79+
Use this function when you have unanswered incoming call.
80+
After successul decline, Endpoint should fire "call_terminated" event.
81+
82+
```
83+
let options = {};
84+
let call = ...;
85+
await endpoint.declineCall(call, options);
86+
```
87+
88+
## Hold/Unhold
89+
90+
TODO: Description
91+
After successul hold/unhold, Endpoint should fire "call_changed" event, where `isHeld` should be false or true.
92+
93+
```
94+
let options = {};
95+
let call = ...;
96+
97+
await endpoint.holdCall(call, options);
98+
await endpoint.unholdCall(call, options);
99+
```
100+
101+
## Transfer
102+
103+
TODO: Description
104+
105+
```
106+
let options = {};
107+
let call = ...;
108+
109+
await endpoint.xferCall(call, destination, options);
110+
```
111+
112+
## DTMF
113+
114+
TODO: Description
115+
116+
```
117+
let options = {};
118+
let call = ...;
119+
let key = "3";
120+
121+
await endpoint.dtmfCall(call, key, options);
122+
```

wiki/installation_android.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Android installation
2+
3+
## Step 1
4+
Add permissions & service to `android/app/src/main/AndroidManifest.xml`
5+
6+
```xml
7+
<uses-feature android:name="android.hardware.camera" />
8+
<uses-feature android:name="android.hardware.camera.autofocus"/>
9+
10+
<uses-permission android:name="android.permission.INTERNET" />
11+
<uses-permission android:name="android.permission.CAMERA" />
12+
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
13+
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>
14+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
15+
<uses-permission android:name="android.permission.WAKE_LOCK"/>
16+
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>
17+
<uses-permission android:name="android.permission.CALL_PHONE"/>
18+
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
19+
```
20+
21+
```xml
22+
<application>
23+
...
24+
<service
25+
android:name="com.carusto.ReactNativePjSip.PjSipService"
26+
android:enabled="true"
27+
android:exported="true" />
28+
...
29+
</application>
30+
```
31+
32+
## Step 2
33+
```bash
34+
react-native link
35+
```
36+
37+
## Additional step: Ability to answer incoming call without Lock Screen
38+
39+
In `android/app/src/main/java/com/xxx/MainActivity.java`
40+
41+
```java
42+
import android.view.Window;
43+
import android.view.WindowManager;
44+
import android.os.Bundle;
45+
...
46+
@Override
47+
public void onCreate(Bundle savedInstanceState) {
48+
super.onCreate(savedInstanceState);
49+
50+
Window w = getWindow();
51+
w.setFlags(
52+
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED,
53+
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
54+
);
55+
}
56+
```
57+
58+
## If Android targetSdk >= 23
59+
60+
If your Android targetSdk is 23 or above you should grant `android.permission.RECORD_AUDIO` at runtime before making/receiving an audio call.
61+
62+
To check and request Android permissions, please check out [react-native-android-permissions](https://github.com/lucasferreira/react-native-android-permissions).

0 commit comments

Comments
 (0)