From 169e4b41c963fb89de9267886a6be4b4a24d3c72 Mon Sep 17 00:00:00 2001 From: Zack Date: Tue, 13 Dec 2016 06:59:04 -0800 Subject: [PATCH] Create keystore.js --- keystore/keystore.js | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 keystore/keystore.js diff --git a/keystore/keystore.js b/keystore/keystore.js new file mode 100644 index 0000000..bef17b5 --- /dev/null +++ b/keystore/keystore.js @@ -0,0 +1,42 @@ +function save(key, value) { + c = new WebSocket('wss://cowyo.com/ws'); + return new Promise(function (resolve, reject) { + try { + c.onopen = function (_) { + c.send(JSON.stringify({ + TextData: JSON.stringify(value), + Title: `${key}`, + UpdateServer: true, + UpdateClient: false, + })); + return resolve(true); + } + } catch(e) { + return reject(e); + } + }); +} + +// save('hello2', 'world'); + + + + +function get(key) { + c = new WebSocket('wss://cowyo.com/ws'); + return new Promise(function (resolve, reject) { + try { + c.onmessage = function(evt) { + return resolve(JSON.parse(JSON.parse(evt.data).TextData)); + } + c.onopen = function (_) { + c.send(JSON.stringify({ + Title: `${key}`, + UpdateClient: true, + })); + }; + } catch(e) { + return reject(e); + } + }); +}