import { IContainer , IRuntimeFactory , } from "@fluidframework/container-definitions" ; import { Loader } from "@fluidframework/container-loader" ; import { LocalDeltaConnectionServer , ILocalDeltaConnectionServer } from "@fluidframework/server-local-server" ; import { LocalResolver , LocalDocumentServiceFactory , LocalSessionStorageDbFactory } from "@fluidframework/local-driver" ; const deltaConnectionMap = new Map < string , ILocalDeltaConnectionServer > ( ) ; const urlResolver = new LocalResolver ( ) ; param documentId param containerRuntimeFactory export async function getSessionStorageContainer ( documentId , containerRuntimeFactory , createNew ) { let deltaConnection = deltaConnectionMap . get ( documentId ) ; if ( deltaConnection === undefined ) { deltaConnection = LocalDeltaConnectionServer . create ( new LocalSessionStorageDbFactory ( documentId ) ) ; deltaConnectionMap . set ( documentId , deltaConnection ) ; } const documentServiceFactory = new LocalDocumentServiceFactory ( deltaConnection ) ; const url = `${ window . location . origin }/${ documentId }` ; const module = { fluidExport : containerRuntimeFactory } ; const codeLoader = { load : async ( ) => module } ; const loader = new Loader ( { urlResolver , documentServiceFactory , codeLoader } ) ; let container ; if ( createNew ) { container = await loader . createDetachedContainer ( { package : "" , config : { } } ) ; await container . attach ( { url } ) ; } else { container = await loader . resolve ( { url } ) ; } return container ; }