snapdrop

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

commit 612d8cf1ea0733499d0e55399aeaaf0e819e142d
parent ea9ce951123b2cc7ac8b577588e24fe7d9f79918
Author: RobinLinus <robinlinus@users.noreply.github.com>
Date:   Wed, 16 Dec 2020 04:16:21 +0100

Use device type as display name

Pro:
- Device types are more descriptive.
- Device types don’t change after every reload

Con:
- Device types may not be unique.

Diffstat:
Mserver/index.js | 19++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/server/index.js b/server/index.js @@ -1,5 +1,4 @@ const parser = require('ua-parser-js'); -const { uniqueNamesGenerator, animals, colors } = require('unique-names-generator'); class SnapdropServer { @@ -36,7 +35,7 @@ class SnapdropServer { } catch (e) { return; // TODO: handle malformed JSON } - + switch (message.type) { case 'disconnect': this._leaveRoom(sender); @@ -186,13 +185,22 @@ class Peer { } _setName(req) { - var ua = parser(req.headers['user-agent']); + let ua = parser(req.headers['user-agent']); + + + let displayName = ua.os.name.replace('Mac OS', 'Mac') + ' '; + if (ua.device.model) { + displayName += ua.device.model; + } else { + displayName += ua.browser.name; + } + this.name = { model: ua.device.model, os: ua.os.name, browser: ua.browser.name, type: ua.device.type, - displayName: uniqueNamesGenerator({ length: 2, separator: ' ', dictionaries: [colors, animals], style: 'capital' }) + displayName: displayName }; } @@ -231,4 +239,4 @@ class Peer { }; } -const server = new SnapdropServer(process.env.PORT || 3000); +const server = new SnapdropServer(process.env.PORT || 3000); +\ No newline at end of file