import { EventEmitter } from "events" ; import { IQuorumClients } from "@fluidframework/protocol-definitions" ; import { IFluidDependencySynthesizer } from "@fluidframework/synthesize" ; import { IContainerRuntime , IProvideContainerRuntime } from "@fluidframework/container-runtime-definitions" ; import { IFluidUserInformation } from "../interfaces" ; export class UserInfo extends EventEmitter implements IFluidUserInformation { private readonly quorum : IQuorumClients ; public on ( event , listener ) ; public on ( event , listener ) { return super . on ( event , listener ) ; } public constructor ( containerRuntime ) { super ( ) ; this . quorum = containerRuntime . getQuorum ( ) ; this . quorum . on ( "addMember" , ( ) => { this . emit ( "membersChanged" ) ; } ) ; this . quorum . on ( "removeMember" , ( ) => { this . emit ( "membersChanged" ) ; } ) ; } public get IFluidUserInformation ( ) { return this ; } public get userCount ( ) : number { return this . getHumanUsers ( ) . length ; } public getUsers ( ) { return this . getUserNames ( ) ; } private getHumanUsers ( ) { const members = this . quorum . getMembers ( ) ; return Array . from ( members ) . filter ( ( member ) => { return member [ 1 ] . client . details . capabilities . interactive ; } ) ; } private getUserNames ( ) { const users = this . getHumanUsers ( ) ; const names = [ ] ; for ( const user of users ) { names . push ( ( user [ 1 ] . client . user as any ) . name ?? "" ) ; } return names ; } } export const userInfoFactory = async ( dc ) => { const s = dc . synthesize < { } , IProvideContainerRuntime > ( { } , { IContainerRuntime } ) ; const containerRuntime = await s . IContainerRuntime ; return new UserInfo ( containerRuntime ) ; } ;