From 0551df6c401aad6e6cbf6f697b37e43a00269890 Mon Sep 17 00:00:00 2001 From: RobinLinus Date: Wed, 8 Feb 2017 01:41:04 +0100 Subject: [PATCH] Commit a dist folder --- .gitignore | 1 - dist/index.js | 23 + dist/package.json | 14 + dist/public/elements/elements.html | 22671 +++++++++++++++++++++++++++ dist/public/index.html | 18 + dist/public/manifest.json | 29 + dist/public/scripts/app.js | 1 + dist/public/sounds/blop.mp3 | Bin 0 -> 1992 bytes dist/public/sounds/blop.ogg | Bin 0 -> 5802 bytes dist/public/styles/main.css | 1 + dist/readme.md | 5 + dist/server/ws-server.js | 154 + 12 files changed, 22916 insertions(+), 1 deletion(-) create mode 100644 dist/index.js create mode 100644 dist/package.json create mode 100644 dist/public/elements/elements.html create mode 100644 dist/public/index.html create mode 100644 dist/public/manifest.json create mode 100644 dist/public/scripts/app.js create mode 100755 dist/public/sounds/blop.mp3 create mode 100644 dist/public/sounds/blop.ogg create mode 100644 dist/public/styles/main.css create mode 100644 dist/readme.md create mode 100644 dist/server/ws-server.js diff --git a/.gitignore b/.gitignore index 1f69570..3a1b68d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ node_modules -dist bower_components .tmp .publish/ diff --git a/dist/index.js b/dist/index.js new file mode 100644 index 0000000..11da079 --- /dev/null +++ b/dist/index.js @@ -0,0 +1,23 @@ +'use strict'; +var express = require('express'); +var compression = require('compression'); +var app = express(); +var http = require('http'); +var ExpressPeerServer = require('peer').ExpressPeerServer; +var wsServer = require('./server/ws-server.js'); + +var server = http.createServer(app); + +// Serve up content from public directory +app.use(compression()); +app.use(express.static(__dirname + '/public')); + +var port = process.env.PORT || 3002; +server.listen(port); +wsServer.create(server); +app.use('/peerjs', ExpressPeerServer(server, { + debug: true +})); + + +console.log('listening on port ' + port); diff --git a/dist/package.json b/dist/package.json new file mode 100644 index 0000000..f6c84c6 --- /dev/null +++ b/dist/package.json @@ -0,0 +1,14 @@ +{ + "private": true, + "engines": { + "node": ">=0.10.0" + }, + "dependencies": { + "binaryjs": "^0.2.1", + "compression": "^1.6.0", + "express": "^4.13.3", + "peer": "^0.2.8", + "ua-parser-js": "^0.7.10", + "ws": "^1.1.1" + } +} diff --git a/dist/public/elements/elements.html b/dist/public/elements/elements.html new file mode 100644 index 0000000..a37e388 --- /dev/null +++ b/dist/public/elements/elements.html @@ -0,0 +1,22671 @@ + + + + + + \ No newline at end of file diff --git a/dist/public/index.html b/dist/public/index.html new file mode 100644 index 0000000..3fc7401 --- /dev/null +++ b/dist/public/index.html @@ -0,0 +1,18 @@ + +Snapdrop + diff --git a/dist/public/manifest.json b/dist/public/manifest.json new file mode 100644 index 0000000..05ab83b --- /dev/null +++ b/dist/public/manifest.json @@ -0,0 +1,29 @@ +{ + "name": "Snapdrop", + "short_name": "Snapdrop", + "icons": [{ + "src": "images/touch/icon-128x128.png", + "sizes": "128x128", + "type": "image/png" + }, { + "src": "images/touch/apple-touch-icon.png", + "sizes": "152x152", + "type": "image/png" + }, { + "src": "images/touch/ms-touch-icon-144x144-precomposed.png", + "sizes": "144x144", + "type": "image/png" + }, { + "src": "images/touch/chrome-touch-icon-192x192.png", + "sizes": "192x192", + "type": "image/png" + }, { + "src": "images/touch/chrome-splashscreen-icon-384x384.png", + "sizes": "384x384", + "type": "image/png" + }], + "background_color": "#3367d6", + "start_url": "index.html", + "display": "standalone", + "theme_color": "#3367d6" +} diff --git a/dist/public/scripts/app.js b/dist/public/scripts/app.js new file mode 100644 index 0000000..27ba397 --- /dev/null +++ b/dist/public/scripts/app.js @@ -0,0 +1 @@ +!function(e){"use strict";var o=e.querySelector("#app");o.baseUrl="/",""===window.location.port,o.displayInstalledToast=function(){Polymer.dom(e).querySelector("platinum-sw-cache").disabled||Polymer.dom(e).querySelector("#caching-complete").show()},o.displayToast=function(o){var t=Polymer.dom(e).querySelector("#toast");t.text=o,t.show()},o.addEventListener("dom-change",function(){console.log("Our app is ready to rock!"),o.conn=e.querySelector("connection-wrapper")}),window.addEventListener("WebComponentsReady",function(){}),o._showAbout=function(){e.querySelector("#pages").select(1)},o._showAbout=function(){e.querySelector("#pages").select(0)}}(document); \ No newline at end of file diff --git a/dist/public/sounds/blop.mp3 b/dist/public/sounds/blop.mp3 new file mode 100755 index 0000000000000000000000000000000000000000..28a62449d56d8122521f016b9cdb8e2d445a3cb0 GIT binary patch literal 1992 zcmezWdrAre0T7Xymkw0I55(LI4D2Tu_+dZ}1}tG99R_+~U^5IHf`Lmg@DK(*z`%bP z0NQ2aLa#IhddLK6iQ)&so^jAuaZxXog*A0{zW>Hoh)QW*F@Ffe2SeZaxM zz^lN(zz9VDfLtKcq=A8fg|X4$K!An}9~)4Nf#0cWd*7?*`)B_7EPs~%K!l4`dV0tz zqeq3ujrL}m2WM%R{4rM5v~&yedpK{mYseyrI=FFUrUnec+-mQgdlms*YtjrPHeB|q&3!1|dGu*sOdm_h z{q2QcW|Tx_zZIN*DSg`O`#t+}Hfg?ps=T=>FW9LyNYaD6+5>lHzUL z`pIME!dL76ZMg1r$GULJ87)J{htD>*d|No!fPqm12CI)7U-G8?&@Qi5D z*#3~s^GAYW=BYkSp*t5&oK!zAA+o^ry-cpF_>>nfrbKdOE6v@^*K$ka`kK?Mw$T^$ z{F5&g8(i*>jos38Q8GDRQ!V9G)?;bQ?I*rGl$aWB9x_Sx=Pjc)zQ%bg5<0qDR{h_? zyxI5v|KBMo%nYB+ye?)-Nv(pWL+%@Q?bk@;ynu$!_X2_E7c?H+JlwQ2iqqk%B3f($dE-~`wdGT zT`NxsuHRp0I7~SvHrF)sS!`BQq$Af}-Vnjk%2`o?%#ByHd3$3{+x$PJ;56au+08nO z_NwsZvUqQ0NM2d`;mi?l!K%6CmrnLo{EA3oU=PjQzs*Bb>M+Q^Yz&{B{rrEcN#B6_ zmus)M$@diB$V48?CZ%~t|98abeD1!N6>KzXk{)lw@-;K> zRc_xO=NsFd@LWLKIPGTP1J#canNiYAXTGx*gqquixwg#Fzc(?+a%Sb{DU;M(=g(X@ zjgvKL$(v(L7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al 0 HcmV?d00001 diff --git a/dist/public/styles/main.css b/dist/public/styles/main.css new file mode 100644 index 0000000..6e71009 --- /dev/null +++ b/dist/public/styles/main.css @@ -0,0 +1 @@ +body,html{height:100%;width:100%;padding:0;margin:0}body{background:#fafafa;font-family:Roboto,'Helvetica Neue',Helvetica,Arial,sans-serif;color:#333;-webkit-font-smoothing:antialiased;overflow-x:hidden}#ads,#ads2{display:none}@media screen and (min-width:520px){#ads{display:block;position:absolute;top:8px;left:50%;margin-left:-150px}}@media screen and (min-width:720px){#ads{display:none}#ads2{display:block;position:absolute;bottom:4px;left:4px}} \ No newline at end of file diff --git a/dist/readme.md b/dist/readme.md new file mode 100644 index 0000000..6c01c5f --- /dev/null +++ b/dist/readme.md @@ -0,0 +1,5 @@ +# Run a Snapdrop Server +- `npm install` +- `node index.js` +- TODO: SSL connection (i.e nginx) + - ( Please do a PR if you've build an alternative index.js with a self-signed cert ) \ No newline at end of file diff --git a/dist/server/ws-server.js b/dist/server/ws-server.js new file mode 100644 index 0000000..c067053 --- /dev/null +++ b/dist/server/ws-server.js @@ -0,0 +1,154 @@ +'use strict'; +var parser = require('ua-parser-js'); + +// Start Binary.js server +var BinaryServer = require('binaryjs').BinaryServer; + +exports.create = function(server) { + + // link it to express + var bs = BinaryServer({ + server: server, + path: '/binary' + }); + + function guid() { + function s4() { + return Math.floor((1 + Math.random()) * 0x10000) + .toString(16) + .substring(1); + } + return s4() + s4() + '-' + s4() + '-' + s4() + '-' + + s4() + '-' + s4() + s4() + s4(); + } + + function getDeviceName(req) { + var ua = parser(req.headers['user-agent']); + return { + model: ua.device.model, + os: ua.os.name, + browser: ua.browser.name, + type: ua.device.type + }; + } + + function hash(text) { + // A string hashing function based on Daniel J. Bernstein's popular 'times 33' hash algorithm. + var h = 5381, + index = text.length; + while (index) { + h = (h * 33) ^ text.charCodeAt(--index); + } + return h >>> 0; + } + + function getIP(socket) { + return socket.upgradeReq.headers['x-forwarded-for'] || socket.upgradeReq.connection.remoteAddress; + } + // Wait for new user connections + bs.on('connection', function(client) { + + client.uuidRaw = guid(); + //ip is hashed to prevent injections by spoofing the 'x-forwarded-for' header + // client.hashedIp = 1; //use this to test locally + client.hashedIp = hash(getIP(client._socket)); + + client.deviceName = getDeviceName(client._socket.upgradeReq); + + // Incoming stream from browsers + client.on('stream', function(stream, meta) { + if (meta && meta.serverMsg === 'rtc-support') { + client.uuid = (meta.rtc ? 'rtc_' : '') + client.uuidRaw; + client.send({ + isSystemEvent: true, + type: 'handshake', + name: client.deviceName, + uuid: client.uuid + }); + return; + } + if (meta && meta.serverMsg === 'device-name') { + //max name length = 40 + if (meta.name && meta.name.length > 40) { + return; + } + client.name = meta.name; + return; + } + + meta.from = client.uuid; + + // broadcast to the other client + for (var id in bs.clients) { + if (bs.clients.hasOwnProperty(id)) { + var otherClient = bs.clients[id]; + if (otherClient !== client && meta.toPeer === otherClient.uuid) { + var send = otherClient.createStream(meta); + stream.pipe(send, meta); + } + } + } + }); + }); + + function forEachClient(fn) { + for (var id in bs.clients) { + if (bs.clients.hasOwnProperty(id)) { + var client = bs.clients[id]; + fn(client); + } + } + } + + + + + + function notifyBuddies() { + var locations = {}; + //group all clients by location (by public ip address) + forEachClient(function(client) { + var ip = client.hashedIp; + locations[ip] = locations[ip] || []; + locations[ip].push({ + socket: client, + contact: { + peerId: client.uuid, + name: client.name || client.deviceName, + device: client.name ? client.deviceName : undefined + } + }); + }); + //notify every location + Object.keys(locations).forEach(function(locationKey) { + //notify every client of all other clients in this location + var location = locations[locationKey]; + location.forEach(function(client) { + //all other clients + var buddies = location.reduce(function(result, otherClient) { + if (otherClient !== client) { + result.push(otherClient.contact); + } + return result; + }, []); + var currState = hash(JSON.stringify(buddies)); + console.log(currState); + var socket = client.socket; + //protocol + var msg = { + buddies: buddies, + isSystemEvent: true, + type: 'buddies' + }; + //send only if state changed + if (currState !== socket.lastState) { + socket.send(msg); + socket.lastState = currState; + return; + } + }); + }); + } + + setInterval(notifyBuddies, 3000); +};