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.
This commit is contained in:
parent
ea9ce95112
commit
612d8cf1ea
1 changed files with 13 additions and 5 deletions
|
@ -1,5 +1,4 @@
|
||||||
const parser = require('ua-parser-js');
|
const parser = require('ua-parser-js');
|
||||||
const { uniqueNamesGenerator, animals, colors } = require('unique-names-generator');
|
|
||||||
|
|
||||||
class SnapdropServer {
|
class SnapdropServer {
|
||||||
|
|
||||||
|
@ -186,13 +185,22 @@ class Peer {
|
||||||
}
|
}
|
||||||
|
|
||||||
_setName(req) {
|
_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 = {
|
this.name = {
|
||||||
model: ua.device.model,
|
model: ua.device.model,
|
||||||
os: ua.os.name,
|
os: ua.os.name,
|
||||||
browser: ua.browser.name,
|
browser: ua.browser.name,
|
||||||
type: ua.device.type,
|
type: ua.device.type,
|
||||||
displayName: uniqueNamesGenerator({ length: 2, separator: ' ', dictionaries: [colors, animals], style: 'capital' })
|
displayName: displayName
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue