PresentationConnectionList_onconnectionavailable-manual.https.html (2643B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <title>Monitoring incoming presentation connections</title> 4 <link rel="author" title="Tomoyuki Shimizu" href="https://github.com/tomoyukilabs"> 5 <link rel="help" href="https://w3c.github.io/presentation-api/#monitoring-incoming-presentation-connections"> 6 <script src="common.js"></script> 7 <script src="support/stash.js"></script> 8 <style> 9 iframe { display: none; } 10 </style> 11 12 <p>Click the button below and select the available presentation display, to start the manual test.</p> 13 <button id="presentBtn" disabled>Start Presentation Test</button> 14 <iframe id="childFrame" sandbox="allow-scripts allow-presentation" src="support/iframe.html"></iframe> 15 16 <script> 17 let connection; 18 const presentBtn = document.getElementById('presentBtn'); 19 const child = document.getElementById('childFrame'); 20 21 child.onload = () => { presentBtn.disabled = false; }; 22 23 presentBtn.onclick = () => { 24 presentBtn.disabled = true; 25 const stash = new Stash(stashIds.toController, stashIds.toReceiver); 26 const request = new PresentationRequest('support/PresentationConnectionList_onconnectionavailable_receiving-ua.html'); 27 28 return request.start().then(c => { 29 connection = c; 30 return stash.init(); 31 }).then(() => { 32 return stash.receive(); 33 }).then(data => { 34 const result = JSON.parse(data); 35 if (result.type === 'ok') { 36 connection.close(); 37 return stash.receive(); 38 } 39 else 40 return data; 41 }).then(data => { 42 const result = JSON.parse(data); 43 if (result.type === 'ok') { 44 request.reconnect(connection.id); 45 return stash.receive(); 46 } 47 else 48 return data; 49 }).then(data => { 50 const result = JSON.parse(data); 51 if (result.type === 'ok') { 52 child.contentWindow.postMessage({ type: 'connect', id: connection.id, url: connection.url }, '*'); 53 return stash.receive(); 54 } 55 else 56 return data; 57 }).then(result => { 58 const json = JSON.parse(result); 59 60 // notify receiver's results of a parent window (e.g. test runner) 61 if (window.opener && 'completion_callback' in window.opener) { 62 window.opener.completion_callback(json.tests, json.status); 63 } 64 // display receiver's results as HTML 65 const log = document.createElement('div'); 66 log.id = 'log'; 67 log.innerHTML = json.log; 68 document.body.appendChild(log); 69 70 connection.onconnect = () => { connection.terminate(); }; 71 if (connection.state === 'closed') 72 request.reconnect(connection.id); 73 else 74 connection.terminate(); 75 }); 76 }; 77 </script>