Home Reference Source Test
import {RPC} from '@mixer/cdk'
public class | source

RPC

Extends:

eventemitter3~EventEmitter → RPC

Primitive postMessage based RPC for the controls to interact with the parent frame.

Constructor Summary

Public Constructor
public

constructor(target: window, protocolVersion: string, origin: string)

Creates a new RPC instance.

Method Summary

Public Methods
public

call(method: string, params: *, waitForReply: boolean): Promise.<object> | undefined

Makes an RPC call out to the target window.

public

Tears down resources associated with the RPC client.

public

expose(method: string, handler: function(params: any): Promise | *)

Attaches a method callable by the other window, to this one.

public

remoteVersion(): string | undefined

Returns the protocol version that the remote client implements.

Public Constructors

public constructor(target: window, protocolVersion: string, origin: string) source

Creates a new RPC instance. Note: you should use the rpc singleton, rather than creating this class directly, in your controls.

Params:

NameTypeAttributeDescription
target window

The window instance to make calls to or from.

protocolVersion string

The protocol version to communicate to the remote.

origin string
  • optional
  • default: '*'

Optionally, allow communication with the target if its origin matches this.

Public Methods

public call(method: string, params: *, waitForReply: boolean): Promise.<object> | undefined source

Makes an RPC call out to the target window.

Params:

NameTypeAttributeDescription
method string
params *
waitForReply boolean
  • optional
  • default: true

Return:

Promise.<object> | undefined

If waitForReply is true, a promise is returned that resolves once the server responds.

public destroy() source

Tears down resources associated with the RPC client.

public expose(method: string, handler: function(params: any): Promise | *) source

Attaches a method callable by the other window, to this one. The handler function will be invoked with whatever the other window gives us. Can return a Promise, or the results directly.

Params:

NameTypeAttributeDescription
method string
handler function(params: any): Promise | *

public remoteVersion(): string | undefined source

Returns the protocol version that the remote client implements. This will return undefined until we get a ready event.

Return:

string | undefined