import * as redis from "redis" ; import { PlayerViewState } from "../common/PlayerViewState" ; import { InMemoryPlayerViewManager } from "./InMemoryPlayerViewManager" ; import { RedisPlayerViewManager } from "./RedisPlayerViewManager" ; export interface PlayerViewManager { Get ( id ) : Promise < PlayerViewState > ; IdAvailable ( id ) : Promise < boolean > ; UpdateEncounter ( id , newState ) : void ; UpdateSettings ( id , newSettings ) : void ; InitializeNew ( ) : Promise < string > ; Destroy ( id ) : void ; } export function GetPlayerViewManager ( ) { if ( process . env . REDIS_URL ) { const client = redis . createClient ( process . env . REDIS_URL ) ; client . on ( "error" , error => { console . error ( "Problem with PlayerViewManager Redis Client: " ) ; console . error ( error ) ; } ) ; return new RedisPlayerViewManager ( client ) ; } return new InMemoryPlayerViewManager ( ) ; }