UNPKG

@inworld/web-core

Version:
35 lines (34 loc) 1.31 kB
import { ErrorType, InworldError } from '../../entities/error.entity.js'; import { StateSerializationService as PbService } from '../pb/state_serialization.service.js'; export class StateSerializationService { constructor(connection) { this.service = new PbService(); this.connection = connection; } async get(attempt = 0) { var _a; let session = await this.connection.ensureSessionToken(); try { return await this.service.getSessionState({ config: this.connection.getConfig(), session, scene: this.connection.getSceneName(), }); } catch (protoErr) { if (attempt) { throw protoErr; } const err = InworldError.fromProto(protoErr); const status = (_a = err.details) === null || _a === void 0 ? void 0 : _a[0]; switch (status === null || status === void 0 ? void 0 : status.errorType) { case ErrorType.SESSION_TOKEN_EXPIRED: case ErrorType.SESSION_TOKEN_INVALID: await this.connection.ensureSessionToken(); return this.get(attempt + 1); default: return; } } } }