
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
rxprotoplex-rpc
Advanced tools
connectAndRpc$
and listenAndConnectionAndRpc$
are utility functions designed for establishing connections and creating RPC (Remote Procedure Call) instances from streams in a reactive programming context. These functions are built using RxJS and leverage JSON encoding for data transmission over specified channels. They also include configurable parameters such as timeout settings for enhanced control.
Additionally, the module provides utility operators like switchRpcRequest
, tapNotify
, and tapExpose
for handling RPC requests, notifications, and exposing methods within an observable stream.
To use connectAndRpc$
, listenAndConnectionAndRpc$
, switchRpcRequest
, tapNotify
, and tapExpose
, make sure to import them from your module:
import { connectAndRpc$, listenAndConnectionAndRpc$, switchRpcRequest, tapNotify, tapExpose } from 'rxprotoplex-rpc';
connectAndRpc$
Establishes a connection to the provided plex
object, sets up a communication channel with JSON encoding, and returns an observable that emits an RPC instance created from the stream.
const rpc$ = connectAndRpc$(plex, channel, config);
plex
(Object): The connection object representing the peer or signaling entity.channel
(Uint8Array, optional): The channel for the connection, defaulting to CHANNEL
(b4a.from("$RPC$")
).config
(Object, optional): Configuration object for the RPC setup.
timeout
(number, optional): Timeout duration for the RPC, in milliseconds.connectAndRpc$(plex, CHANNEL, { timeout: 5000 }).subscribe(rpc => {
// Use the rpc instance here
rpc.request.someMethod().then(response => console.log(response));
});
listenAndConnectionAndRpc$
Listens for connections on the given plex
object, sets up a communication channel with JSON encoding, and returns an observable that emits an RPC instance created from the connected stream.
const rpc$ = listenAndConnectionAndRpc$(plex, channel, config);
plex
(Object): The connection listener object representing where connections are managed.channel
(Uint8Array, optional): The channel for listening and connection, defaulting to CHANNEL
(b4a.from("$RPC$")
).config
(Object, optional): Configuration object for the RPC setup.
timeout
(number, optional): Timeout duration for the RPC, in milliseconds.listenAndConnectionAndRpc$(plex, CHANNEL, { timeout: 10000 }).subscribe(rpc => {
// Use the rpc instance here
rpc.request.anotherMethod().then(result => console.log(result));
});
switchRpcRequest
An RxJS operator that switches to a new observable for each emission and makes an RPC request using the specified method and arguments.
observable$.pipe(switchRpcRequest(method, ...args));
method
(string): The method name to be called on the RPC request object.args
(...any): Additional arguments to be passed to the method.const [p1, p2] = createPlexPair();
const rpcClient = connectAndRpc$(p2).pipe(
switchRpcRequest('add', 5, 6),
tap(({ rpc }) => rpc.stream.destroy())
).subscribe(
({ ack: sum }) => {
console.log('Sum:', sum); // Output: Sum: 11
}
);
tapNotify
An RxJS tap
operator that calls a notification method on the RPC object as a side-effect.
observable$.pipe(tapNotify(methodName, ...args));
methodName
(string): The name of the notification method to be called on the RPC object.args
(...any): Additional arguments to be passed to the notification method.tap
operator that performs a side-effect by calling the specified notification method with the provided arguments.observable$.pipe(
tapNotify('notifyMethod', param1)
).subscribe();
tapExpose
An RxJS tap
operator that exposes an object containing RPC methods on the RPC instance.
observable$.pipe(tapExpose(exposeObject));
exposeObject
(Object): The object containing RPC methods to be exposed on the RPC instance.tap
operator that performs a side-effect by calling the expose
method on the RPC instance with the provided object.const [p1, p2] = createPlexPair();
const rpcServer = listenAndConnectionAndRpc$(p1).pipe(
tapExpose({
add(a, b) {
return a + b;
}
})
).subscribe();
CHANNEL
A predefined constant for channel identification:
export const CHANNEL = b4a.from("$RPC$");
This module is licensed under MIT License.
For more details on how to extend or modify these functions, refer to the code comments or inline documentation.
FAQs
A library for managing RPC connections using RxJS and Protoplex.
The npm package rxprotoplex-rpc receives a total of 1 weekly downloads. As such, rxprotoplex-rpc popularity was classified as not popular.
We found that rxprotoplex-rpc demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.