From 49aa6731df52de67c75c473489296e13e580427d Mon Sep 17 00:00:00 2001 From: adb Date: Sat, 7 Nov 2020 20:31:55 +0100 Subject: [PATCH] login --- api.js | 7 +++++++ src/components/newMessage.vue | 4 ++-- src/main.js | 12 ++++++++++++ src/views/login.vue | 14 +++++++++++--- 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/api.js b/api.js index a001add..8321bf9 100644 --- a/api.js +++ b/api.js @@ -21,12 +21,19 @@ const wss = new ws.Server({ }); //WS handler +let user = []; wss.on('connection', (ws, req) => { console.log(`${req.socket.remoteAddress} connected`) ws.on('message', msgJSON => { let msg = JSON.parse(msgJSON) console.log(`${req.socket.remoteAddress} => ${msgJSON}`) if (msg.type === 'message') wss.clients.forEach(client => client.send(msgJSON)) + else if (msg.type === 'login' && msg.content.user !== ""){ + user.push(msg.content.user) + ws.send('{"type":"route","path":"/chat"}') + let msg = {type: "room", name: "open chat", user: user} + ws.send(JSON.stringify(msg)) + } }) let msg = { type: "info", diff --git a/src/components/newMessage.vue b/src/components/newMessage.vue index 74f91bb..c1800a0 100644 --- a/src/components/newMessage.vue +++ b/src/components/newMessage.vue @@ -9,8 +9,8 @@