import { AzureFunctionTokenProvider , AzureClient , AzureConnectionConfig , AzureContainerServices , LOCAL_MODE_TENANT_ID , } from "@fluidframework/azure-client" ; import { generateTestUser , InsecureTokenProvider , } from "@fluidframework/test-client-utils" ; import { IFluidContainer , SharedMap , } from "fluid-framework" ; import { DiceRollerController } from "./controller" ; import { makeAppView } from "./view" ; export interface ICustomUserDetails { gender : string ; email : string ; } const userDetails = { gender : "female" , email : "xyz@microsoft.com" } ; const useAzure = process . env . FLUID_CLIENT === "azure" ; const user = generateTestUser ( ) ; const azureUser = { userId : user . id , userName : user . name , additionalDetails : userDetails } ; const connectionConfig = useAzure ? { tenantId : "" , tokenProvider : new AzureFunctionTokenProvider ( "" , azureUser ) , orderer : "" , storage : "" } : { tenantId : LOCAL_MODE_TENANT_ID , tokenProvider : new InsecureTokenProvider ( "fooBar" , user ) , orderer : "http://localhost:7070" , storage : "http://localhost:7070" } ; const containerSchema = { initialObjects : { map1 : SharedMap , map2 : SharedMap } } ; async function initializeNewContainer ( container ) { const sharedMap1 = container . initialObjects . map1 as SharedMap ; const sharedMap2 = container . initialObjects . map2 as SharedMap ; await Promise . all ( [ DiceRollerController . initializeModel ( sharedMap1 ) , DiceRollerController . initializeModel ( sharedMap2 ) , ] ) ; } async function start ( ) { const clientProps = { connection : connectionConfig } ; const client = new AzureClient ( clientProps ) ; let container ; let services ; let id ; const createNew = location . hash . length === 0 ; if ( createNew ) { ( { container , services } = await client . createContainer ( containerSchema ) ) ; await initializeNewContainer ( container ) ; id = await container . attach ( ) ; location . hash = id ; } else { id = location . hash . substring ( 1 ) ; ( { container , services } = await client . getContainer ( id , containerSchema ) ) ; } document . title = id ; const sharedMap1 = container . initialObjects . map1 as SharedMap ; const sharedMap2 = container . initialObjects . map2 as SharedMap ; const diceRollerController1 = new DiceRollerController ( sharedMap1 ) ; const diceRollerController2 = new DiceRollerController ( sharedMap2 ) ; const contentDiv = document . getElementById ( "content" ) as HTMLDivElement ; contentDiv . append ( makeAppView ( [ diceRollerController1 , diceRollerController2 ] , services . audience ) ) ; } start ( ) . catch ( console . error ) ;