mirror of
1
2
Fork 0

Converted initalizeSession

This commit is contained in:
Frank Lemanschik 2020-03-15 14:09:39 +01:00
parent 10465e6841
commit 6612145c4f
2 changed files with 52 additions and 23 deletions

View File

@ -1,41 +1,70 @@
enum Indexes {
clientId = 0,
imageUrl
}
const Indexes = {
clientId: 0,
imageUrl: 1
};
export default class InitSession {
private _clientSessionId: string | undefined;
private _imageUrl: string | undefined;
set sessionId(id: string) {
if(id.length !== 8) throw Error("ClientID is not 8 characters");
this._clientSessionId = id;
constructor() {
/** @type {string | undefined} */
this._sessionId;
/** @type {string | undefined} */
this._imageUrl;
}
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;
}
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) {
throw Error("Unable to serialize because missing field(s)")
/**
* Serialize the session into a JSON object
* @return {Array<any>}
*/
serialize() {
if (!this._sessionId || !this._imageUrl) {
throw Error("Unable to serialize because missing field(s)");
}
const payload = [];
payload[Indexes.clientId] = this._clientSessionId;
payload[Indexes.clientId] = this._sessionId;
payload[Indexes.imageUrl] = this._imageUrl;
return payload;
}
/**
* Deserialize session data from JSON object
* @param {Array<any>} payload
*/
deserialize(payload: any[]) {
this.setSessionId(payload[Indexes.clientId]);
this.setImageUrl(payload[Indexes.imageUrl]);
}
}
}

View File

@ -6,9 +6,9 @@
"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. */
// "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'. */
// "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. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */