-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.html
161 lines (123 loc) · 3.77 KB
/
index.html
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<html>
<head>
<script src="jquery-2.2.3.min.js"></script>
<script src="sip-0.7.5.min.js"></script>
<script>
if (SIP.WebRTC.isSupported()) {
var mediaStream;
var mediaConstraints = {
audio: true,
video: true
};
var audioConstraints = {
audio: true,
video: false
};
<!-- Here we wait for the document to be fully loaded and ready before executing the
function -->
$(document).ready(function() {
<!-- Registers a callback on the reglink 'click' action. It then creates a new user agent
and registers. -->
$("#reglink").on('click', function(id) {
myAuth = $("#authname").val();
ua = new SIP.UA({
uri: myAuth + "@146.185.161.38",
wsServers: "wss://146.185.161.38:443",
traceSip: true,
authorizationUser: '1000',
password: '1000'
});
<!-- registers an "INVITE" callback on the useragent that has been created. Basically
if I receive an invite then accept the call and put the remote video into remoteVideo -->
ua.on("invite", function(session) {
$("#msg").html("Accepting incoming call");
session.accept({
media: {
stream: mediaStream,
render: {
remote: document.getElementById('remoteVideo'),
}
}
});
<!-- Change some HTML when the incoming call is accepted -->
session.on('accepted', function(response, cause) {
$("#msg").html("Call in Progress");
});
});
});
<!-- Registers a callback on the pstnlink 'click' action. It then sends an INVITE using the existing ua
- slight bug here on this page is that you must always REGISTER to get a ua, it should not be necessary normally -->
$("#pstnlink").on("click", function(user) {
SIP.WebRTC.getUserMedia(audioConstraints, function(stream) {
mediaStream = stream;
}, function(e) {
console.error(e);
});
$("#msg").html("Calling PSTN");
var session = ua.invite("sip:" + $("#topstn").val() + "@146.185.161.38", {
media: {
stream: mediaStream,
render: {
remote: document.getElementById('remoteAudio'),
}
}
});
session.on('accepted', function(response, cause) {
$("#msg").html("Call in Progress");
});
session.on('progress', function(response, cause) {
$("#msg").html("Ringing");
});
session.on('failed', function(response, cause) {
$("#msg").html("Call Failed");
});
});
<!-- Registers a callback on the calllink 'click' action. It then sends an INVITE using the existing ua
- slight bug here on this page is that you must always REGISTER to get a ua, it should not be necessary normally -->
$("#calllink").on("click", function(user) {
SIP.WebRTC.getUserMedia(mediaConstraints, function(stream) {
mediaStream = stream;
}, function(e) {
console.error(e);
});
$("#msg").html("Calling");
var session = ua.invite("sip:" + $("#touser").val() + "@146.185.161.38", {
media: {
stream: mediaStream,
render: {
remote: document.getElementById('remoteVideo'),
}
}
});
session.on('accepted', function(response, cause) {
$("#msg").html("Call in Progress");
});
});
});
}
</script>
<style type="text/css">
video {
width: 320px;
height: 240px;
}
</style>
</head>
<body>
<div id="controls">
<input id="authname" type="text" value="" />
<a id="reglink" href="#">Register</a>
<br />
<input id="touser" type="text" value="" />
<a id="calllink" href="#">Call</a>
<br />
<input id="topstn" type="text" value="" />
<a id="pstnlink" href="#">Call PSTN</a>
</div>
<div id="videos">
<div id="msg"></div>
<video id="remoteVideo"></video>
<audio id="remoteAudio"></audio>
</div>
</body>
</html>