[Assist] added city and state support for geo extractor (#1314)
* feat(assist): added support for city and state extraction from GeoLite.db * feat(assist): added new fields to base session info structure
This commit is contained in:
parent
83ba3d3c98
commit
d8d4e0beeb
3 changed files with 10 additions and 4 deletions
|
|
@ -16,7 +16,7 @@ COPY . .
|
|||
|
||||
RUN adduser -u 1001 openreplay -D
|
||||
USER 1001
|
||||
ADD --chown=1001 https://static.openreplay.com/geoip/GeoLite2-Country.mmdb $MAXMINDDB_FILE
|
||||
ADD --chown=1001 https://static.openreplay.com/geoip/GeoLite2-City.mmdb $MAXMINDDB_FILE
|
||||
|
||||
ENTRYPOINT ["/sbin/tini", "--"]
|
||||
CMD npm start
|
||||
|
|
@ -43,6 +43,8 @@ const BASE_sessionInfo = {
|
|||
"userDevice": "",
|
||||
"userDeviceType": "",
|
||||
"userCountry": "",
|
||||
"userState": "",
|
||||
"userCity": "",
|
||||
"projectId": 0
|
||||
};
|
||||
|
||||
|
|
@ -61,13 +63,17 @@ const extractSessionInfo = function (socket) {
|
|||
socket.handshake.query.sessionInfo.userDevice = ua.device.model || null;
|
||||
socket.handshake.query.sessionInfo.userDeviceType = ua.device.type || 'desktop';
|
||||
socket.handshake.query.sessionInfo.userCountry = null;
|
||||
socket.handshake.query.sessionInfo.userState = null;
|
||||
socket.handshake.query.sessionInfo.userCity = null;
|
||||
if (geoip() !== null) {
|
||||
debug && console.log(`looking for location of ${socket.handshake.headers['x-forwarded-for'] || socket.handshake.address}`);
|
||||
try {
|
||||
let ip = socket.handshake.headers['x-forwarded-for'] || socket.handshake.address;
|
||||
ip = ip.split(",")[0];
|
||||
let country = geoip().country(ip);
|
||||
socket.handshake.query.sessionInfo.userCountry = country.country.isoCode;
|
||||
let info = geoip().city(ip);
|
||||
socket.handshake.query.sessionInfo.userCountry = info.country.isoCode;
|
||||
socket.handshake.query.sessionInfo.userCity = info.city.names.en;
|
||||
socket.handshake.query.sessionInfo.userState = info.subdivisions.length > 0 ? info.subdivisions[0].names.en : null;
|
||||
} catch (e) {
|
||||
debug && console.log("geoip-country failed");
|
||||
debug && console.log(e);
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ COPY . .
|
|||
|
||||
RUN adduser -u 1001 openreplay -D
|
||||
USER 1001
|
||||
ADD --chown=1001 https://static.openreplay.com/geoip/GeoLite2-Country.mmdb $MAXMINDDB_FILE
|
||||
ADD --chown=1001 https://static.openreplay.com/geoip/GeoLite2-City.mmdb $MAXMINDDB_FILE
|
||||
|
||||
ENTRYPOINT ["/sbin/tini", "--"]
|
||||
CMD npm start
|
||||
Loading…
Add table
Reference in a new issue