@ceramicnetwork/rpc-iframe
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

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

  1. Methods extends RPCMethods
  2. Namespace extends string = string

Arguments

  1. namespace: Namespace
  2. methods: HandlerMethods<IncomingRequest<Methods, Namespace>, Methods>

Returns Observable<ServerPayload<Methods, Namespace>>

createClient()

Type parameters

  1. Methods extends RPCMethods
  2. Namespace extends string = string

Arguments

  1. namespace: Namespace
  2. target: PostMessageTarget
  3. options?: ClientOptions

Returns RPCClient<Methods>

License

Apache-2.0 OR MIT

Readme

Keywords

Package Sidebar

Install

npm i @ceramicnetwork/rpc-iframe

Weekly Downloads

2

Version

0.1.0

License

(Apache-2.0 OR MIT)

Unpacked Size

16.6 kB

Total Files

10

Last publish

Collaborators

  • dav1do
  • ceramic-velvetshark
  • cb3box
  • jpham2023
  • npm.3box
  • smrz2001
  • oed
  • paul_lecam
  • stbrody
  • ukstv