MCPcopy Create free account
hub / github.com/Noumena-Network/code / handleRawMessage

Method handleRawMessage

src/remote/appServer/client.ts:469–503  ·  view source on GitHub ↗
(raw: string)

Source from the content-addressed store, hash-verified

467 }
468
469 private handleRawMessage(raw: string): void {
470 let message: unknown
471 try {
472 message = jsonParse(raw)
473 } catch (error) {
474 this.close(
475 `remote app server at ${this.args.websocketUrl} sent invalid JSON-RPC: ${String(error)}`,
476 )
477 return
478 }
479
480 if (isJsonRpcResponse(message)) {
481 const pending = this.pendingRequests.get(requestIdKey(message.id))
482 if (pending) {
483 this.pendingRequests.delete(requestIdKey(message.id))
484 pending.resolve(message.result)
485 }
486 return
487 }
488 if (isJsonRpcError(message)) {
489 const pending = this.pendingRequests.get(requestIdKey(message.id))
490 if (pending) {
491 this.pendingRequests.delete(requestIdKey(message.id))
492 pending.reject(new Error(message.error.message))
493 }
494 return
495 }
496 if (isJsonRpcNotification(message)) {
497 this.enqueueEvent(appServerEventFromNotification(message))
498 return
499 }
500 if (isJsonRpcRequest(message)) {
501 this.enqueueEvent({ type: 'server_request', request: message })
502 }
503 }
504
505 private enqueueEvent(event: RemoteAppServerEvent): void {
506 if (this.skippedEvents > 0) {

Callers 1

openMethod · 0.95

Calls 13

closeMethod · 0.95
enqueueEventMethod · 0.95
jsonParseFunction · 0.85
isJsonRpcResponseFunction · 0.85
requestIdKeyFunction · 0.85
isJsonRpcErrorFunction · 0.85
isJsonRpcNotificationFunction · 0.85
isJsonRpcRequestFunction · 0.85
deleteMethod · 0.80
resolveMethod · 0.80
rejectMethod · 0.80

Tested by

no test coverage detected