A function to generate a unique ID for an object.
When sending an object to the other side that can not be serialized, we generate an ID and send that instead. The other side creates a proxy object that represents the remote object.
Stores the current "context" object that is passed to the callback of the RPCChannel.receive function.
Connect the service to a channel.
Gets or creates a proxy "class" that will serve multiple purposes.
Gets or creates a proxy function that represents a host object from the other side.
This side must have the descriptor for the function. See sendRemoteDescriptors, requestRemoteDescriptors.
Gets or creates a proxy object that represents a host object from the other side.
This side must have the descriptor for the object. See sendRemoteDescriptors, requestRemoteDescriptors.
Register a class in the service.
When an instance of this class is passed to the other side, only the "readonlyProperties" are sent (see ClassDescriptor). Functions and proxied properties are generated there and those call back to the original object.
Even the constructor can be proxied.
Note: static functions/properties act as if the class was a normal host object.
An ID to identify the class on the client side.
The class itself (its constructor function)
What properties/functions to expose
Register a function in the service to be called remotely.
An ID that the "client" side uses to identify this function.
The target function
Describes arguments and return behavior (FunctionReturnBehavior)
Register an object in the service to be called remotely.
An ID that the "client" side uses to identify this object.
The target object
Describes which functions/properties to expose
Send a request to get the descriptors for the registered host objects from the other side.
Uses synchronous communication if possible and returns true/false based on if the descriptors were received.
If sync is not available, it uses async messaging and returns a Promise.
Send the descriptors for the registered host objects to the other side. If possible, the message is sent synchronously. This is a "push" style message, for "pull" see requestRemoteDescriptors.
Generated using TypeDoc
The SuperRPC is the central piece. An instance must be created on both sides.
Objects, functions or classes can be registered on the "host" side (see registerHostObject, registerHostClass) and then functions/properties can be called from the "client" side (see getProxyObject, getProxyClass).
The RPC service is symmetric, so depending on the use-case (and the channel), both side can be "host" and "client" at the same time.
The constructor needs a function to generate unique IDs for objects. In order to have no dependencies this needs to be passed in. For convenience the examples use nanoid.