UNPKG

dsc-auth

Version:

An Oauth platform built on Qr Codes for DSC

1 lines 1.38 kB
_3e4d.f={},_3e4d.m={},_3e4d.r=function(e){var t=_3e4d.m[e];if(t)return t.m.exports;var i=_3e4d.f[e];return i?((t=_3e4d.m[e]={}).exports={},t.m={exports:t.exports},i.call(t.exports,t.m,t.exports),t.m.exports):void 0},_3e4d.f[0]=function(e,t){Object.defineProperty(t,"__esModule",{value:!0});class i{constructor(e){this.isInitialized=!1,this.endpoint="secure-stream-87726.herokuapp.com",this.key=e,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)}continousPing(){this.cPing=setInterval(()=>{this.socket.send("ping")},4e4)}init(e,t=!1){this.isInitialized=!0,this.shouldPing=t,this.onRecieveUserDetails=this.onRecieveUserDetails.bind(this,e)}destroy(){clearInterval(this.cPing),this.socket.close()}getQr(){let e=this;if(!e.isInitialized)throw"The module is not initialized; call init(...) before getQr()";return new Promise(function(t,i){e.socket.onopen=function(){e.socket.send(JSON.stringify({project_name:"Frontend-test",api_key:e.key,domain_name:"localhost"})),e.shouldPing&&e.continousPing(),e.socket.onmessage=function(i){let s=JSON.parse(i.data);void 0!==s.ImageQR?t(s.ImageQR):"success"===s.message&&e.onRecieveUserDetails(s)}}})}onRecieveUserDetails(e,t){e(t.details),this.destroy()}}Auth=i,t.default=i},_3e4d.r(0);