-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
83 lines (71 loc) · 2.04 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { StatusBar } from 'expo-status-bar';
import React, { useState, useEffect } from 'react';
import { StyleSheet, Text, View, TextInput, Button, Alert } from 'react-native';
import JsSIP from 'jssip';
import * as Permissions from 'expo-permissions';
import { Audio } from 'expo-av';
export default function App() {
const [number, setNumber] = useState('');
// Configuration for the SIP connection
const configuration = {
sockets: [new JsSIP.WebSocketInterface('')],
uri: '',
password: '',
};
const ua = new JsSIP.UA(configuration);
const requestPermissions = async () => {
const { status } = await Audio.requestPermissionsAsync();
if (status !== 'granted') {
Alert.alert('Permission not granted', 'Sorry, we need microphone permissions to make this work!');
}
}
// Handle the call initiation
const handleCall = async () => {
await requestPermissions();
ua.start();
const session = ua.call(number);
// Add event listeners
session.on('progress', (event) => {
console.log('Call is in progress');
});
session.on('confirmed', (event) => {
console.log('Call is established');
});
session.on('ended', (event) => {
console.log('Call ended with cause:', event.cause);
});
session.on('failed', (event) => {
console.log('Call failed with cause:', event.cause);
});
}
return (
<View style={styles.container}>
<Text>Enter the number to call:</Text>
<TextInput
style={styles.input}
value={number}
onChangeText={setNumber}
placeholder="Enter the number"
keyboardType="numeric"
/>
<Button title="Call" onPress={handleCall} />
<StatusBar style="auto" />
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
input: {
width: 200,
height: 40,
borderColor: 'gray',
borderWidth: 1,
margin: 10,
padding: 5
}
});