Replies: 4 comments 11 replies
-
Hi @Koliham :) That being said, while you got the basic schema correct; you have left out the rest of the RPC protocol, which would be my prime suspect for the issues you're experiencing. Primarily not receiving the responses sent back for your RPC (subscribe) call |
Beta Was this translation helpful? Give feedback.
-
I've added more tips on how to implement the RPC protocol here for JS: |
Beta Was this translation helpful? Give feedback.
-
Hi @orweis and @Koliham Here is some example code. const WebSocket = require("ws");
try {
socketClient = new WebSocket('ws://localhost:3010/pubsub');
socketClient?.on("open", async () => {
await socketClient?.send(
'{"request": {"method": "subscribe", "arguments": {"topics": ["a", "b", "c", "d", "e", "f", "g"]}}}');
socketClient?.on("message", async (data) => {
try {
const request = JSON.parse(data);
const body = JSON.parse(request?.request?.arguments?.data);
const call_id = request?.request?.call_id;
console.log(`request: ${JSON.stringify(request)}`);
console.log(`body: ${JSON.stringify(body)}`);
if (body) {
console.log(JSON.stringify(body));
const topic = body?.topic?.toString() ?? undefined;
console.log(`Webhook Challenged Date: ${JSON.stringify(new Date().toISOString())} | topic: ${topic} | Body: ${JSON.stringify(body)}`);
try {
const notify = {
"response": {
"result": "None",
"result_type": "None",
"call_id": call_id
}
};
console.log(`NOTIFYING ${JSON.stringify(notify)}`);
socketClient?.send(JSON.stringify(notify));
} catch (ex) {
console.log(JSON.stringify(ex));
}
//send heartbeat
//this.socketClient.send("heartbeat");
// }
}
} catch (ex) {
console.log(JSON.stringify(ex));
}
});
});
socketClient?.on("error", (data) => {
console.log(data.toString());
});
socketClient?.on("close", (data) => {
console.log(data.toString());
});
} catch (ex) {
console.log(JSON.stringify(ex));
} |
Beta Was this translation helpful? Give feedback.
-
Hi, I'm writing my own frontend client for fastapi_pubsub and fastapi_websocket_rpc in typescript. See the files in this folder: https://github.com/Open-Pectus/Open-Pectus/tree/e68ca4e9bbc0a08563a355365c7da266cb02f069/openpectus/frontend/src/fastapi_websocket I'm writing it as a consultant on an open source project, and we're interested in giving back to the community, but I have no plan to support it once I'm no longer attached to the project. I've written a client for RPC, one for pubsub exposing promises, and one for pubsub exposing it as RxJs Observables (useful in Angular in particular). There's a number of features not implemented, that I might implement later, but I'm not sure I will need them all:
|
Beta Was this translation helpful? Give feedback.
-
I was able to extract the payloads sent between client and server to create a Javascript client with websocket (code below).
But there are 2 issues, which I haven't solved yet:
Click to see stack trace!
Frontend Code
Backend Code
Beta Was this translation helpful? Give feedback.
All reactions