Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
| IJsonRpcRequest
| IJsonRpcResponseSuccess
| IJsonRpcResponseError
| IInternalEvent
): void {
let eventEmitters: IEventEmitter[] = []
let event: string
if (isJsonRpcRequest(payload)) {
event = payload.method
} else if (
isJsonRpcResponseSuccess(payload) ||
isJsonRpcResponseError(payload)
) {
event = `response:${payload.id}`
} else if (isInternalEvent(payload)) {
event = payload.event
} else {
event = ''
}
if (event) {
eventEmitters = this._eventEmitters.filter(
(eventEmitter: IEventEmitter) => eventEmitter.event === event
)
}
if (
(!eventEmitters || !eventEmitters.length) &&
!isReservedEvent(event) &&
!isInternalEvent(event)
) {
} else if (isInternalEvent(payload)) {
event = payload.event
} else {
event = ''
}
if (event) {
eventEmitters = this._eventEmitters.filter(
(eventEmitter: IEventEmitter) => eventEmitter.event === event
)
}
if (
(!eventEmitters || !eventEmitters.length) &&
!isReservedEvent(event) &&
!isInternalEvent(event)
) {
eventEmitters = this._eventEmitters.filter(
(eventEmitter: IEventEmitter) => eventEmitter.event === 'call_request'
)
}
eventEmitters.forEach((eventEmitter: IEventEmitter) => {
if (isJsonRpcResponseError(payload)) {
const error = new Error(payload.error.message)
eventEmitter.callback(error, null)
} else {
eventEmitter.callback(null, payload)
}
})
}
}