From 074b7769843c3e52260677bb8700ce5157b299bd Mon Sep 17 00:00:00 2001 From: Zack Date: Tue, 13 Dec 2016 06:59:04 -0800 Subject: [PATCH] Create keystore.js Former-commit-id: 6e57c4fa824b56c208f0910bd462b7145b3a201d [formerly 6750759dea61eb28bc5cca842d5fb3659fd9795b] [formerly 69062d21361147bfc05d329f26e4ba5167a59565 [formerly 83dfac9923a9ce6869b5b62f34d5282927480cdf [formerly 169e4b41c963fb89de9267886a6be4b4a24d3c72]]] Former-commit-id: fed116cda64134c4b76f2665f283d08176697b1c [formerly 8654e5a8f910d7f5135572eab42c48511e62f38f] Former-commit-id: 136a617fe456bdea15c6d4173f6abd9bc4bba819 Former-commit-id: ad4ed378980a8cb5df8ffecefb1a7f8df658a031 --- 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); + } + }); +}