dsc-auth
Version:
An Oauth platform built on Qr Codes for DSC
1 lines • 1.52 kB
JavaScript
!function(){var n={f:{},m:{},r:function(t){var i=n.m[t];if(i)return i.m.exports;var e=n.f[t];return e?((i=n.m[t]={}).exports={},i.m={exports:i.exports},e.call(i.exports,i.m,i.exports),i.m.exports):void 0}};n.f[0]=function(t,i){Object.defineProperty(i,"__esModule",{value:!0});var e=function(){function t(t){this.isInitialized=!1,this.endpoint="secure-stream-87726.herokuapp.com",this.key=t,this.socket=new WebSocket("wss://"+this.endpoint+"/qr"),this.init=this.init.bind(this),this.getQr=this.getQr.bind(this),this.destroy=this.destroy.bind(this),this.continousPing=this.continousPing.bind(this)}return t.prototype.continousPing=function(){var t=this;this.cPing=setInterval(function(){t.socket.send("ping")},4e4)},t.prototype.init=function(t,i){void 0===i&&(i=!1),this.isInitialized=!0,this.shouldPing=i,this.onRecieveUserDetails=this.onRecieveUserDetails.bind(this,t)},t.prototype.destroy=function(){clearInterval(this.cPing),this.socket.close()},t.prototype.getQr=function(){var n=this;if(!n.isInitialized)throw"The module is not initialized; call init(...) before getQr()";return new Promise(function(e,t){n.socket.onopen=function(){n.socket.send(JSON.stringify({project_name:"Frontend-test",api_key:n.key,domain_name:"localhost"})),n.shouldPing&&n.continousPing(),n.socket.onmessage=function(t){var i=JSON.parse(t.data);void 0!==i.ImageQR?e(i.ImageQR):"success"===i.message&&n.onRecieveUserDetails(i)}}})},t.prototype.onRecieveUserDetails=function(t,i){t(i.details),this.destroy()},t}();Auth=e,i.default=e},n.r(0)}();