diff --git a/app/elements/buddy-finder/buddy-finder.html b/app/elements/buddy-finder/buddy-finder.html index cd13a24..4af193c 100644 --- a/app/elements/buddy-finder/buddy-finder.html +++ b/app/elements/buddy-finder/buddy-finder.html @@ -1,97 +1,100 @@ - - + + + - People near by - - + + - - - - - - - - - - + + Open this page on another device + to share files. + + + diff --git a/app/elements/buddy-finder/personal-avatar.html b/app/elements/buddy-finder/personal-avatar.html new file mode 100644 index 0000000..2b8345a --- /dev/null +++ b/app/elements/buddy-finder/personal-avatar.html @@ -0,0 +1,41 @@ + + + + + + + + SnapDrop lets you share instantly with people near by. + + + Allow me to be discovered by: Everyone in this network. + + + + diff --git a/app/elements/buddy-finder/user-avatar.html b/app/elements/buddy-finder/user-avatar.html index b602ed4..64d3a4a 100644 --- a/app/elements/buddy-finder/user-avatar.html +++ b/app/elements/buddy-finder/user-avatar.html @@ -1,4 +1,4 @@ - + - + {{_displayName}} + {{status}} diff --git a/app/elements/contact-item/anonymous-contact-behavior.html b/app/elements/contact-item/anonymous-contact-behavior.html deleted file mode 100644 index d85dc68..0000000 --- a/app/elements/contact-item/anonymous-contact-behavior.html +++ /dev/null @@ -1,337 +0,0 @@ - diff --git a/app/elements/elements.html b/app/elements/elements.html index 795ebc3..22b422d 100644 --- a/app/elements/elements.html +++ b/app/elements/elements.html @@ -1,15 +1,15 @@ + - + - - + diff --git a/app/elements/file-sharing/file-button-behavior.html b/app/elements/file-sharing/file-button-behavior.html index 931700f..3c81e65 100644 --- a/app/elements/file-sharing/file-button-behavior.html +++ b/app/elements/file-sharing/file-button-behavior.html @@ -8,6 +8,7 @@ Chat.FileButtonBehaviorImpl = { if (!fileInput) { fileInput = document.createElement('input'); fileInput.type = 'file'; + fileInput.multiple = 'true'; fileInput.className = 'fileInput'; fileInput.style.position = 'fixed'; fileInput.style.top = '-10000px'; diff --git a/app/elements/file-sharing/file-button.html b/app/elements/file-sharing/file-button.html index 9059907..457c5b8 100644 --- a/app/elements/file-sharing/file-button.html +++ b/app/elements/file-sharing/file-button.html @@ -1,4 +1,4 @@ - + diff --git a/app/elements/file-sharing/file-drop-behavior.html b/app/elements/file-sharing/file-drop-behavior.html index 388ea12..a1ac1ad 100644 --- a/app/elements/file-sharing/file-drop-behavior.html +++ b/app/elements/file-sharing/file-drop-behavior.html @@ -25,7 +25,7 @@ Chat.FileDropBehaviorImpl = { dropZone.addEventListener('drop', function(event) { event.stopPropagation(); event.preventDefault(); - + //call dragend dragEnd(); @@ -36,5 +36,13 @@ Chat.FileDropBehaviorImpl = { }); } }; +document.body.addEventListener('dragover', function(e) { + e.stopPropagation(); + e.preventDefault(); +}, false); +document.body.addEventListener('drop', function(event) { + event.stopPropagation(); + event.preventDefault(); +}); Chat.FileDropBehavior = [Chat.FileDropBehaviorImpl, Chat.FileSelectionBehavior]; diff --git a/app/elements/file-sharing/file-receiver.html b/app/elements/file-sharing/file-receiver.html index 5e03bc0..edfc6dc 100644 --- a/app/elements/file-sharing/file-receiver.html +++ b/app/elements/file-sharing/file-receiver.html @@ -2,51 +2,94 @@ + + - - File Received - You received file {{file.name}} + + Download File + {{file.name}} - Dismiss - Download + Discard + Download + + + + File Received + Right Click and "Save as"... + + Discard + + Download + diff --git a/app/elements/file-sharing/file-saver.html b/app/elements/file-sharing/file-saver.html new file mode 100644 index 0000000..4d0896c --- /dev/null +++ b/app/elements/file-sharing/file-saver.html @@ -0,0 +1,4 @@ + \ No newline at end of file diff --git a/app/elements/file-sharing/file-selection-behavior.html b/app/elements/file-sharing/file-selection-behavior.html index 17440a8..99ff34b 100644 --- a/app/elements/file-sharing/file-selection-behavior.html +++ b/app/elements/file-sharing/file-selection-behavior.html @@ -3,22 +3,16 @@ window.Chat = window.Chat || {}; Chat.FileSelectionBehavior = { notifyFilesSelection: function(files) { - if(!files){ + if (!files) { console.log('no files selected...'); return; } for (var i = 0; i < files.length; i++) { var file = files[i]; - var reader = new FileReader(); - reader.onload = function(e2) { - // finished reading file data. - console.log('file dropped'); - this.fire('file-selected', { - dataURI: e2.target.result, - name: file.name - }); - }.bind(this); - reader.readAsDataURL(file); // start reading the file data. + this.fire('file-selected', { + file: file, + name: file.name + }); } } }; diff --git a/app/elements/p2p-network/binaryjs.html b/app/elements/p2p-network/binaryjs.html new file mode 100644 index 0000000..8dbd0c8 --- /dev/null +++ b/app/elements/p2p-network/binaryjs.html @@ -0,0 +1,1572 @@ + \ No newline at end of file diff --git a/app/elements/p2p-network/connection-wrapper.html b/app/elements/p2p-network/connection-wrapper.html new file mode 100644 index 0000000..b54e20c --- /dev/null +++ b/app/elements/p2p-network/connection-wrapper.html @@ -0,0 +1,59 @@ + + + + + + + + + diff --git a/app/elements/p2p-network/file-transfer-protocol.html b/app/elements/p2p-network/file-transfer-protocol.html new file mode 100644 index 0000000..e8d893f --- /dev/null +++ b/app/elements/p2p-network/file-transfer-protocol.html @@ -0,0 +1,137 @@ + diff --git a/app/elements/p2p-network/p2p-network.html b/app/elements/p2p-network/p2p-network.html index de07c24..a26ae8b 100644 --- a/app/elements/p2p-network/p2p-network.html +++ b/app/elements/p2p-network/p2p-network.html @@ -1,4 +1,5 @@ - + + @@ -30,7 +31,7 @@ path: 'peerjs', secure: true }; - this._peer = new Peer(options); + this._peer = new Peer(this.me,options); this._peer.on('open', function(id) { console.log('My peer ID is: ' + id); this.set('me', id); @@ -65,12 +66,22 @@ if (c.label === 'file') { c.on('data', function(data) { - console.log('received!', data); + console.log(data); + var dataView = new Uint8Array(data.file); + var dataBlob = new Blob([dataView]); this.fire('file-received', { - peer: peer, - dataURI: data.dataURI, + from: peer, + blob: dataBlob, name: data.name, }); + + }.bind(this)); + } + + if (c.label === 'system') { + c.on('data', function(data) { + data.from = peer; + this.fire('system-event', data); }.bind(this)); } }, @@ -78,15 +89,32 @@ function request(requestedPeer, callback) { return function() { + //system messages channel + var s = this._peer.connect(requestedPeer, { + label: 'system' + }); + + s.on('open', function() { + this.connect(s); + if (callback) { + callback(); + } + }.bind(this)); + s.on('error', function(err) { + console.log(err); + if (err.message.indexOf('Connection is not open') > -1) { + console.err('Handle this error!!'); + } + }); + + //files channel var f = this._peer.connect(requestedPeer, { label: 'file', reliable: true }); f.on('open', function() { this.connect(f); - if (callback) { - callback(); - } + }.bind(this)); f.on('error', function(err) { console.log(err); @@ -98,7 +126,6 @@ callback(); return; } - this.set('loading', true); if (this._peerOpen) { request(requestedPeer, callback).bind(this)(); } else { @@ -107,7 +134,7 @@ }; }()), - sendFile: function(peerId, file) { + _sendFile: function(peerId, file) { var conns = this._peer.connections[peerId]; if (conns) { conns.forEach(function(conn) { @@ -115,7 +142,17 @@ conn.send(file); console.log('file send'); } - }); + }.bind(this)); + } + }, + _sendSystemEvent: function(peerId, msg) { + var conns = this._peer.connections[peerId]; + if (conns) { + conns.forEach(function(conn) { + if (conn.label === 'system') { + conn.send(msg); + } + }.bind(this)); } } }); diff --git a/app/elements/p2p-network/web-socket.html b/app/elements/p2p-network/web-socket.html new file mode 100644 index 0000000..23bdb7e --- /dev/null +++ b/app/elements/p2p-network/web-socket.html @@ -0,0 +1,82 @@ + + + + + + + diff --git a/app/favicon.ico b/app/favicon.ico index 4887394..ef96003 100644 Binary files a/app/favicon.ico and b/app/favicon.ico differ diff --git a/app/images/touch/apple-touch-icon.png b/app/images/touch/apple-touch-icon.png index 243b899..88c28b3 100644 Binary files a/app/images/touch/apple-touch-icon.png and b/app/images/touch/apple-touch-icon.png differ diff --git a/app/images/touch/chrome-splashscreen-icon-384x384.png b/app/images/touch/chrome-splashscreen-icon-384x384.png index 436e9b9..8618175 100644 Binary files a/app/images/touch/chrome-splashscreen-icon-384x384.png and b/app/images/touch/chrome-splashscreen-icon-384x384.png differ diff --git a/app/images/touch/chrome-touch-icon-192x192.png b/app/images/touch/chrome-touch-icon-192x192.png index 6a5e101..d403fe7 100644 Binary files a/app/images/touch/chrome-touch-icon-192x192.png and b/app/images/touch/chrome-touch-icon-192x192.png differ diff --git a/app/images/touch/icon-128x128.png b/app/images/touch/icon-128x128.png index 4364903..35ce743 100644 Binary files a/app/images/touch/icon-128x128.png and b/app/images/touch/icon-128x128.png differ diff --git a/app/images/touch/logo.png b/app/images/touch/logo.png new file mode 100644 index 0000000..22cd7a6 Binary files /dev/null and b/app/images/touch/logo.png differ diff --git a/app/images/touch/ms-icon-144x144.png b/app/images/touch/ms-icon-144x144.png index cb9f44c..85c7bb6 100644 Binary files a/app/images/touch/ms-icon-144x144.png and b/app/images/touch/ms-icon-144x144.png differ diff --git a/app/images/touch/ms-touch-icon-144x144-precomposed.png b/app/images/touch/ms-touch-icon-144x144-precomposed.png index cb9f44c..6d595cd 100644 Binary files a/app/images/touch/ms-touch-icon-144x144-precomposed.png and b/app/images/touch/ms-touch-icon-144x144-precomposed.png differ diff --git a/app/index.html b/app/index.html index c19ea7e..fa615be 100644 --- a/app/index.html +++ b/app/index.html @@ -4,12 +4,12 @@ - - - Share With Me! + + + SnapDrop! - + @@ -21,7 +21,7 @@ - + @@ -29,23 +29,23 @@ - + - - - + + - + + - - + + + - - Ok + diff --git a/app/manifest.json b/app/manifest.json index 80b9029..6a84718 100644 --- a/app/manifest.json +++ b/app/manifest.json @@ -1,28 +1,30 @@ { - "name": "Share With Me", - "short_name": "Share With Me", - "icons": [{ + "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": "#3E4EB8", - "display": "standalone", - "theme_color": "#2E3AA1" + }], + "background_color": "#3367d6", + "start_url": "index.html", + "display": "standalone", + "theme_color": "#3367d6", + "orientation": "portrait" } diff --git a/app/scripts/animated-bg.js b/app/scripts/animated-bg.js new file mode 100644 index 0000000..436e24c --- /dev/null +++ b/app/scripts/animated-bg.js @@ -0,0 +1,64 @@ +'use strict'; +(function() { + var requestAnimFrame = (function() { + return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || + function(callback) { + window.setTimeout(callback, 1000 / 60); + }; + })(); + var c = document.createElement('canvas'); + document.body.appendChild(c); + var style = c.style; + style.width = '100%'; + style.position = 'absolute'; + var ctx = c.getContext('2d'); + var x0, y0, w, h, dw; + + function init() { + w = window.innerWidth; + h = window.innerHeight; + c.width = w; + c.height = h; + x0 = w / 2; + y0 = h - 103; + dw = Math.max(w, h, 1000) / 13; + drawCircles(); + } + window.onresize = init; + + function drawCicrle(radius) { + ctx.beginPath(); + var color = Math.round(255 * (1- radius / Math.max(w, h))); + ctx.strokeStyle = 'rgba(' + color + ',' + color + ',' + color + ',0.1)'; + ctx.arc(x0, y0, radius, 0, 2 * Math.PI); + ctx.stroke(); + ctx.lineWidth = 2; + } + + var step = 0; + + function drawCircles() { + ctx.clearRect(0, 0, w, h); + for (var i = 0; i < 8; i++) { + drawCicrle(dw * i + step % dw); + } + step += 1; + } + + var loading = true; + + function animate() { + if (loading || step % dw < dw - 5) { + requestAnimFrame(function() { + drawCircles(); + animate(); + }); + } + } + window.anim = function(l) { + loading = l; + animate(); + }; + init(); + animate(); +}()); diff --git a/app/scripts/app.js b/app/scripts/app.js index 40c1152..9ae759b 100644 --- a/app/scripts/app.js +++ b/app/scripts/app.js @@ -21,17 +21,25 @@ } }; + app.displayToast = function(msg) { + var toast = Polymer.dom(document).querySelector('#toast'); + toast.text = msg; + toast.show(); + }; + // Listen for template bound event to know when bindings // have resolved and content has been stamped to the page app.addEventListener('dom-change', function() { console.log('Our app is ready to rock!'); + app.p2p = document.querySelector('connection-wrapper'); }); // See https://github.com/Polymer/polymer/issues/1381 window.addEventListener('WebComponentsReady', function() { // imports are loaded and elements have been registered - app.p2p = document.querySelector('p2p-network'); }); + + })(document); diff --git a/app/styles/app-theme.html b/app/styles/app-theme.html index 646782d..f2c5d67 100644 --- a/app/styles/app-theme.html +++ b/app/styles/app-theme.html @@ -1,214 +1,31 @@ - - - diff --git a/app/styles/icons.html b/app/styles/icons.html new file mode 100644 index 0000000..4866561 --- /dev/null +++ b/app/styles/icons.html @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/styles/main.css b/app/styles/main.css index 1c9ea79..cc5e696 100644 --- a/app/styles/main.css +++ b/app/styles/main.css @@ -1,14 +1,12 @@ -/* -Copyright (c) 2015 The Polymer Project Authors. All rights reserved. -This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt -The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt -The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt -Code distributed by Google as part of the polymer project is also -subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt -*/ +html, +body { + height: 100%; + width: 100%; +} body { - background: #fafafa; - font-family: 'Roboto', 'Helvetica Neue', Helvetica, Arial, sans-serif; - color: #333; + background: #fafafa; + font-family: 'Roboto', 'Helvetica Neue', Helvetica, Arial, sans-serif; + color: #333; + -webkit-font-smoothing: antialiased; } diff --git a/app/styles/shared-styles.html b/app/styles/shared-styles.html deleted file mode 100644 index c3ee7a2..0000000 --- a/app/styles/shared-styles.html +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - diff --git a/gulpfile.js b/gulpfile.js index 808ae9d..188d6cd 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,5 +1,3 @@ - - 'use strict'; // Include Gulp & tools we'll use @@ -17,175 +15,185 @@ var historyApiFallback = require('connect-history-api-fallback'); var packageJson = require('./package.json'); var crypto = require('crypto'); var ensureFiles = require('./tasks/ensure-files.js'); +var inlinesource = require('gulp-inline-source'); // var ghPages = require('gulp-gh-pages'); var AUTOPREFIXER_BROWSERS = [ - 'ie >= 10', - 'ie_mob >= 10', - 'ff >= 30', - 'chrome >= 34', - 'safari >= 7', - 'opera >= 23', - 'ios >= 7', - 'android >= 4.4', - 'bb >= 10' + 'ie >= 10', + 'ie_mob >= 10', + 'ff >= 30', + 'chrome >= 34', + 'safari >= 7', + 'opera >= 23', + 'ios >= 7', + 'android >= 4.4', + 'bb >= 10' ]; var DIST = 'dist'; var dist = function(subpath) { - return !subpath ? DIST : path.join(DIST, subpath); + return !subpath ? DIST : path.join(DIST, subpath); }; var styleTask = function(stylesPath, srcs) { - return gulp.src(srcs.map(function(src) { - return path.join('app', stylesPath, src); - })) - .pipe($.changed(stylesPath, {extension: '.css'})) - .pipe($.autoprefixer(AUTOPREFIXER_BROWSERS)) - .pipe(gulp.dest('.tmp/' + stylesPath)) - .pipe($.minifyCss()) - .pipe(gulp.dest(dist(stylesPath))) - .pipe($.size({title: stylesPath})); + return gulp.src(srcs.map(function(src) { + return path.join('app', stylesPath, src); + })) + .pipe($.changed(stylesPath, { + extension: '.css' + })) + .pipe($.autoprefixer(AUTOPREFIXER_BROWSERS)) + .pipe(gulp.dest('.tmp/' + stylesPath)) + .pipe($.minifyCss()) + .pipe(gulp.dest(dist(stylesPath))) + .pipe($.size({ + title: stylesPath + })); }; var imageOptimizeTask = function(src, dest) { - return gulp.src(src) - .pipe($.imagemin({ - progressive: true, - interlaced: true - })) - .pipe(gulp.dest(dest)) - .pipe($.size({title: 'images'})); + return gulp.src(src) + .pipe($.imagemin({ + progressive: true, + interlaced: true + })) + .pipe(gulp.dest(dest)) + .pipe($.size({ + title: 'images' + })); }; var optimizeHtmlTask = function(src, dest) { - var assets = $.useref.assets({ - searchPath: ['.tmp', 'app'] - }); + var assets = $.useref.assets({ + searchPath: ['.tmp', 'app'] + }); - return gulp.src(src) - .pipe(assets) - // Concatenate and minify JavaScript - .pipe($.if('*.js', $.uglify({ - preserveComments: 'some' - }))) - // Concatenate and minify styles - // In case you are still using useref build blocks - .pipe($.if('*.css', $.minifyCss())) - .pipe(assets.restore()) - .pipe($.useref()) - // Minify any HTML - .pipe($.if('*.html', $.minifyHtml({ - quotes: true, - empty: true, - spare: true - }))) - // Output files - .pipe(gulp.dest(dest)) - .pipe($.size({ - title: 'html' - })); + return gulp.src(src) + .pipe(assets) + // Concatenate and minify JavaScript + .pipe($.if('*.js', $.uglify({ + preserveComments: 'some' + }))) + // Concatenate and minify styles + // In case you are still using useref build blocks + .pipe($.if('*.css', $.minifyCss())) + .pipe(assets.restore()) + .pipe($.useref()) + // Minify any HTML + .pipe($.if('*.html', $.minifyHtml({ + quotes: true, + empty: true, + spare: true + }))) + .pipe($.if('*.html', inlinesource())) + // Output files + .pipe(gulp.dest(dest)) + .pipe($.size({ + title: 'html' + })); }; // Compile and automatically prefix stylesheets gulp.task('styles', function() { - return styleTask('styles', ['**/*.css']); + return styleTask('styles', ['**/*.css']); }); gulp.task('elements', function() { - return styleTask('elements', ['**/*.css']); + return styleTask('elements', ['**/*.css']); }); // Ensure that we are not missing required files for the project // "dot" files are specifically tricky due to them being hidden on // some systems. gulp.task('ensureFiles', function(cb) { - var requiredFiles = ['.jscsrc', '.jshintrc', '.bowerrc']; + var requiredFiles = ['.jscsrc', '.jshintrc', '.bowerrc']; - ensureFiles(requiredFiles.map(function(p) { - return path.join(__dirname, p); - }), cb); + ensureFiles(requiredFiles.map(function(p) { + return path.join(__dirname, p); + }), cb); }); // Lint JavaScript gulp.task('lint', ['ensureFiles'], function() { - return gulp.src([ - 'app/scripts/**/*.js', - 'app/elements/**/*.js', - 'app/elements/**/*.html', - 'gulpfile.js' - ]) - .pipe(reload({ - stream: true, - once: true - })) + return gulp.src([ + 'app/scripts/**/*.js', + 'app/elements/**/*.js', + 'app/elements/**/*.html', + 'gulpfile.js' + ]) + .pipe(reload({ + stream: true, + once: true + })) - // JSCS has not yet a extract option - .pipe($.if('*.html', $.htmlExtract())) - .pipe($.jshint()) - .pipe($.jscs()) - .pipe($.jscsStylish.combineWithHintResults()) - .pipe($.jshint.reporter('jshint-stylish')) - .pipe($.if(!browserSync.active, $.jshint.reporter('fail'))); + // JSCS has not yet a extract option + .pipe($.if('*.html', $.htmlExtract())) + .pipe($.jshint()) + .pipe($.jscs()) + .pipe($.jscsStylish.combineWithHintResults()) + .pipe($.jshint.reporter('jshint-stylish')) + .pipe($.if(!browserSync.active, $.jshint.reporter('fail'))); }); // Optimize images gulp.task('images', function() { - return imageOptimizeTask('app/images/**/*', dist('images')); + return imageOptimizeTask('app/images/**/*', dist('images')); }); // Copy all files at the root level (app) gulp.task('copy', function() { - var app = gulp.src([ - 'app/*', - '!app/test', - '!app/elements', - '!app/bower_components', - '!app/cache-config.json' - ], { - dot: true - }).pipe(gulp.dest(dist())); + var app = gulp.src([ + 'app/*', + '!app/test', + '!app/elements', + '!app/bower_components', + '!app/cache-config.json' + ], { + dot: true + }).pipe(gulp.dest(dist())); - // Copy over only the bower_components we need - // These are things which cannot be vulcanized - var bower = gulp.src([ - 'app/bower_components/{webcomponentsjs,platinum-sw,sw-toolbox,promise-polyfill}/**/*' - ]).pipe(gulp.dest(dist('bower_components'))); + // Copy over only the bower_components we need + // These are things which cannot be vulcanized + var bower = gulp.src([ + 'app/bower_components/{webcomponentsjs,platinum-sw,sw-toolbox,promise-polyfill}/**/*' + ]).pipe(gulp.dest(dist('bower_components'))); - return merge(app, bower) - .pipe($.size({ - title: 'copy' - })); + return merge(app, bower) + .pipe($.size({ + title: 'copy' + })); }); // Copy web fonts to dist gulp.task('fonts', function() { - return gulp.src(['app/fonts/**']) - .pipe(gulp.dest(dist('fonts'))) - .pipe($.size({ - title: 'fonts' - })); + return gulp.src(['app/fonts/**']) + .pipe(gulp.dest(dist('fonts'))) + .pipe($.size({ + title: 'fonts' + })); }); // Scan your HTML for assets & optimize them gulp.task('html', function() { - return optimizeHtmlTask( - ['app/**/*.html', '!app/{elements,test,bower_components}/**/*.html'], - dist()); + return optimizeHtmlTask( + ['app/**/*.html', '!app/{elements,test,bower_components}/**/*.html'], + dist()); }); // Vulcanize granular configuration gulp.task('vulcanize', function() { - return gulp.src('app/elements/elements.html') - .pipe($.vulcanize({ - stripComments: true, - inlineCss: true, - inlineScripts: true - })) - .pipe(gulp.dest(dist('elements'))) - .pipe($.size({title: 'vulcanize'})); + return gulp.src('app/elements/elements.html') + .pipe($.vulcanize({ + stripComments: true, + inlineCss: true, + inlineScripts: true + })) + .pipe(gulp.dest(dist('elements'))) + .pipe($.size({ + title: 'vulcanize' + })); }); // Generate config data for the element. @@ -196,121 +204,123 @@ gulp.task('vulcanize', function() { // See https://github.com/PolymerElements/polymer-starter-kit#enable-service-worker-support // for more context. gulp.task('cache-config', function(callback) { - var dir = dist(); - var config = { - cacheId: packageJson.name || path.basename(__dirname), - disabled: false - }; + var dir = dist(); + var config = { + cacheId: packageJson.name || path.basename(__dirname), + disabled: false + }; - glob([ - 'index.html', - './', - 'bower_components/webcomponentsjs/webcomponents-lite.min.js', - '{elements,scripts,styles}/**/*.*'], - {cwd: dir}, function(error, files) { - if (error) { - callback(error); - } else { - config.precache = files; + glob([ + 'index.html', + './', + 'bower_components/webcomponentsjs/webcomponents-lite.min.js', + '{elements,scripts,styles}/**/*.*' + ], { + cwd: dir + }, function(error, files) { + if (error) { + callback(error); + } else { + config.precache = files; - var md5 = crypto.createHash('md5'); - md5.update(JSON.stringify(config.precache)); - config.precacheFingerprint = md5.digest('hex'); + var md5 = crypto.createHash('md5'); + md5.update(JSON.stringify(config.precache)); + config.precacheFingerprint = md5.digest('hex'); - var configPath = path.join(dir, 'cache-config.json'); - fs.writeFile(configPath, JSON.stringify(config), callback); - } - }); + var configPath = path.join(dir, 'cache-config.json'); + fs.writeFile(configPath, JSON.stringify(config), callback); + } + }); }); // Clean output directory gulp.task('clean', function() { - return del(['.tmp', dist()]); + return del(['.tmp', dist()]); }); // Watch files for changes & reload -gulp.task('serve', [ 'styles', 'elements', 'images'], function() { - browserSync({ - port: 5000, - notify: false, - logPrefix: 'PSK', - snippetOptions: { - rule: { - match: '', - fn: function(snippet) { - return snippet; +gulp.task('serve', ['styles', 'elements', 'images'], function() { + browserSync({ + port: 5000, + notify: false, + logPrefix: 'PSK', + ghostMode: false, + snippetOptions: { + rule: { + match: '', + fn: function(snippet) { + return snippet; + } + } + }, + // Run as an https by uncommenting 'https: true' + // Note: this uses an unsigned certificate which on first access + // will present a certificate warning in the browser. + // https: true, + server: { + baseDir: ['.tmp', 'app'], + middleware: [historyApiFallback()] } - } - }, - // Run as an https by uncommenting 'https: true' - // Note: this uses an unsigned certificate which on first access - // will present a certificate warning in the browser. - // https: true, - server: { - baseDir: ['.tmp', 'app'], - middleware: [historyApiFallback()] - } - }); + }); - gulp.watch(['app/**/*.html'], reload); - gulp.watch(['app/styles/**/*.css'], ['styles', reload]); - gulp.watch(['app/elements/**/*.css'], ['elements', reload]); - gulp.watch(['app/{scripts,elements}/**/{*.js,*.html}'], ['lint']); - gulp.watch(['app/images/**/*'], reload); + gulp.watch(['app/**/*.html'], reload); + gulp.watch(['app/styles/**/*.css'], ['styles', reload]); + gulp.watch(['app/elements/**/*.css'], ['elements', reload]); + gulp.watch(['app/{scripts,elements}/**/{*.js,*.html}'], ['lint']); + gulp.watch(['app/images/**/*'], reload); }); // Build and serve the output from the dist build gulp.task('serve:dist', ['default'], function() { - browserSync({ - port: 5001, - notify: false, - logPrefix: 'PSK', - snippetOptions: { - rule: { - match: '', - fn: function(snippet) { - return snippet; - } - } - }, - // Run as an https by uncommenting 'https: true' - // Note: this uses an unsigned certificate which on first access - // will present a certificate warning in the browser. - // https: true, - server: dist(), - middleware: [historyApiFallback()] - }); + browserSync({ + port: 5001, + notify: false, + logPrefix: 'PSK', + snippetOptions: { + rule: { + match: '', + fn: function(snippet) { + return snippet; + } + } + }, + // Run as an https by uncommenting 'https: true' + // Note: this uses an unsigned certificate which on first access + // will present a certificate warning in the browser. + // https: true, + server: dist(), + middleware: [historyApiFallback()] + }); }); // Build production files, the default task gulp.task('default', ['clean'], function(cb) { - // Uncomment 'cache-config' if you are going to use service workers. - runSequence( - ['copy', 'styles'], - 'elements', - ['lint', 'images', 'fonts', 'html'], - 'vulcanize', // 'cache-config', - cb); + // Uncomment 'cache-config' if you are going to use service workers. + runSequence( + ['copy', 'styles'], + 'elements', ['images', 'fonts', 'html'], //'lint', + 'vulcanize', 'cache-config', + cb); }); // Build then deploy to GitHub pages gh-pages branch gulp.task('build-deploy-gh-pages', function(cb) { - runSequence( - 'default', - 'deploy-gh-pages', - cb); + runSequence( + 'default', + 'deploy-gh-pages', + cb); }); // Deploy to GitHub pages gh-pages branch gulp.task('deploy-gh-pages', function() { - return gulp.src(dist('**/*')) - // Check if running task from Travis CI, if so run using GH_TOKEN - // otherwise run using ghPages defaults. - .pipe($.if(process.env.TRAVIS === 'true', $.ghPages({ - remoteUrl: 'https://$GH_TOKEN@github.com/polymerelements/polymer-starter-kit.git', - silent: true, - branch: 'gh-pages' - }), $.ghPages())); + return gulp.src(dist('**/*')) + // Check if running task from Travis CI, if so run using GH_TOKEN + // otherwise run using ghPages defaults. + .pipe($.if(process.env.TRAVIS === 'true', $.ghPages({ + remoteUrl: 'https://$GH_TOKEN@github.com/polymerelements/polymer-starter-kit.git', + silent: true, + branch: 'gh-pages' + }), $.ghPages())); }); // Load tasks for web-component-tester @@ -319,5 +329,5 @@ require('web-component-tester').gulp.init(gulp); // Load custom tasks from the `tasks` directory try { - require('require-dir')('tasks'); + require('require-dir')('tasks'); } catch (err) {} diff --git a/package.json b/package.json index a577a14..f4935d2 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "gulp-html-extract": "^0.0.3", "gulp-if": "^2.0.0", "gulp-imagemin": "^2.2.1", + "gulp-inline-source": "^2.1.0", "gulp-jscs": "^3.0.0", "gulp-jscs-stylish": "^1.1.2", "gulp-jshint": "^1.6.3", @@ -39,5 +40,11 @@ }, "engines": { "node": ">=0.10.0" + }, + "dependencies": { + "binaryjs": "^0.2.1", + "express": "^4.13.3", + "ua-parser-js": "^0.7.10", + "ws": "^0.8.1" } } diff --git a/server/ws-server.js b/server/ws-server.js new file mode 100644 index 0000000..cf732db --- /dev/null +++ b/server/ws-server.js @@ -0,0 +1,106 @@ +'use strict'; +var fs = require('fs'); +var parser = require('ua-parser-js'); + +// Serve client side statically +var express = require('express'); +var app = express(); +app.use(express.static(__dirname + '/public')); + +var https = require('https'); +var server = https.createServer({ + key: fs.readFileSync('/var/www/sharewithme/ssl/privkey.pem').toString(), + cert: fs.readFileSync('/var/www/sharewithme/ssl/fullchain.pem').toString() +}, app); + +// var http = require('http'); +// var server = http.createServer(app); + +// Start Binary.js server +var BinaryServer = require('binaryjs').BinaryServer; + +// link it to express +var bs = BinaryServer({ + server: server +}); + +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 + }; +} +// Wait for new user connections +bs.on('connection', function(client) { + console.log('connection received!'); + + + client.deviceName = getDeviceName(client._socket.upgradeReq); + + // Incoming stream from browsers + client.on('stream', function(stream, meta) { + console.log('stream received!', meta); + if (meta.handshake) { + client.uuid = meta.handshake; + return; + } + meta.from = client.uuid; + + // broadcast to all other clients + 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 getIP(socket) { + return socket.upgradeReq.headers['x-forwarded-for'] || socket.upgradeReq.connection.remoteAddress; +} + +function notifyBuddies() { + //TODO: This should be possible in linear time + forEachClient(function(client1) { + var buddies = []; + var myIP = getIP(client1._socket); + forEachClient(function(client2) { + var otherIP = getIP(client2._socket); + console.log(myIP, otherIP); + if (client1 !== client2 && myIP === otherIP) { + buddies.push({ + peerId: client2.uuid, + name: client2.deviceName + }); + } + }); + var msg = { + buddies: buddies, + isSystemEvent: true, + type: 'buddies' + }; + client1.send(msg); + }); +} +setInterval(notifyBuddies, 4000); + +server.listen(9001); +console.log('HTTP and BinaryJS server started on port 9001');
You received file {{file.name}}
{{file.name}}
Right Click and "Save as"...