import { getTinyliciousContainer } from "@fluid-experimental/get-container" ; import { FluidObject } from "@fluidframework/core-interfaces" ; import { IContainer } from "@fluidframework/container-definitions" ; import { ReactViewAdapter } from "@fluidframework/view-adapters" ; import { IFluidMountableView } from "@fluidframework/view-interfaces" ; import React from "react" ; import ReactDOM from "react-dom" ; import { DiceRollerContainerRuntimeFactory } from "./containerCode" ; async function mountDefaultFluidObjectFromContainer ( container ) { const div = document . getElementById ( "content" ) as HTMLDivElement ; const url = "/" ; const response = await container . request ( { headers : { mountableView : true } , url } ) ; if ( response . status !== 200 || response . mimeType !== "fluid/object" ) { throw new Error ( `Unable to retrieve Fluid object at URL: "${ url }"` ) ; } else if ( response . value === undefined ) { throw new Error ( `Empty response from URL: "${ url }"` ) ; } const fluidObject = response . value ; const mountableView = fluidObject . IFluidMountableView ; if ( mountableView !== undefined ) { mountableView . mount ( div ) ; return ; } if ( ReactViewAdapter . canAdapt ( fluidObject ) ) { console . warn ( `Container returned a non-IFluidMountableView.  This can cause errors when mounting React ` + `components with hooks across bundle boundaries.  URL: ${ url }` ) ; ReactDOM . render ( React . createElement ( ReactViewAdapter , { view : fluidObject } ) , div ) ; return ; } throw new Error ( "Could not retrieve a view" ) ; } async function start ( ) { const shouldCreateNew = location . hash . length === 0 ; const documentId = ! shouldCreateNew ? window . location . hash . substring ( 1 ) : "" ; const [ container , containerId ] = await getTinyliciousContainer ( documentId , new DiceRollerContainerRuntimeFactory ( ) , shouldCreateNew ) ; location . hash = containerId ; document . title = containerId ; await mountDefaultFluidObjectFromContainer ( container ) ; window [ "fluidStarted" ] = true ; } start ( ) . catch ( ( error ) => console . error ( error ) ) ;