psa-api
v0.0.2
Published
Collection of logic for psa api connect
Downloads
117
Readme
psa-api
A Socket.IO client wrapper for Python backend communication.
Installation
npm install psa-api
# or
yarn add psa-api
Usage
import { initializeSocket, sendMessage, subscribeMessage } from "psa-api";
// Initialize socket connection
initializeSocket((message) => {
console.log(message); // "Connected to Python backend!"
});
// Send a message
sendMessage({ data: "Hello Python!" });
// Subscribe to messages
subscribeMessage((data) => {
console.log("Received:", data);
});
// Send and receive in one call
import { sendAndReceive } from "psa-api";
const response = await sendAndReceive("custom-topic", { data: "test" }, (data) => {
console.log("Received response:", data);
});
API
initializeSocket(onConnect?: (message: string) => void)
: Initialize socket connectionsendMessage(value: any)
: Send a message on the "message" topicsubscribeMessage(callback: (values?: any) => void)
: Subscribe to messages on the "message" topiconceMessage(callback: (values?: any) => void)
: Listen for a single message on the "message" topicsend(topic: string, value: any)
: Send a message on a custom topicsubscribe(topic: string, callback: (values?: any) => void)
: Subscribe to messages on a custom topiconce(topic: string, callback: (values?: any) => void)
: Listen for a single message on a custom topicsendAndReceive(topic: string, value: any, callback: (values?: any) => void): Promise<unknown>
: Send a message and wait for a response
License
MIT