diff --git a/src/index.ts b/src/index.ts index 3d27322fe..8fb0b4807 100644 --- a/src/index.ts +++ b/src/index.ts @@ -588,7 +588,7 @@ function startMdns(app: ServerApp & WithConfig) { } } -function startInterfaces(app: ServerApp & WithConfig) { +function startInterfaces(app: ServerApp & WithConfig & WithWrappedEmitter) { debug('Interfaces config:' + JSON.stringify(app.config.settings.interfaces)) const availableInterfaces = require('./interfaces') _.forIn(availableInterfaces, (theInterface: any, name: string) => { @@ -598,14 +598,35 @@ function startInterfaces(app: ServerApp & WithConfig) { (app.config.settings.interfaces || {})[name] ) { debug(`Loading interface '${name}'`) - app.interfaces[name] = theInterface(app) - if (app.interfaces[name] && _.isFunction(app.interfaces[name].start)) { + const boundEventMethods = app.wrappedEmitter.bindMethodsById( + `interface:${name}` as EventsActorId + ) + + const appCopy = { + ...app, + ...boundEventMethods + } + const handler = { + set(obj: any, prop: any, value: any) { + ;(app as any)[prop] = value + ;(appCopy as any)[prop] = value + return true + }, + // eslint-disable-next-line @typescript-eslint/no-unused-vars + get(target: any, prop: string | symbol, receiver: any) { + return (appCopy as any)[prop] + } + } + const _interface = (appCopy.interfaces[name] = theInterface( + new Proxy(appCopy, handler) + )) + if (_interface && _.isFunction(_interface.start)) { if ( - _.isUndefined(app.interfaces[name].forceInactive) || - !app.interfaces[name].forceInactive + _.isUndefined(_interface.forceInactive) || + !_interface.forceInactive ) { debug(`Starting interface '${name}'`) - app.interfaces[name].data = app.interfaces[name].start() + _interface.data = _interface.start() } else { debug(`Not starting interface '${name}' by forceInactive`) }