@ceramicnetwork/rpc-iframe
v0.1.0
Published
[RPC utilities](https://github.com/ceramicnetwork/js-rpc-utils#rpc-utils) using iframe
Downloads
6
Readme
iframe RPC
RPC utilities using iframe
Installation
npm install @ceramicnetwork/rpc-iframe
Usage
import { createClient, createServer } from '@ceramicnetwork/rpc-iframe'
type Methods = {
foo: { result: string }
}
const methods = { foo: () => 'bar' }
const server = createServer<Methods>('test', methods).subscribe()
const client = createClient<Methods>('test', window)
await client.request('foo') // 'bar'
// Stop server when done
server.unsubscribe()
Types
ClientOptions
Uses UnwrapObservableOptions
from @ceramicnetwork/transport-subject
and PostMessageTransportOptions
from @ceramicnetwork/transport-postmessage
type ClientOptions = UnwrapObservableOptions & PostMessageTransportOptions
IncomingRequest
Uses RPCMethods
, RPCRequest
, IncomingMessage
from @ceramicnetwork/transport-postmessage
and Wrapped
from @ceramicnetwork/transport-subject
type IncomingRequest<
Methods extends RPCMethods,
Namespace extends string = string
> = IncomingMessage<Wrapped<RPCRequest<Methods, keyof Methods>, Namespace>>
ServerPayload
Uses RPCMethods
, HandledPayload
from @ceramicnetwork/rpc-postmessage
and IncomingRequest
type ServerPayload<Methods extends RPCMethods, Namespace extends string> = HandledPayload<
IncomingRequest<Methods, Namespace>,
Methods,
keyof Methods
>
APIs
createServer()
Type parameters
Methods extends RPCMethods
Namespace extends string = string
Arguments
namespace: Namespace
methods: HandlerMethods<IncomingRequest<Methods, Namespace>, Methods>
Returns Observable<ServerPayload<Methods, Namespace>>
createClient()
Type parameters
Methods extends RPCMethods
Namespace extends string = string
Arguments
namespace: Namespace
target: PostMessageTarget
options?: ClientOptions
Returns RPCClient<Methods>
License
Apache-2.0 OR MIT