feat rpc
- 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:
+31
-4
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user