How oeway/hypha-rpc works
Main Components
• Client Libraries (Python and JavaScript): Represent separate modules that handle the RPC communication. Each has its own “src” or “hypha_rpc” code base with utilities for transport management, encoding/decoding data types, and handling remote calls.
• Transport Layer: Identify the business logic that manages two different transports:
– WebSocket Clients (e.g., javascript/src/websocket-client.js and python/hypha_rpc/websocket_client.py)
– WebRTC support (e.g., javascript/src/webrtc-client.js and python/hypha_rpc/pyodide_sse.py, along with rtc service functions)
• Data Encoding/Decoding Mechanism: Components responsible for custom codecs, type conversion, and unified data representation. Illustrate the codec registration and data transformation layer.
• RPC Core Logic: The central module that integrates function calls (both synchronous and asynchronous), including how remote calls traverse the transport layer.
Relationships and Interactions
• Flow where custom data objects are first encoded (using custom codecs) on the client, sent as JSON (with potential binary data), and then decoded on the other end.
• Interactions such as login and connection establishment that involve token generation, plus the optional registration of telemetry or login callbacks.
Architectural Patterns and Design Principles
• Modular Design: Emphasize a separation between language-specific client implementations with common shared concepts (RPC invocation, codec handling).
• Client-Server Model: Clearly demarcate the client libraries (consider grouping the JavaScript and Python implementations side by side) and the external Hypha server that provides services.
• Layered Architecture: At the lowest level, the transport layer (WebSocket, WebRTC). In the middle, the encoding/decoding logic, and at the top, the RPC interfaces offered to the developer (including synchronous wrappers).
• Extensibility: Highlight the codec registration pattern which allows support for custom data types.
Technologies, Frameworks, and Libraries
• In JavaScript: ESLint, Prettier for style; Webpack for bundling; and specialized client modules (rpc.js, websocket-client.js, webrtc-client.js).
• In Python: Packaging files (setup.cfg, pyproject.toml), asynchronous modules (asyncio), and the synchronous wrapper (hypha_rpc.sync).
• Both sides use JSON for structured data representation and are set up to handle binary as well via ArrayBuffer/bytes.