- architecture tweaks for scalability
- added option for global debug logs
- added option for cef debug mode to run in browser only
This commit is contained in:
2024-10-27 14:53:55 +00:00
parent 640adae8a5
commit e2e58e100a
6 changed files with 156 additions and 50 deletions
+31 -4
View File
@@ -1,9 +1,31 @@
import { Environment, Errors, RPCState, Utils } from './utils'
import { Environment, Errors, RPCState, RpcWrapperConfig, Utils } from './utils'
export class Wrapper {
protected environment_ = Utils.getEnvironment()
protected state_ =
this.environment_ === Environment.BROWSER ? window : global
protected environment_ = Environment.UNKNOWN
protected state_: any
protected console_ =
this.environment_ === Environment.CLIENT
? mp.console.logInfo
: console.log
protected debug_ = false
protected forceBrowserDevMode_ = false
constructor(
options: RpcWrapperConfig = {
forceBrowserDevMode: false,
},
) {
if (options.forceBrowserDevMode) {
this.environment_ = Environment.UNKNOWN
this.state_ = window
} else {
this.environment_ = Utils.getEnvironment()
this.state_ =
this.environment_ === Environment.BROWSER ? window : global
}
this.forceBrowserDevMode_ = !!options.forceBrowserDevMode
}
protected verifyEvent_(data: string | RPCState): RPCState {
let rpcData =
@@ -30,4 +52,9 @@ export class Wrapper {
throw new Error(errorMessage.join('\n | '))
}
protected log(method: string, eventName: string, ...args: unknown[]): void {
if (this.debug_)
this.console_('RPC | [' + method + '] ' + eventName + ':', ...args)
}
}