"use strict" ; import { IGW_FRAME_RCV_CTOR , IGW_FRAME_RCV , GatewayCommand } from "./common" ; import * as path from "path" ; export class FrameRcvFactory { public static async CreateRcvFrame ( Buff ) { const CommandName = GatewayCommand [ Buff . readUInt16BE ( 1 ) ] ; await this . LoadModule ( CommandName ) ; const typeToCreate = this . modules [ CommandName ] [ CommandName ] ; if ( typeToCreate === undefined ) throw new Error ( `Unknown command ${ CommandName }.` ) ; return new typeToCreate ( Buff ) ; } private static modules : { [ index ] : { [ key ] : IGW_FRAME_RCV_CTOR ; } ; } = { } ; private static async LoadModule ( moduleName ) { if ( ! this . modules [ moduleName ] ) { const modulePath = path . resolve ( __dirname , moduleName ) ; this . modules [ moduleName ] = await import ( modulePath ) ; } } }