snapdrop

A Progressive Web App for local file sharing
git clone http://git.hanabi.in/repos/snapdrop.git
Log | Files | Refs | README | LICENSE

commit 0c7abfbf1d3260ff6dfa72ff186030491e79e109
parent ff42ee1a3eb627a006f1657caca1f6aa3c645f49
Author: Mrigank Krishan <mrigankkrishan@gmail.com>
Date:   Wed, 28 Aug 2019 20:16:04 +0530

generate unique peer names

use unique-names-generator to generate peer names instead of relying on
UA. This prevents confusion when there are multiple clients on the network
with same UA.

Diffstat:
Mclient/scripts/ui.js | 6+-----
Mserver/index.js | 4+++-
Mserver/package-lock.json | 5+++++
Mserver/package.json | 1+
4 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/client/scripts/ui.js b/client/scripts/ui.js @@ -111,11 +111,7 @@ class PeerUI { } _name() { - if (this._peer.name.model) { - return this._peer.name.os + ' ' + this._peer.name.model; - } - this._peer.name.os = this._peer.name.os.replace('Mac OS', 'Mac'); - return this._peer.name.os + ' ' + this._peer.name.browser; + return this._peer.name.displayName; } _icon() { diff --git a/server/index.js b/server/index.js @@ -1,4 +1,5 @@ const parser = require('ua-parser-js'); +const { uniqueNamesGenerator } = require('unique-names-generator'); class SnapdropServer { @@ -187,7 +188,8 @@ class Peer { model: ua.device.model, os: ua.os.name, browser: ua.browser.name, - type: ua.device.type + type: ua.device.type, + displayName: uniqueNamesGenerator({ length: 2 }) }; } diff --git a/server/package-lock.json b/server/package-lock.json @@ -14,6 +14,11 @@ "resolved": "https://registry.npmjs.org/ua-parser-js/-/ua-parser-js-0.7.18.tgz", "integrity": "sha512-LtzwHlVHwFGTptfNSgezHp7WUlwiqb0gA9AALRbKaERfxwJoiX0A73QbTToxteIAuIaFshhgIZfqK8s7clqgnA==" }, + "unique-names-generator": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/unique-names-generator/-/unique-names-generator-3.0.0.tgz", + "integrity": "sha512-5BQhANYUKPqFnFYL1OduL7FDPiV7u5K1Lm4Z89YL4uOLH/uCNTnHkW3roFUEiEptOKt8f3uhmWnZj9w0zBXppw==" + }, "ws": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/ws/-/ws-6.0.0.tgz", diff --git a/server/package.json b/server/package.json @@ -10,6 +10,7 @@ "license": "ISC", "dependencies": { "ua-parser-js": "^0.7.18", + "unique-names-generator": "^3.0.0", "ws": "^6.0.0" } }