diff options
author | Marvin Borner | 2019-01-28 19:11:25 +0100 |
---|---|---|
committer | Marvin Borner | 2019-01-28 19:11:25 +0100 |
commit | 4b9d36039734a1b23d960ba215190860855b0141 (patch) | |
tree | 807c056bdf380a4d06ed5e8078582d5517e746ba /public/scripts/chat.js | |
parent | 784e129902421f918dbf71e7aa3ef346ce1c00f7 (diff) |
Tried implementing encrypted message storage
Diffstat (limited to 'public/scripts/chat.js')
-rw-r--r-- | public/scripts/chat.js | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/public/scripts/chat.js b/public/scripts/chat.js index 35e75db..36cfdf1 100644 --- a/public/scripts/chat.js +++ b/public/scripts/chat.js @@ -90,9 +90,11 @@ function chat() { // Peer events peer.on('open', id => console.log('[LOG] Your ID is', id)); peer.on('error', err => console.error(err)); - peer.on('connection', conn => { + peer.on('connection', async conn => { connectedPeer = conn; console.log('[LOG] Connected with', connectedPeer.peer); + encryption.getMsgs(connectedPeer.peer, await encryption.get(connectedPeer.peer), await encryption.getPrivate(), passphrase).then(messages => + messages.forEach(data => receivedMessage(`${data.message} - ${data.time}`, true))); connectedPeer.on('open', async () => transferKey(await encryption.getPublic())); connectedPeer.on('data', async message => { console.log('[LOG] Received new message!'); @@ -111,6 +113,8 @@ function chat() { console.log('[LOG] Your connection ID is', connectionId); connectedPeer = peer.connect(id, {label: connectionId, reliable: true}); console.log('[LOG] Connected with', connectedPeer.peer); + encryption.getMsgs(connectedPeer.peer, await encryption.get(connectedPeer.peer), await encryption.getPrivate(), passphrase).then(messages => + messages.forEach(data => receivedMessage(`${data.message} - ${data.time}`, true))); connectedPeer.on('open', async () => transferKey(await encryption.getPublic())); connectedPeer.on('data', async message => { console.log('[LOG] Received new message!'); @@ -151,6 +155,7 @@ function chat() { $('#messages').append(`<span style="color: green">${message}</span><br>`); } else { if (message.type === 'text') { + await encryption.storeMsg(peerId, message.data); await encryption.decrypt(message.data, await encryption.get(connectedPeer.peer), await encryption.getPrivate(), passphrase) .then(plaintext => $('#messages').append(`${plaintext}<br>`)); } else if (message.type === 'key') { |