import { EventEmitter } from "events" ; import { IAudience } from "@fluidframework/container-definitions" ; import { IClient } from "@fluidframework/protocol-definitions" ; /**
 * Audience represents all clients connected to the op stream.
 */ export class Audience extends EventEmitter implements IAudience { private readonly members = new Map < string , IClient > ( ) ; public on ( event , listener ) ; public on ( event , listener ) { return super . on ( event , listener ) ; } /**
     * Adds a new client to the audience
     */ public addMember ( clientId , details ) { this . members . set ( clientId , details ) ; this . emit ( "addMember" , clientId , details ) ; } returns public removeMember ( clientId ) { const removedClient = this . members . get ( clientId ) ; if ( removedClient !== undefined ) { this . members . delete ( clientId ) ; this . emit ( "removeMember" , clientId , removedClient ) ; return true ; } else { return false ; } } /**
     * Retrieves all the members in the audience
     */ public getMembers ( ) { return new Map ( this . members ) ; } /**
     * Retrieves a specific member of the audience
     */ public getMember ( clientId ) { return this . members . get ( clientId ) ; } /**
     * Clears the audience
     */ public clear ( ) { const clientIds = this . members . keys ( ) ; for ( const clientId of clientIds ) { this . removeMember ( clientId ) ; } } }