- rpc
This commit is contained in:
2024-10-27 11:47:55 +00:00
parent 7369ff8868
commit 640adae8a5
28 changed files with 7875 additions and 9992 deletions
+33
View File
@@ -0,0 +1,33 @@
import { Environment, Errors, RPCState, Utils } from './utils'
export class Wrapper {
protected environment_ = Utils.getEnvironment()
protected state_ =
this.environment_ === Environment.BROWSER ? window : global
protected verifyEvent_(data: string | RPCState): RPCState {
let rpcData =
typeof data === 'string' ? Utils.prepareExecution(data) : data
if (!this.state_[rpcData.eventName]) {
rpcData.knownError = Errors.EVENT_NOT_REGISTERED
}
return rpcData
}
protected triggerError_(rpcData: RPCState, error?: any) {
const errorMessage = [
`${rpcData.knownError}`,
`Caller: ${rpcData.calledFrom}`,
`Receiver: ${this.environment_}`,
`Event: ${rpcData.eventName}`,
]
if (error) {
errorMessage.push(`Additional Info: ${error}`)
}
throw new Error(errorMessage.join('\n | '))
}
}