diff --git a/keyserver/package.json b/keyserver/package.json --- a/keyserver/package.json +++ b/keyserver/package.json @@ -48,6 +48,7 @@ "common-tags": "^1.7.2", "cookie-parser": "^1.4.3", "dateformat": "^3.0.3", + "detect-browser": "^4.0.4", "ethers": "^5.7.2", "express": "^4.17.3", "express-ws": "^4.0.0", diff --git a/keyserver/src/keyserver.js b/keyserver/src/keyserver.js --- a/keyserver/src/keyserver.js +++ b/keyserver/src/keyserver.js @@ -3,6 +3,7 @@ import olm from '@matrix-org/olm'; import cluster from 'cluster'; import cookieParser from 'cookie-parser'; +import { detect as detectBrowser } from 'detect-browser'; import express from 'express'; import expressWs from 'express-ws'; import os from 'os'; @@ -127,8 +128,14 @@ // should redirect the user to a place from which the app can be // downloaded. router.get('/invite/:secret', (req, res) => { + const userAgent = req.get('User-Agent'); + const detectionResult = detectBrowser(userAgent); + const redirectUrl = + detectionResult.os === 'Android OS' + ? stores.googlePlayUrl + : stores.appStoreUrl; res.writeHead(301, { - Location: stores.appStoreUrl, + Location: redirectUrl, }); res.end(); }); diff --git a/lib/facts/stores.js b/lib/facts/stores.js --- a/lib/facts/stores.js +++ b/lib/facts/stores.js @@ -2,6 +2,8 @@ const stores = { appStoreUrl: 'https://apps.apple.com/us/app/comm-messenger/id1574433435', + googlePlayUrl: + 'https://play.google.com/store/apps/details?id=app.comm.android', }; export default stores;