Browse Source

Send data over url instead of json text box

laramackey 5 years ago
parent
commit
1325d77534
4 changed files with 27 additions and 15 deletions
  1. 6 6
      web-client/answerScript.js
  2. 0 3
      web-client/answerer.html
  3. 7 6
      web-client/script.js
  4. 14 0
      web-client/server.js

+ 6 - 6
web-client/answerScript.js

@@ -1,12 +1,12 @@
 (function (){
-    console.log('Hello');
-    const connectRemote = document.getElementById('connectRemote')
-    connectRemote.addEventListener('click', createRemoteConnection, false)
+    const urlParams = new URLSearchParams(window.location.search);
+    const connectionParam = urlParams.get('connection')
+    const connection = JSON.parse(atob(connectionParam));
+    console.dir(connection);
+    createRemoteConnection(connection);
 })();
 
-function createRemoteConnection() {
-    const remoteDescText = document.getElementById('remoteDesc').value
-    const remoteDescJSON = JSON.parse(remoteDescText);
+function createRemoteConnection(remoteDescJSON) {
     const remoteDesc = {
         type: "offer",
         sdp: remoteDescJSON.description 

+ 0 - 3
web-client/answerer.html

@@ -5,9 +5,6 @@
     </head>
     <body>
         <h1>Web Rtc</h1>
-        <textarea id="remoteDesc" placeholder="Enter remote JSON" style="width: 500px; height: 200px"></textarea>
-        <br/>
-        <button id="connectRemote">Connect</button>
         <script src="/answerScript.js"></script>
     </body>
 </html>

+ 7 - 6
web-client/script.js

@@ -21,7 +21,12 @@ function createConnection() {
         if (e.candidate) {
             const candidate = e.candidate.candidate;
             connectionInfo.candidate = candidate;
-            document.body.append(JSON.stringify(connectionInfo));
+            const answererUrl = 'http://localhost:8000/answerer.html?connection=' + btoa(JSON.stringify(connectionInfo));
+            const createLink = document.createElement('a');
+            createLink.setAttribute('href', answererUrl);
+            createLink.setAttribute('target', 'new');
+            createLink.append('Open me ;)');
+            document.body.append(createLink);
         }
     }
     localConnection.onicecandidateerror = err => {
@@ -42,11 +47,7 @@ function createConnection() {
             type: "answer",
             sdp: remoteDescJSON.description 
         }
-        const remoteCandidate = {
-            candidate: remoteDescJSON.candidate,
-            sdpMid: "0", // Media stream ID for audio
-            sdpMLineIndex: 0 // Something to do with media
-        }
+
         console.dir(remoteDescJSON)
         localConnection.setRemoteDescription(remoteDesc).then((e) => {
             console.log(e)

+ 14 - 0
web-client/server.js

@@ -0,0 +1,14 @@
+const http = require('http');
+
+
+
+const connection = {
+    "description":"v=0\r\no=- 9134460598269614011 2 IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\na=group:BUNDLE 0\r\na=msid-semantic: WMS\r\nm=application 9 UDP/DTLS/SCTP webrtc-datachannel\r\nc=IN IP4 0.0.0.0\r\na=ice-ufrag:xlQY\r\na=ice-pwd:STMZXrUH+JPpmy86lz5Tp0YB\r\na=ice-options:trickle\r\na=fingerprint:sha-256 80:4C:CB:B5:45:89:0C:51:0A:2A:E5:AC:96:A7:53:F3:42:2B:F6:B8:1D:B0:CE:44:9F:0B:86:FC:B0:BD:94:F7\r\na=setup:actpass\r\na=mid:0\r\na=sctp-port:5000\r\na=max-message-size:262144\r\n",
+    "candidate":"candidate:269456666 1 udp 2113937151 10.0.1.185 58326 typ host generation 0 ufrag xlQY network-cost 999"
+};
+
+console.log('http://localhost:8000/answerer.html?connection=' + Buffer.from(JSON.stringify(connection)).toString('base64'));
+http.createServer(function(req, res){
+    res.writeHead(200, {'Content-Type': 'application/json'});
+    res.end(JSON.stringify());
+}).listen(3030);