test_dataChannel_stats.html (2047B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <script type="application/javascript" src="pc.js"></script> 5 </head> 6 <body> 7 <pre id="test"> 8 <script type="application/javascript"> 9 createHTML({ 10 bug: "1218356", 11 title: "DataChannel stats" 12 }); 13 14 runNetworkTest(function (options) { 15 const test = new PeerConnectionTest(options); 16 test.chain.remove('PC_LOCAL_CHECK_STATS'); 17 test.chain.remove('PC_REMOTE_CHECK_STATS'); 18 addInitialDataChannel(test.chain); 19 test.chain.removeAfter("PC_REMOTE_CHECK_ICE_CONNECTIONS"); 20 test.chain.insertAfter("PC_REMOTE_CHECK_ICE_CONNECTIONS", 21 async function TEST_DATA_CHANNEL_STATS(test) { 22 const channel = test.pcLocal.dataChannels[0]; 23 test.pcRemote.dataChannels[0].onbufferedamountlow = () => {}; 24 test.pcRemote.dataChannels[0].send(`Sending Message`); 25 channel.onbufferedamountlow = () => {}; 26 const event = await new Promise( r => channel.onmessage = r); 27 info(`Received message: "${event.data}"`); 28 const report = await test.pcLocal.getStats(); 29 info(`Received Stats ${JSON.stringify([...report.values()], null, 2)}\n`); 30 const stats = [...report.values()].find(block => block.type == "data-channel"); 31 info(`DataChannel stats ${JSON.stringify(stats, null, 2)}`); 32 is(stats.label, channel.label, 'DataChannel stats has correct label'); 33 is(stats.protocol, channel.protocol, 34 'DataChannel stats has correct protocol'); 35 is(stats.dataChannelIdentifier, channel.id, 36 'DataChannel stats has correct dataChannelIdentifier'); 37 is(stats.state, channel.readyState, 'DataChannel has correct state'); 38 is(stats.bytesReceived, 15, 'DataChannel has correct bytesReceived'); 39 is(stats.bytesSent, 0, 'DataChannel has correct bytesSent'); 40 is(stats.messagesReceived, 1, 41 'DataChannel has correct messagesReceived'); 42 is(stats.messagesSent, 0, 'DataChannel has correct messagesSent'); 43 }); 44 return test.run(); 45 }); 46 47 </script> 48 </pre> 49 </body> 50 </html>