* Handle serverside callback via WebSocket connection. * * Uses the SharedWorker to send the callback request through the persistent * WebSocket connection instead of HTTP POST.
(
dispatch: any,
hooks: any,
config: any,
payload: ICallbackPayload,
running: any
)
| 697 | * WebSocket connection instead of HTTP POST. |
| 698 | */ |
| 699 | async function handleWebsocketCallback( |
| 700 | dispatch: any, |
| 701 | hooks: any, |
| 702 | config: any, |
| 703 | payload: ICallbackPayload, |
| 704 | running: any |
| 705 | ): Promise<CallbackResponse> { |
| 706 | if (hooks.request_pre) { |
| 707 | hooks.request_pre(payload); |
| 708 | } |
| 709 | |
| 710 | const requestTime = Date.now(); |
| 711 | let runningOff: any; |
| 712 | |
| 713 | if (running) { |
| 714 | dispatch(sideUpdate(running.running, payload)); |
| 715 | runningOff = running.runningOff; |
| 716 | } |
| 717 | |
| 718 | const workerClient = getWorkerClient(); |
| 719 | |
| 720 | try { |
| 721 | // Ensure WebSocket connection is established |
| 722 | await workerClient.ensureConnected(config); |
| 723 | |
| 724 | const response = await workerClient.sendCallback(payload); |
| 725 | |
| 726 | // Handle running off state |
| 727 | if (runningOff) { |
| 728 | dispatch(sideUpdate(runningOff, payload)); |
| 729 | } |
| 730 | |
| 731 | if (response.status === 'prevent_update') { |
| 732 | // Record timing for profiling |
| 733 | if (config.ui) { |
| 734 | const totalTime = Date.now() - requestTime; |
| 735 | dispatch( |
| 736 | updateResourceUsage({ |
| 737 | id: payload.output, |
| 738 | usage: { |
| 739 | __dash_server: totalTime, |
| 740 | __dash_client: totalTime, |
| 741 | __dash_upload: 0, |
| 742 | __dash_download: 0 |
| 743 | }, |
| 744 | status: STATUS.PREVENT_UPDATE, |
| 745 | result: {}, |
| 746 | inputs: payload.inputs, |
| 747 | state: payload.state |
| 748 | }) |
| 749 | ); |
| 750 | } |
| 751 | return {}; |
| 752 | } |
| 753 | |
| 754 | if (response.status === 'error') { |
| 755 | throw new Error(response.message || 'Callback error'); |
| 756 | } |
no test coverage detected
searching dependent graphs…