From: jordan lavatai Date: Wed, 12 Jul 2017 19:13:29 +0000 (-0700) Subject: Merge branch 'master' of github.com:Jlavatai/strapp X-Git-Url: https://git.kengrimes.com/?p=henge%2Fkiak.git;a=commitdiff_plain;h=a8bdc6c150c4f3417b2f18a480552a4015c248b1;hp=-c Merge branch 'master' of github.com:Jlavatai/strapp --- a8bdc6c150c4f3417b2f18a480552a4015c248b1 diff --combined client.js index 4d1bf9a,c1956a7..6cdf150 --- a/client.js +++ b/client.js @@@ -2,6 -2,8 +2,6 @@@ const body = document.createElement('bo 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() { @@@ -53,8 -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.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') @@@ -123,7 -125,6 +123,7 @@@ function requestHostICE(cpc, url, pubKe /* 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) @@@ -174,11 -175,13 +174,11 @@@ /* 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) { @@@ -186,6 -189,7 +186,6 @@@ } console.log(hostScreen.getVideoTracks()) console.log(video.srcObject) - video.play() video.onloadedmetadata = () => { video.play() } diff --combined opts.js index 5767cf6,29a378a..d930e79 --- a/opts.js +++ b/opts.js @@@ -13,20 -13,19 +13,19 @@@ const path = require('path' */ exports = require('minimist')(process.argv.slice(2), { string: [ 'config', 'client-js', 'host-js', 'ca-cert', 'ca-key', - 'port', 'index', 'bind', 'electron', 'dedicated' + 'port', 'bind', 'electron', 'file-dir', 'dedicated' ], boolean: [ 'no-tls', 'legacy-socket' ], alias: { c: 'config', j: 'client-js', J: 'host-js', - T: 'no-tls', C: 'ca-cert', K: 'ca-key', p: 'port', - i: 'index', b: 'bind', e: 'electron', - d: 'dedicated' + d: 'file-dir', + D: 'dedicated' }, stopEarly: true, unknown: (opt) => { @@@ -42,15 -41,15 +41,15 @@@ */ exports['defaults'] = { config: '/etc/strapp.conf:~/.strapp/strapp.conf:./strapp.conf', - 'client-js': './client.js', - 'host-js': './host.js', + 'client-js': './client-test.js', + 'host-js': './host-test.js', tls: true, 'ca-cert': '../certs/cert.pem', 'ca-key': '../certs/key.pem', port: 2443, - index: './index.html', bind: 'www:./www', electron: undefined, + 'file-dir': undefined, dedicated: undefined, 'legacy-socket': false } diff --combined router.js index 411c488,8fe5235..da32c95 --- a/router.js +++ b/router.js @@@ -33,7 -33,7 +33,7 @@@ exports = httpdRoot: undefined, bindJail: undefined, - /** @func + /** @func * @summary Start main HTTP server * @desc starts up an HTTP or HTTPS server used for routing * @arg {Object} conf - object containing configuration properties @@@ -83,7 -83,7 +83,11 @@@ console.log(err) }) console.log(`HTTP${(conf.tls == undefined) ? '' : 'S'} ` + ++<<<<<<< HEAD + `Server Started on port ${conf.port}${this.httpdRoot ? ++======= + `Server Started on port ${conf.port}${this.httpdRoot ? ++>>>>>>> 3f5fce84645ec2c59aec0908807d1e9cb3e05e2d `, serving files from ${this.httpdRoot}`:''}`) }, @@@ -116,7 -116,7 +120,7 @@@ throw new Error(`${path} not found, ${routeName} not bound`) }, - /** @func + /** @func * @summary Router * @desc listens for http client requests and services routes/files * @arg {http.ClientRequest} request @@@ -127,7 -127,6 +131,10 @@@ let htArgv = request.url.slice(1).split('?') const routeName = htArgv[0].split('/')[0] let route = this.routes[routeName] ++<<<<<<< HEAD + console.log(`route is ${route}`) ++======= ++>>>>>>> 3f5fce84645ec2c59aec0908807d1e9cb3e05e2d /* If the route exists, check if we are a returning host or a new client */ if (route) { if (route.bind) { @@@ -143,9 -142,7 +150,12 @@@ request.connection.remoteAddress)) this.serveHost(response, route, htArgv) else */ ++<<<<<<< HEAD + else { ++======= ++>>>>>>> 3f5fce84645ec2c59aec0908807d1e9cb3e05e2d this.serveClient(request, response, route) + } } /* If it's a valid routename that doesn't exist, make this client a host */ else if (this.validRoutes.test(routeName)) { @@@ -214,7 -211,7 +224,7 @@@ this.serveFile(response, bind.path) }, - /** @func + /** @func * @summary Serve a route to an http client * @desc routes may be bound to the filesystem, or to an outgoing host * @arg {http.ClientRequest} request - request from the client @@@ -237,9 -234,9 +247,9 @@@ case 'client-sdp-offer': let data = '' if (pubKey) { + let data = request.headers['x-strapp-offer'] route.pendingResponses.addResponse(pubKey, response) - request.on('data', (chunk) => data += chunk) - request.on('end', () => route.socket.send(`${pubKey} ${type} ${data}`)) + route.socket.send(`${pubKey} ${type} ${data}`) } else { response.writeHead(401) @@@ -252,7 -249,7 +262,11 @@@ } }, ++<<<<<<< HEAD + /** @func ++======= + /** @func ++>>>>>>> 3f5fce84645ec2c59aec0908807d1e9cb3e05e2d * @summary Create a new route for a host * @desc makes a new route for the given route name * @arg {string} routeName - name of the new route @@@ -287,14 -284,13 +301,22 @@@ }) route.pendingResponses.addResponse = function (key, response_p) { let responses = this.get(key) || [] ++<<<<<<< HEAD + responses.push(response_p) + this.set(key, responses) ++======= + this.set(key, responses.push(response_p)) ++>>>>>>> 3f5fce84645ec2c59aec0908807d1e9cb3e05e2d } this.routes[routeName] = route this.serveHost(response, route, argv) }, ++<<<<<<< HEAD + /** @func ++======= + /** @func ++>>>>>>> 3f5fce84645ec2c59aec0908807d1e9cb3e05e2d * @summary Serve a route to an authorized http host * @desc services host application to the client, establishing a socket * @arg {http.ServerResponse} response - response object to use @@@ -383,7 -379,7 +405,7 @@@ } }, - /** @func + /** @func * @summary Serve a file to an http client after a request * @desc reads files from the system to be distributed to clients, and * buffers recently accessed files @@@ -405,8 -401,8 +427,8 @@@ response.end() }) }, - - /** @func + + /** @func * @summary Synchronize Reading Multiple Files * @desc reads an array of files into an object, whose keys are the * input filenames, and values are the data read