Browse Source

it still works - 2s timeout

laramackey 5 years ago
parent
commit
2594e8f5d7
4 changed files with 13 additions and 1 deletions
  1. 2 1
      .vscode/settings.json
  2. 2 0
      test/p2p/offerer.cpp
  3. 6 0
      web-client/answerScript.js
  4. 3 0
      web-client/answerer.html

+ 2 - 1
.vscode/settings.json

@@ -4,6 +4,7 @@
         "iosfwd": "cpp",
         "ostream": "cpp",
         "memory": "cpp",
-        "functional": "cpp"
+        "functional": "cpp",
+        "chrono": "cpp"
     }
 }

+ 2 - 0
test/p2p/offerer.cpp

@@ -28,6 +28,7 @@
 
 using namespace rtc;
 using namespace std;
+using namespace std::chrono_literals;
 
 template <class T> weak_ptr<T> make_weak_ptr(shared_ptr<T> ptr) { return ptr; }
 
@@ -97,6 +98,7 @@ int main(int argc, char **argv) {
 			return;
 
 		while (res->body.empty()) {
+			std::this_thread::sleep_for(2s);
 			res = cli.Get("/state/json");
 		}
 

+ 6 - 0
web-client/answerScript.js

@@ -61,6 +61,12 @@ function createRemoteConnection(remoteDescJSON) {
         console.log('onDataChannel')
         const receiveChannel = e.channel;
         console.dir(receiveChannel);
+        const sendButton = document.getElementById('sendDataBtn')
+        sendButton.addEventListener('click', sendMessage, false)
+        function sendMessage() {
+            const messageText = document.getElementById('sendData').value;
+            receiveChannel.send(messageText);   
+        }
         receiveChannel.onopen = () => {
             console.log('channel open')
             receiveChannel.send('testing testing 123'); 

+ 3 - 0
web-client/answerer.html

@@ -5,6 +5,9 @@
     </head>
     <body>
         <h1>Web Rtc</h1>
+        <textarea id="sendData" placeholder="Send a message" style="width: 500px; height: 50px"></textarea>
+        <br/>
+        <button id="sendDataBtn">Send Data</button>
         <script src="/answerScript.js"></script>
     </body>
 </html>