-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
81 lines (64 loc) · 2.08 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
let server = '';
let extension = '';
let password = '';
let socket = new JsSIP.WebSocketInterface(`wss://${server}:8089/ws`);
// Getting elements
let videoElement = document.querySelector('#videoCall');
let audioElement = document.querySelector('#audioCall');
let isCalling = document.querySelector('#isCalling')
audioElement.autoplay = true;
videoElement.autoplay = true;
let param = [
{
sockets: [socket],
uri: `sip:${extension}@${server}`,
password: password,
}
];
let userAgent = new JsSIP.UA(param);
setEvents(userAgent)
userAgent.start();
function setEvents(userAgent) {
userAgent.on('newRTCSession', data => {
let session = data.session;
isCalling.innerText = 'CALLING...'
session.on('accepted', (accepted) => {
console.log('accepted', accepted)
})
session.on('confirmed', (confirmed) => {
console.log('confirmed', confirmed)
})
session.on('ended', (ended) => {
console.log('ended', ended)
isCalling.innerText = '';
})
session.on('failed', (failed) => {
console.log('failed', failed)
isCalling.innerText = '';
})
session.on('sdp', (data) => {
console.log('sdp', data)
})
session.on('peerconnection', (connectionEvent) => {
console.log('peerconnection', connectionEvent)
session.connection.addEventListener('track', event => {
event.streams.forEach(stream => {
audioElement.srcObject = stream;
videoElement.srcObject = stream;
})
})
})
session.answer({
mediaConstraints: {
audio: true,
video: true
}
});
})
userAgent.on('registered', data => {
console.log('registered!!!', data);
})
userAgent.on('registration failed', data => {
console.log('registration failed', data);
})
}