import { Service } from "./service" ; import { NodeCG } from "nodecg-types/types/server" ; import { error , Result , success } from "./utils/result" ; /**
 * Manages services by allowing services to register them and allowing access of other components to the registered services.
 */ export class ServiceManager { private services : Service < unknown , any > [ ] = [ ] ; constructor ( private readonly nodecg ) { } /**
     * Registers the passed service which show it in the GUI and allows it to be instanced using  createServiceInstance .
     *  param service registerService < R , C > ( service ) { this . services . push ( service ) ; this . nodecg . log . info ( `Service ${ service . serviceType } has been registered.` ) ; } /**
     * Returns all registered services.
     */ getServices ( ) { return this . services ; } param serviceName return getService ( serviceName ) { const svc = this . services . find ( ( svc ) => svc . serviceType === serviceName ) ; if ( svc === undefined ) { return error ( "Service hasn't been registered." ) ; } else { return success ( svc ) ; } } }