dsc-auth
Version:
An Oauth platform built on Qr Codes for DSC
10 lines (9 loc) • 2.73 kB
JavaScript
module.exports = { contents: "\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar Authentication = /** @class */ (function () {\n function Authentication(API_KEY) {\n this.isInitialized = false;\n this.endpoint = \"secure-stream-87726.herokuapp.com\";\n this.key = API_KEY;\n this.socket = new WebSocket(\"wss://\" + this.endpoint + \"/qr\");\n this.init = this.init.bind(this);\n this.getQr = this.getQr.bind(this);\n this.destroy = this.destroy.bind(this);\n this.continousPing = this.continousPing.bind(this);\n }\n Authentication.prototype.continousPing = function () {\n var _this = this;\n this.cPing = setInterval(function () {\n _this.socket.send(\"ping\");\n }, 40000);\n };\n Authentication.prototype.init = function (detailsHandler, ping) {\n if (ping === void 0) { ping = false; }\n this.isInitialized = true;\n this.shouldPing = ping;\n this.onRecieveUserDetails = this.onRecieveUserDetails.bind(this, detailsHandler);\n };\n Authentication.prototype.destroy = function () {\n clearInterval(this.cPing);\n this.socket.close();\n };\n Authentication.prototype.getQr = function () {\n var self = this;\n if (!self.isInitialized) {\n throw \"The module is not initialized; call init(...) before getQr()\";\n }\n return new Promise(function (resolve, reject) {\n self.socket.onopen = function () {\n self.socket.send(JSON.stringify({\n \"project_name\": \"Frontend-test\",\n \"api_key\": self.key,\n \"domain_name\": \"localhost\"\n }));\n if (self.shouldPing)\n self.continousPing();\n self.socket.onmessage = function (event) {\n var data = JSON.parse(event.data);\n if (data.ImageQR !== undefined) {\n resolve(data.ImageQR);\n }\n else if (data.message === \"success\") {\n self.onRecieveUserDetails(data);\n }\n };\n };\n });\n };\n Authentication.prototype.onRecieveUserDetails = function (userDetailsHandler, data) {\n var self = this;\n userDetailsHandler(data.details);\n self.destroy();\n };\n return Authentication;\n}());\nAuth = Authentication;\nexports.default = Authentication;\n",
dependencies: [],
sourceMap: {},
headerContent: undefined,
mtime: 1532822399726,
devLibsRequired : undefined,
ac : undefined,
_ : {}
}