X-Git-Url: https://git.kengrimes.com/?p=henge%2Fkiak.git;a=blobdiff_plain;f=client.js;h=6cdf1504ef6c6b407ee8b1558d2b64ec24fa836b;hp=c1956a7775420b0f207f1055594746166e51eff2;hb=a8bdc6c150c4f3417b2f18a480552a4015c248b1;hpb=3f5fce84645ec2c59aec0908807d1e9cb3e05e2d diff --git a/client.js b/client.js index c1956a7..6cdf150 100644 --- a/client.js +++ b/client.js @@ -2,8 +2,6 @@ const body = document.createElement('body') const root = document.createElement('div') document.title = "Strapp.io Client" const conf = {"iceServers": [{ "urls": "stun:stun.1.google.com:19302" }] } -let dataChannel -let hostScreen /* TODO: This is duplicated in both client.js and host.js */ function getPublicKey() { @@ -55,8 +53,8 @@ function requestHostAnswer(url, data) { /* But there is no JSON? */ request.setRequestHeader('Content-Type', 'application/json' ) request.setRequestHeader('X-Strapp-Type', 'client-sdp-offer') - request.setRequestHeader('X-Strapp-Pubkey', data.pubKey) - request.onreadystatechange = () => { + request.setRequestHeader('X-Strapp-Pubkey', data.pubKey) + request.onreadystatechange = () => { if (request.status === 200) { if(request.readyState === 4) { console.log('Client: Recieved Answer from Host') @@ -125,6 +123,7 @@ function requestHostICE(cpc, url, pubKey) { /* Create and send offer -> Send ICE Candidates -> Poll for ICE Candidates */ getPublicKey().then((cpk) => { + let dataChannel console.log('Client: Create and send offer') const cpc = new RTCPeerConnection(conf) @@ -175,13 +174,11 @@ getPublicKey().then((cpk) => { /* Triggered when Host adds track to peer connection */ cpc.ontrack = (event) => { - console.log(`track event is ${event}`) - let remoteRTPSenders = cpc.getSenders() let remoteRTPReceivers = cpc.getReceivers() - console.log(remoteRTPReceivers) - /* Add each remoteRTPSenders.track to own stream */ + let hostScreen let video = document.querySelector('video') - video.autoplay = true + /* TODO: Audio, video, or other track? */ + console.log(remoteRTPReceivers) console.log(video) hostScreen = new MediaStream([remoteRTPReceivers[0].track]) if(!video.srcObject) { @@ -189,7 +186,6 @@ getPublicKey().then((cpk) => { } console.log(hostScreen.getVideoTracks()) console.log(video.srcObject) - video.play() video.onloadedmetadata = () => { video.play() }