now we trigger data channel after setting up events!
authorjordan lavatai <jordanlavatai@gmail.com>
Wed, 5 Jul 2017 17:12:23 +0000 (10:12 -0700)
committerjordan lavatai <jordanlavatai@gmail.com>
Wed, 5 Jul 2017 17:12:23 +0000 (10:12 -0700)
client.js

index 1f62625..956971a 100644 (file)
--- a/client.js
+++ b/client.js
@@ -123,15 +123,6 @@ function pollServerForICECandidate(cpc, url, pubKey) {
 getPublicKey().then((cpk) => {
   console.log('Client: Create and send offer')
   const cpc = new RTCPeerConnection(conf)
-  /* Start data channel */
-  dataChannel = cpc.createDataChannel("sendChannel");
-  dataChannel.onmessage = (msg) => {
-    console.log(msg.data)
-  }
-  dataChannel.onopen = () => {
-    dataChannel.send(`Hi from the Client`)
-  }
-
 
   cpc.oniceconnectionstatechange = () => {
     console.log('iceConnectionState = ' + cpc.iceConnectionState)
@@ -174,4 +165,13 @@ getPublicKey().then((cpk) => {
       console.log('error in sdp handshake: ' + err)
     })
   }
+  /* Start data channel */
+  dataChannel = cpc.createDataChannel("sendChannel");
+  dataChannel.onmessage = (msg) => {
+    console.log(msg.data)
+  }
+  dataChannel.onopen = () => {
+    dataChannel.send(`Hi from the Client`)
+  }
+
 })