forked from melio-matt/JsSIPUpgrade
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
136 lines (112 loc) · 3.31 KB
/
index.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/**
* @format
*/
/*
* SECTION WEBRTC
* This is required for webrtc compatiblity issues, it's a polyfill.
* It might not all be required with latest versions
* except for the addTrack function but better safe than sorry.
*/
import {
RTCPeerConnection,
RTCIceCandidate,
RTCSessionDescription,
// RTCView,
MediaStream,
MediaStreamTrack,
mediaDevices,
// registerGlobals
} from 'react-native-webrtc';
window.RTCPeerConnection = window.RTCPeerConnection || RTCPeerConnection;
// *****
// This is required to comply with react-native media issues
// *****
window.RTCPeerConnection.addTrack = function (track, stream) {
this.addStream(stream);
};
window.RTCIceCandidate = window.RTCIceCandidate || RTCIceCandidate;
window.RTCSessionDescription =
window.RTCSessionDescription || RTCSessionDescription;
window.MediaStream = window.MediaStream || MediaStream;
window.MediaStreamTrack = window.MediaStreamTrack || MediaStreamTrack;
window.navigator.mediaDevices = window.navigator.mediaDevices || mediaDevices;
window.navigator.getUserMedia =
window.navigator.getUserMedia || mediaDevices.getUserMedia;
/*
* END SECTION WEBRTC
*/
import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';
/*
* SECTION SIP
* This is a demo class about how to connect to a sip server.
*/
import JsSIP from 'react-native-jssip';
class Sip {
constructor() {
// Set up server config
let config = {
// WSS endpoint, like what a Kamailo server would support
'endpoint': 'wss://rcs.domain.com:8443',
// SIP username
'username': 'sip:some_username@some_sip_domain',
// SIP password
'password': 'ha1_sip_password',
// ha1 password is of format:
// ha1(username + ':' + realm + ':' + password)
}
this.client = null;
this.config = null;
this.call = null;
var socket = new JsSIP.WebSocketInterface(config.endpoint);
/* Use this if you're using plaing passwords
var configuration = {
sockets : [ socket ],
uri : config.username,
password : config.password
};
*/
// Use this if you're using ha1 passwords
var configuration = {
sockets : [ socket ],
uri : config.username,
ha1 : config.password,
realm : 'realmname.domain.com' // See SIP server config for realm
};
// Enabable this to see full console logs of SIP traffic
// It is very verbose, enable only when debugging!
JsSIP.debug.enable('JsSIP:*');
var ua = new JsSIP.UA(configuration);
this.client = ua;
ua.on('connected', () => {
console.log('connected');
});
ua.on('registered', () => {
console.log('registered');
});
ua.on('unregistered', () => {
console.log('unregistered');
});
ua.on('registrationFailed', () => {
console.log('registrationFailed');
});
ua.on('newRTCSession', (data) => {
console.log('newRTCSession');
if (data.originator === 'local') {
return;
}
// New incoming call,
// TODO: emit an event that a call is available in this service
this.call = data.session;
});
// Connect to the server
ua.start();
}
}
try {
const SipService = new Sip();
} catch (e) {
console.log(e.message);
}
AppRegistry.registerComponent(appName, () => App);