| <!doctype html> |
| <html> |
| <head> |
| <meta charset="utf-8"> |
| <title>Testing basic data channel from offerer to receiver</title> |
| <script src="../../resources/testharness.js"></script> |
| <script src="../../resources/testharnessreport.js"></script> |
| </head> |
| <body> |
| <script src ="../routines.js"></script> |
| <script> |
| var localChannel; |
| var remoteChannel; |
| |
| function closeDataChannels() { |
| localChannel.close(); |
| remoteChannel.close(); |
| closeConnections(); |
| } |
| |
| function receiveMessages(event) { |
| try { |
| if (++counter === 1) |
| assert_equals(event.data, "one"); |
| else if (counter === 2) |
| assert_equals(event.data, "two"); |
| else if (counter === 3) |
| assert_equals(event.data, "three"); |
| else if (counter === 4) { |
| assert_equals(event.data, "four"); |
| closeDataChannels(); |
| finishTest(); |
| } else |
| assert_unreached(); |
| } catch(e) { |
| console.log(e); |
| } |
| } |
| |
| function sendMessages(channel) |
| { |
| channel.send("one"); |
| channel.send("two"); |
| channel.send("three"); |
| channel.send("four"); |
| } |
| |
| var finishTest; |
| promise_test((test) => { |
| counter = 0; |
| return new Promise((resolve, reject) => { |
| if (window.internals) { |
| internals.setEnumeratingAllNetworkInterfacesEnabled(true); |
| } |
| |
| finishTest = resolve; |
| createConnections((localConnection) => { |
| localChannel = localConnection.createDataChannel('sendDataChannel'); |
| localChannel.onopen = () => { sendMessages(localChannel) }; |
| }, (remoteConnection) => { |
| remoteConnection.ondatachannel = (event) => { |
| remoteChannel = event.channel; |
| remoteChannel.onmessage = receiveMessages; |
| }; |
| }, { filterOutICECandidate: (candidate) => { return candidate && candidate.candidate.toLowerCase().indexOf("tcp") == -1; } }); |
| setTimeout(() => { reject("Test timed out"); }, 5000); |
| }); |
| }, "Basic data channel exchange from offerer to receiver using TCP only"); |
| </script> |
| </body> |
| </html> |