-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcreateoffer1.html
76 lines (67 loc) · 1.91 KB
/
createoffer1.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
<!DOCTYPE html>
<html>
<head>
<title>offerToReceieveAudio/Video test</title>
</head>
<body>
offerToReceiveAudio:
<select id="offerAudio">
<option value="1">1</option>
<option value="0">0</option>
<option value="-1">-1</option>
</select>
offerToReceiveVideo:
<select id="offerVideo">
<option value="0">0</option>
<option value="1">1</option>
<option value="-1">-1</option>
</select>
<table border=1>
<tr>
<td>
<button onclick='run(false)'>Run promise-based createOffer()</button><br><br>
</td>
<td>
<button onclick='run(true)'>Run callback-based createOffer()</button><br><br>
</td>
</td>
<tr>
<td>
<textarea id="promiselabel" rows=50 cols=80></textarea>
</td>
<td>
<textarea id="callbacklabel" rows=50 cols=80></textarea>
</td>
</tr>
</table>
<script>
var audio_select = null;
var video_select = null;
var promise_label = null;
var callback_label = null;
window.onload = onLoad;
function onLoad() {
audio_select = document.getElementById("offerAudio");
video_select = document.getElementById("offerVideo");
promise_label = document.getElementById("promiselabel");
callback_label = document.getElementById("callbacklabel");
}
function run(isCallback) {
var pc = new webkitRTCPeerConnection(null);
var offer_audio = audio_select.options[audio_select.selectedIndex].value;
var offer_video = video_select.options[video_select.selectedIndex].value;
var options = {offerToReceiveAudio: offer_audio, offerToReceiveVideo: offer_video};
var label = undefined;
var onOffer = function(offer) {label.value = offer.sdp};
var onError = function(error) {label.value = "ERROR: " + error};
if (isCallback) {
label = callback_label;
pc.createOffer(onOffer, onError, options);
} else {
label = promise_label;
pc.createOffer(options).then(onOffer, onError);
}
}
</script>
</body>
</html>