import debug from "debug" ; import { when } from "mobx" ; import RootStore from "../stores" ; const log = debug ( "effect:stats" ) ; export const openStats = ( { ui , room } ) => ( ) => { log ( "openStats()" ) ; ui . isStatsOpen = true ; const timer = setInterval ( async ( ) => { const pc = room . getPeerConnection ( ) ; if ( pc === null ) { return ; } pc . getStats ( ) . then ( ( statsReport ) => ( room . rtcStats = statsReport ) ) . catch ( ( err ) => log ( "getStats() error" , err ) ) ; } , 1000 ) ; when ( ( ) => ! ui . isStatsOpen , ( ) => { log ( "stop stats collector" ) ; clearInterval ( timer ) ; room . rtcStats = null ; } ) ; } ; export const closeStats = ( { ui } ) => ( ) => { log ( "closeStats()" ) ; ui . isStatsOpen = false ; } ;