A service for communicating between browser frames.
Life Cycle
- One of the frames triggers a session which the other frame can subscribe to by name via a callback.
- Once the subscriber's callback is called, its return value will be resolved within the initiator frame and the session will end.
Although the session has ended, the subscriber will be called next time when a new session with the same name will be initialized.
Installation
npm install crosser --save
Code Example
Frame 1
var Crosser = ; // Instantiationvar crosser = frame2contentWindow 'http://frame2.origin.com'; // Start a sessioncrosser ;
Frame 2
var Crosser = ; // Instantiationvar crosser = frame1contentWindow 'http://frame1.origin.com'; // Subscribe to a sessioncrosser;
API Reference
constructor(otherFrameWindow, otherFrameOrigin)
- arguments:
- otherFrameWindow [
Object
] - otherFrameOrigin [
String
]
- otherFrameWindow [
- Returns
object [
Object
]
trigger (sessionName, payload)
- arguments:
- sessionName [
String
] - payload [
Object
]
- sessionName [
- Returns
promise [
Promise
]
abort (sessionName)
- arguments:
- sessionName [
String
]
- sessionName [
subscribe (sessionName, callback)
- arguments:
- sessionName [
String
] - callback [
Function
]
- sessionName [
unsubscribe (sessionName)
- arguments:
- sessionName [
String
]
- sessionName [