Skip to content

Instantly share code, notes, and snippets.

@madclaws
Last active April 24, 2018 11:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save madclaws/7c35554d71a0ee991c3c130f1946f2a2 to your computer and use it in GitHub Desktop.
Save madclaws/7c35554d71a0ee991c3c130f1946f2a2 to your computer and use it in GitHub Desktop.
session restore and connect
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