Left: | ||
Right: |
OLD | NEW |
---|---|
(Empty) | |
1 title = $webrtc - ABP Test Pages | |
2 template = testcase | |
3 | |
4 {% set testcase_moreinfo = [ | |
5 ("Filter Options", "https://adblockplus.org/filters#options"), | |
6 ] %} | |
7 | |
8 | |
9 <script> | |
10 | |
11 // Borrowed from https://developer.mozilla.org/en-US/docs/Web/API/WebRTC_API/Sim ple_RTCDataChannel_sample | |
12 | |
13 function pagelog(message) { | |
14 var log = document.getElementById("testcase-fo-webrtc"); | |
15 log.innerText = log.innerText + message + "\n"; | |
16 console.log(message); | |
17 } | |
18 | |
19 function handleReceiveMessage(event) { | |
20 pagelog(event.data); | |
21 } | |
22 | |
23 function handleLocalAddCandidateSuccess() { | |
24 pagelog("handleLocalAddCandidateSuccess()") | |
25 } | |
26 | |
kzar
2018/04/19 13:08:22
Nit: Please could you remove the trailing whitespa
| |
27 function handleRemoteAddCandidateSuccess() { | |
28 pagelog("handleRemoteAddCandidateSuccess()") | |
29 } | |
30 | |
31 function handleReceiveChannelStatusChange(event) { | |
32 if (receiveChannel) { | |
33 pagelog("Receive channel's status has changed to " + receiveChannel.readySta te); | |
34 } | |
35 } | |
36 | |
37 function handleSendChannelStatusChange(event) { | |
38 if (sendChannel) { | |
39 var state = sendChannel.readyState; | |
40 | |
kzar
2018/04/19 13:08:22
Nit: Please could you remove the trailing whitespa
| |
41 if (state === "open") { | |
42 pagelog("handleSendChannelStatusChange() open") | |
43 sendChannel.send("Test Message"); | |
44 } else { | |
45 pagelog("handleSendChannelStatusChange() not open") | |
46 } | |
47 } | |
48 } | |
49 | |
50 function receiveChannelCallback(event) { | |
51 receiveChannel = event.channel; | |
52 receiveChannel.onmessage = handleReceiveMessage; | |
53 receiveChannel.onopen = handleReceiveChannelStatusChange; | |
54 receiveChannel.onclose = handleReceiveChannelStatusChange; | |
55 } | |
56 | |
57 function do_connect() { | |
58 localConnection = new RTCPeerConnection(); | |
59 | |
60 sendChannel = localConnection.createDataChannel("sendChannel"); | |
61 sendChannel.onopen = handleSendChannelStatusChange; | |
62 sendChannel.onclose = handleSendChannelStatusChange; | |
63 | |
64 remoteConnection = new RTCPeerConnection(); | |
65 remoteConnection.ondatachannel = receiveChannelCallback; | |
66 | |
67 localConnection.onicecandidate = e => !e.candidate | |
68 || remoteConnection.addIceCandidate(e.candidate) | |
69 .catch(handleAddCandidateError); | |
70 | |
71 remoteConnection.onicecandidate = e => !e.candidate | |
72 || localConnection.addIceCandidate(e.candidate) | |
73 .catch(handleAddCandidateError); | |
74 | |
75 localConnection.createOffer() | |
76 .then(offer => localConnection.setLocalDescription(offer)) | |
77 .then(() => remoteConnection.setRemoteDescription(localConnection.localDescr iption)) | |
78 .then(() => remoteConnection.createAnswer()) | |
79 .then(answer => remoteConnection.setLocalDescription(answer)) | |
80 .then(() => localConnection.setRemoteDescription(remoteConnection.localDescr iption)) | |
81 .catch(handleCreateDescriptionError); | |
82 } | |
83 | |
84 document.addEventListener('DOMContentLoaded', do_connect, false); | |
85 </script> | |
86 | |
87 <section class="site-panel"> | |
88 <h2>$webrtc</h2> | |
89 <p>Check that usage of the $webrtc filter option works as expected.</p> | |
90 </section> | |
91 | |
92 <section class="site-panel"> | |
93 <h2>Test case</h2> | |
94 <div class="testcase-container"> | |
95 <div class="testcase-row"> | |
96 <h3>WebRTC Request</h3><div id="testcase-fo-webrtc"></div> | |
97 </div> | |
98 </div> | |
99 <h3>Filters</h3> | |
100 $webrtc,domain=testpages.adblockplus.org | |
101 </section> | |
OLD | NEW |