aboutsummaryrefslogtreecommitdiffstats
path: root/lib/sockets.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2020-06-23 14:39:41 -0700
committerAdam Soltys <[email protected]>2020-06-23 14:39:41 -0700
commitd6af21064d106e6179d76e0dddee049c5e7c0fc5 (patch)
treed6cf57a7659a6e60ad80992c8f93dcc59c11c770 /lib/sockets.js
parent3c46dc86b753cdfd71da7b8bb86710032668b5eb (diff)
downloadcoinos-server-d6af21064d106e6179d76e0dddee049c5e7c0fc5.tar.gz
coinos-server-d6af21064d106e6179d76e0dddee049c5e7c0fc5.zip
lnurl auth
Diffstat (limited to 'lib/sockets.js')
-rw-r--r--lib/sockets.js18
1 files changed, 12 insertions, 6 deletions
diff --git a/lib/sockets.js b/lib/sockets.js
index 4b733882..d4ca336d 100644
--- a/lib/sockets.js
+++ b/lib/sockets.js
@@ -6,7 +6,6 @@ wss = new WebSocket.Server({ clientTracking: false, noServer: true });
/* eslint-disable-next-line */
const pick = (O, ...K) => K.reduce((o, k) => ((o[k] = O[k]), o), {});
-sockets = {};
emit = (username, type, data) => {
if (data.username !== undefined) data = pick(data, ...whitelist);
@@ -37,15 +36,15 @@ const names = {};
wss.on("connection", function(ws, req) {
const id = uuidv4();
- setTimeout(() => ws.user || ws.close(), 2000);
+ ws.send(JSON.stringify({ type: "connected" }));
- ws.on("message", async (message) => {
+ ws.on("message", async message => {
let type, data;
try {
- ({ type, data } = JSON.parse(message));
+ ({ type, data } = JSON.parse(message));
} catch (e) {
l.error("coudn't parse socket message");
- }
+ }
let token;
switch (type) {
@@ -71,13 +70,17 @@ wss.on("connection", function(ws, req) {
}
});
let accounts = await user.getAccounts();
+ let keys = await user.getKeys();
user = user.get({ plain: true });
user.accounts = accounts;
+ user.keys = keys;
user.payments = payments;
ws.user = user;
ws.send(JSON.stringify({ type: "login", data: user }));
- ws.send(JSON.stringify({ type: "version", data: config.clientVersion }));
+ ws.send(
+ JSON.stringify({ type: "version", data: config.clientVersion })
+ );
l.info("socket open", username, id);
} catch (e) {
ws.close();
@@ -95,6 +98,9 @@ wss.on("connection", function(ws, req) {
if (!ws.user) return;
ws.token = token;
break;
+ case "lnurl":
+ sessions[data] = ws;
+ break;
default:
l.warn("received socket message of unknown type", type, data);
}