Last active
April 24, 2018 11:19
-
-
Save madclaws/7c35554d71a0ee991c3c130f1946f2a2 to your computer and use it in GitHub Desktop.
session restore and connect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private restoreSessionAndConnect(){ | |
let sessionString:string=null; | |
if(typeof(Storage)!==undefined){ | |
sessionString=localStorage.getItem('nakamaToken'); | |
} | |
if(!sessionString || sessionString===""){ | |
return; | |
} | |
let session; | |
session=nakamajs.Session.restore(sessionString); | |
console.log("recovered session",session); | |
if(session.isexpired(new Date())){ | |
return; | |
} | |
this.sessionHandler(session); | |
} | |
private sessionHandler(session){ | |
this._session=session; | |
console.log("session",this._session); | |
//socket connection | |
this._clientInstance.connect(this._session).then(()=>{ | |
console.log("session Connected"); | |
// console.log(this._session.token); | |
localStorage.setItem('nakamaToken',this._session.token_); | |
this._ClientID=this._session.id; | |
// console.log(this._ClientID); | |
// this.selfFetchRequest(); | |
}).catch((err)=>{ | |
console.log("An error occured during session connection",err); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment