iframe-stream

3.0.0 • Public • Published

iframe-stream

Create a stream around an iframe via post-message-stream

const IframeStream = require('iframe-stream').IframeStream
 
var iframe = createIframe()
var iframeStream = IframeStream(iframe)

Note

  • Setup the stream immediately, so we don't miss the iframe's load event.
  • The IframeStream will buffer all input until the childstream is ready.
  • This is an object stream, and buffers will not be handled gracefully.

Example

Here is an example using dnode to create a callback based API with a javascript context inside an iframe.

Parent:

const IframeStream = require('iframe-stream').IframeStream
const Dnode = require('dnode')
 
var iframe = createIframe()
var iframeStream = IframeStream(iframe)
var dnode = Dnode()
dnode.on('remote', function(child){
  child.doAsyncSomething(function(){
    console.log('child finished doing the thing!')
  })
})
 
dnode.pipe(iframeStream).pipe(dnode)

Child:

const ParentStream = require('iframe-stream').ParentStream
const Dnode = require('dnode')
 
var parentStream = ParentStream(iframe)
var dnode = Dnode({
  doAsyncSomething: function (cb) {
    console.log('doing something async...')
    cb()
  }
})
 
dnode.pipe(parentStream).pipe(dnode)

Package Sidebar

Install

npm i iframe-stream

Weekly Downloads

6

Version

3.0.0

License

ISC

Last publish

Collaborators

  • kumavis