Converted initalizeSession
This commit is contained in:
parent
10465e6841
commit
6612145c4f
|
@ -1,41 +1,70 @@
|
||||||
enum Indexes {
|
const Indexes = {
|
||||||
clientId = 0,
|
clientId: 0,
|
||||||
imageUrl
|
imageUrl: 1
|
||||||
}
|
};
|
||||||
|
|
||||||
export default class InitSession {
|
export default class InitSession {
|
||||||
private _clientSessionId: string | undefined;
|
constructor() {
|
||||||
private _imageUrl: string | undefined;
|
/** @type {string | undefined} */
|
||||||
|
this._sessionId;
|
||||||
set sessionId(id: string) {
|
/** @type {string | undefined} */
|
||||||
if(id.length !== 8) throw Error("ClientID is not 8 characters");
|
this._imageUrl;
|
||||||
this._clientSessionId = id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get sessionId(): string {
|
/**
|
||||||
return this._clientSessionId!;
|
* Set the session ID for the user
|
||||||
|
* @param {string} id
|
||||||
|
*/
|
||||||
|
setSessionId(id) {
|
||||||
|
if (id.length !== 8) throw Error("ClientID is not 8 characters");
|
||||||
|
this._sessionId = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
set imageUrl(url: string) {
|
/**
|
||||||
|
* Get the session ID for the user
|
||||||
|
* @return {string}
|
||||||
|
*/
|
||||||
|
getSessionId() {
|
||||||
|
return this._sessionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the image URL for the initial challenge
|
||||||
|
* @param {string} url
|
||||||
|
*/
|
||||||
|
setImageUrl(url: string) {
|
||||||
this._imageUrl = url;
|
this._imageUrl = url;
|
||||||
}
|
}
|
||||||
|
|
||||||
get imageUrl(): string {
|
/**
|
||||||
return this._imageUrl!;
|
* Get the image URL for the initial challenge
|
||||||
|
* @return {string}
|
||||||
|
*/
|
||||||
|
getImageUrl() {
|
||||||
|
return this._imageUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
serialize(): any[] {
|
/**
|
||||||
if(!this._clientSessionId || !this._imageUrl) {
|
* Serialize the session into a JSON object
|
||||||
throw Error("Unable to serialize because missing field(s)")
|
* @return {Array<any>}
|
||||||
|
*/
|
||||||
|
serialize() {
|
||||||
|
if (!this._sessionId || !this._imageUrl) {
|
||||||
|
throw Error("Unable to serialize because missing field(s)");
|
||||||
}
|
}
|
||||||
const payload = [];
|
const payload = [];
|
||||||
payload[Indexes.clientId] = this._clientSessionId;
|
payload[Indexes.clientId] = this._sessionId;
|
||||||
payload[Indexes.imageUrl] = this._imageUrl;
|
payload[Indexes.imageUrl] = this._imageUrl;
|
||||||
|
|
||||||
return payload;
|
return payload;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deserialize session data from JSON object
|
||||||
|
* @param {Array<any>} payload
|
||||||
|
*/
|
||||||
deserialize(payload: any[]) {
|
deserialize(payload: any[]) {
|
||||||
|
this.setSessionId(payload[Indexes.clientId]);
|
||||||
|
this.setImageUrl(payload[Indexes.imageUrl]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,9 +6,9 @@
|
||||||
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
|
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
|
||||||
// "lib": [], /* Specify library files to be included in the compilation. */
|
// "lib": [], /* Specify library files to be included in the compilation. */
|
||||||
// "allowJs": true, /* Allow javascript files to be compiled. */
|
// "allowJs": true, /* Allow javascript files to be compiled. */
|
||||||
// "checkJs": true, /* Report errors in .js files. */
|
"checkJs": true, /* Report errors in .js files. */
|
||||||
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
|
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
|
||||||
// "declaration": true, /* Generates corresponding '.d.ts' file. */
|
"declaration": true, /* Generates corresponding '.d.ts' file. */
|
||||||
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
||||||
// "sourceMap": true, /* Generates corresponding '.map' file. */
|
// "sourceMap": true, /* Generates corresponding '.map' file. */
|
||||||
// "outFile": "./", /* Concatenate and emit output to single file. */
|
// "outFile": "./", /* Concatenate and emit output to single file. */
|
||||||
|
|
Loading…
Reference in New Issue