| 29 | |
| 30 | @Service() |
| 31 | export class NodeRuntimeState { |
| 32 | private readonly _loadingStep = signal<number>(LoadingStep.NOT_STARTED); |
| 33 | loadingStep = this._loadingStep.asReadonly(); |
| 34 | |
| 35 | private readonly _isResetting = signal(false); |
| 36 | readonly isResetting = this._isResetting.asReadonly(); |
| 37 | |
| 38 | private readonly _error = signal<NodeRuntimeError | undefined>(undefined); |
| 39 | readonly error = this._error.asReadonly(); |
| 40 | |
| 41 | constructor() { |
| 42 | this.checkUnsupportedEnvironment(); |
| 43 | } |
| 44 | |
| 45 | setLoadingStep(step: LoadingStep): void { |
| 46 | this._loadingStep.set(step); |
| 47 | } |
| 48 | |
| 49 | setIsResetting(isResetting: boolean): void { |
| 50 | this._isResetting.set(isResetting); |
| 51 | } |
| 52 | |
| 53 | setError({message, type}: NodeRuntimeError) { |
| 54 | type ??= this.getErrorType(message); |
| 55 | this._error.set({message, type}); |
| 56 | this.setLoadingStep(LoadingStep.ERROR); |
| 57 | } |
| 58 | |
| 59 | private getErrorType(message: NodeRuntimeError['message']) { |
| 60 | if (message?.includes(OUT_OF_MEMORY_MSG)) { |
| 61 | return ErrorType.OUT_OF_MEMORY; |
| 62 | } |
| 63 | |
| 64 | if (message?.toLowerCase().includes('service worker')) { |
| 65 | return ErrorType.COOKIES; |
| 66 | } |
| 67 | |
| 68 | return ErrorType.UNKNOWN; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * This method defines whether the current environment is compatible |
| 73 | * with the NodeRuntimeSandbox. The embedded editor requires significant |
| 74 | * CPU and memory resources and can not be ran in all browsers/devices. More |
| 75 | * specifically, mobile devices are affected by this, so for the best user |
| 76 | * experience (to avoid crashes), we disable the NodeRuntimeSandbox and |
| 77 | * recommend using desktop. |
| 78 | */ |
| 79 | private checkUnsupportedEnvironment(): void { |
| 80 | if (isIos) { |
| 81 | this.setError({ |
| 82 | message: 'Unsupported environment', |
| 83 | type: ErrorType.UNSUPPORTED_BROWSER_ENVIRONMENT, |
| 84 | }); |
| 85 | } |
| 86 | } |
| 87 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…