func(url, clientPubKey, resolve, reject )
})
}
-/* If https connection, should be already defined. If not https,*/
+
+/* TODO: duplicate in both client.js and host.js */
function getPublicKey() {
/* Check local storage for public key */
if (window.localStorage.getItem('public-key') === undefined) {
/* Poll for answer */
return pollServer(window.location, offer, pollServerTimeout)
}).then((answer) => {
- /* TODO: Extract sdp from answer ?*/
console.log(answer)
- /* State machine to parse answer */
+ /* TODO: State machine to parse answer */
cpc.setRemoteDescription(answer.sdp)
})
/* Message is offer from client */
console.log("Incoming connection " + msg)
- /* State machine to parse offer */
+ /* TODO: State machine to parse offer */
/* New Client Connection*/
hpc = new RTCPeerConnection()
pubKey: hpk
})
clients.push({
- sdp: hpc.localDescription
+ host-sdp: hpc.localDescription,
+ client-sdp: hpc.remoteDescription,
clientPubKey: msg.pubKey
})
})
document.body.innerHTML = 'Websockets not supported in your browser'
})
}
+/* TODO: duplicate in both client.js and host.jhs */
+function getPublicKey() {
+ /* Check local storage for public key */
+ if (window.localStorage.getItem('public-key') === undefined) {
+ /* If doesn't exist, generate public and private key pair, store in
+ local storage */
+ crypto.subtle.generateKey({name:'RSA-OAEP', length: 192}, true, ['encrypt', 'decrypt'])
+ .then((keyPair) => {
+ /* TODO: Do we need to store the private key as well? */
+ window.localStorage.setItem('public-key', keyPair.type.public.toString())
+ })
+ }
+ console.log(window.localStorage.getItem('public-key'))
+ return window.localStorage.getItem('public-key')
+}
httpd: undefined,
wsProtocol: opts['no-tls'] ? 'ws' : 'wss',
respond: (request,response) => {
+ console.log('server handling request')
+ console.log(request)
const serveFile = (fPath) => {
fs.readFile(fPath, { encoding: 'utf8' }, (err, data) => {
if (err || data == undefined) {
let routePath = htArgv[0].split('/')
let routeName = routePath[0]
if (routeName === '' || routeName === 'index.html')
- serveFile(opts['index'])
+ serveFile(opts['index'])
else if (routeName in opts['bindings']) {
let localPath = path.normalize(opts['bindings'][routeName].concat(path.sep + routePath.slice(1).join(path.sep)))
if (localPath.includes(opts['bindings'][routeName])) {
console.log(`SEC: ${localPath} references files not in route`)
}
}
+ /* TODO: Handle reconnecting host */
else if (routeName in router.routes) {
const route = router.routes[routeName]
- response.writeHead(200, { 'Content-Type': 'text/html' })
- response.write(`${router.skelPage[0]}${router.clientJS}${router.skelPage[1]}`)
- response.end()
- //TODO: if route.socket == undefined: have server delay this send until host connects
- // (this happens when a client connects to an active route with no currently-online host)
- route.socket.send(request.headers['x-forwarded-for'] || request.connection.remoteAddress)
+ console.log(request)
+ /* Client is INIT GET */
+ if (request) {
+ response.writeHead(200, { 'Content-Type': 'text/html' })
+ response.write(`${router.skelPage[0]}${router.clientJS}${router.skelPage[1]}`)
+ response.end()
+ //TODO: if route.socket == undefined: have server delay this send until host connects
+ // (this happens when a client connects to an active route with no currently-online host)
+ }
+ else { /* Client sent offer, waiting for answer */
+
+ }
+
}
else {
router.routes[routeName] = true