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

Method onMessage

src/remote/appServer/client.ts:401–436  ·  view source on GitHub ↗
(data: WS.RawData)

Source from the content-addressed store, hash-verified

399 await timeoutPromise(
400 new Promise<void>((resolve, reject) => {
401 const onMessage = (data: WS.RawData) => {
402 let message: unknown
403 try {
404 message = jsonParse(String(data))
405 } catch (error) {
406 cleanup()
407 reject(
408 new Error(
409 `remote app server at ${this.args.websocketUrl} sent invalid initialize response: ${String(error)}`,
410 ),
411 )
412 return
413 }
414
415 if (isJsonRpcResponse(message) && message.id === INITIALIZE_REQUEST_ID) {
416 cleanup()
417 resolve()
418 return
419 }
420 if (isJsonRpcError(message) && message.id === INITIALIZE_REQUEST_ID) {
421 cleanup()
422 reject(
423 new Error(
424 `remote app server at ${this.args.websocketUrl} rejected initialize: ${message.error.message}`,
425 ),
426 )
427 return
428 }
429 if (isJsonRpcNotification(message)) {
430 pendingEvents.push(appServerEventFromNotification(message))
431 return
432 }
433 if (isJsonRpcRequest(message)) {
434 pendingEvents.push({ type: 'server_request', request: message })
435 }
436 }
437 const onClose = () => {
438 cleanup()
439 reject(

Callers 3

handleMessageMethod · 0.80
handleMessageMethod · 0.80
connectMethod · 0.80

Calls 8

jsonParseFunction · 0.85
isJsonRpcResponseFunction · 0.85
isJsonRpcErrorFunction · 0.85
isJsonRpcNotificationFunction · 0.85
isJsonRpcRequestFunction · 0.85
cleanupFunction · 0.50
resolveFunction · 0.50

Tested by

no test coverage detected