iframes

package
Version: v0.0.0-...-c3c9c93 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 17, 2017 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package iframes provides abstractions for inter-iframe communication

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init()

Init installs the event listener to receive messages from iframes.

func RegisterListener

func RegisterListener(mtype string, lf ListenerFunc)

RegisterListener registers a ListnerFunc to receive messages of the given type.

func UnregisterIframe

func UnregisterIframe(iframeID string) error

UnregisterIframe unregisters the iframe. This should be called whenever the iframe is removed from the DOM. Any Respond functions corresponding to this iframe will be invalidated.

Types

type ListenerFunc

type ListenerFunc func(cardID string, payload *js.Object, respond Respond) error

ListenerFunc is a function which responds to a parsed iframe message. It receives the original payload, and a function which may be called with a response to the original iframe.

A ListenerFunc is called as a JS callback, so it may not block.

type Message

type Message struct {
	*js.Object
	Type     string     `js:"type"`
	IframeID string     `js:"iframeID"`
	CardID   string     `js:"cardID"`
	Payload  *js.Object `js:"payload"`
}

Message is a message to be sent to or received from an iframe

type Respond

type Respond func(mtype string, payload interface{}, transferrable ...*js.Object) error

Respond sends a response to the iframe

func RegisterIframe

func RegisterIframe(iframeID, cardID string) (Respond, error)

RegisterIframe associates an iframe ID with a card ID so that requests can be served. A Responder is returned, which may then be used to send messages to the iframe.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL