{"id":18338716,"url":"https://github.com/tableflip/pull-postmsg-stream","last_synced_at":"2025-04-06T05:31:50.316Z","repository":{"id":57144089,"uuid":"119039751","full_name":"tableflip/pull-postmsg-stream","owner":"tableflip","description":"A pull source and sink for pulling over postMessage","archived":false,"fork":false,"pushed_at":"2018-04-19T15:18:33.000Z","size":168,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-18T12:34:05.979Z","etag":null,"topics":["postmessage","pull-stream"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/pull-postmsg-stream","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tableflip.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-01-26T10:38:49.000Z","updated_at":"2018-09-25T02:31:12.000Z","dependencies_parsed_at":"2022-09-05T13:00:13.735Z","dependency_job_id":null,"html_url":"https://github.com/tableflip/pull-postmsg-stream","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tableflip%2Fpull-postmsg-stream","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tableflip%2Fpull-postmsg-stream/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tableflip%2Fpull-postmsg-stream/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tableflip%2Fpull-postmsg-stream/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tableflip","download_url":"https://codeload.github.com/tableflip/pull-postmsg-stream/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247440346,"owners_count":20939221,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["postmessage","pull-stream"],"created_at":"2024-11-05T20:14:56.316Z","updated_at":"2025-04-06T05:31:49.642Z","avatar_url":"https://github.com/tableflip.png","language":"JavaScript","readme":"# pull-postmsg-stream\n\n[![Build Status](https://travis-ci.org/tableflip/pull-postmsg-stream.svg?branch=master)](https://travis-ci.org/tableflip/pull-postmsg-stream)\n[![dependencies Status](https://david-dm.org/tableflip/pull-postmsg-stream/status.svg)](https://david-dm.org/tableflip/pull-postmsg-stream)\n[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)\n\n\u003e Pull streams over `window.postMessage`\n\nIt provides the two parts of a [through stream](https://github.com/pull-stream/pull-stream/blob/master/docs/spec.md#through-streams): a source stream and a sink stream that can be used together to stream data over `window.postMessage`.\n\n## Install\n\n```sh\nnpm install pull-postmsg-stream\n```\n\n## Usage\n\nTo use `pull-postmsg-stream` you need two window objects. One of the window objects _has_ the data, the other _wants_ the data. Under the hood, `pull-postmsg-stream` uses [`postmsg-rpc`](https://github.com/tableflip/postmsg-rpc). If you're not familiar with it, it's a good idea to read up on how it works before continuing!\n\nIn the first window (the one that _has_ the data):\n\n```js\nconst pull = require('pull-stream')\nconst PMS = require('pull-postmsg-stream')\n\npull(\n  pull.values([/* your data */]),\n  PMS.sink('read', {/* options passed to postmsg-rpc expose */})\n)\n```\n\nIn the second window (the one that _wants_ the data):\n\n```js\nconst pull = require('pull-stream')\nconst PMS = require('pull-postmsg-stream')\n\npull(\n  PMS.source('read', {/* options passed to postmsg-rpc caller */}),\n  pull.collect(console.log) // Collects and logs out your data\n)\n```\n\n1. Window that _has_ the data calls `PMS.sink`, which **exposes** a function called \"read\" \u0026 returns a [sink stream](https://github.com/pull-stream/pull-stream/blob/master/docs/spec.md#sink-streams)\n2. Window that _wants_ the data calls `PMS.source`, which creates a **caller** function for \"read\" \u0026 returns a [source stream](https://github.com/pull-stream/pull-stream/blob/master/docs/spec.md#source-streams)\n3. In the window that _wants_ the data, the `pull(...)` pipeline starts the flow of data from the `PMS.source` stream\n4. When data is requested from the `PMS.source` stream, it **calls** the **exposed** \"read\" function\n5. This causes the `PMS.sink` stream in the window that _has_ the data to pull out of `pull.values` and return it all the way back to `pull.collect` in the window that _wants_ the data\n\nSee the [example](example) for complete code.\n\n### Example\n\nTo build and run the [example](example), run the following in your terminal:\n\n```sh\ngit clone https://github.com/tableflip/pull-postmsg-stream.git\ncd pull-postmsg-stream\nnpm install\nnpm run example\n```\n\nThen open your browser at `http://localhost:3000`\n\n## API\n\n### `PMS.sink(readFnName, options)`\n\nCreates a new [sink stream](https://github.com/pull-stream/pull-stream/blob/master/docs/spec.md#sink-streams) for exposing data to be pulled over `postMessage`.\n\n* `readFnName` - the name of the function that `postmsg-rpc` will expose for a `PMS.source` stream to read from\n* `options` - options passed directly to `postmsg-rpc` `expose`, see [docs here](https://github.com/tableflip/postmsg-rpc#exposefuncname-func-options)\n    * `options.post` - function to call after read, see [docs here](https://github.com/tableflip/prepost#postfunc-postfunc--postfunc1-postfunc2-)\n\nNote that if you're going to create multiple streams, you'll need to generate a new `readFnName` for each stream and somehow communicate that to your other window so that it can create a `PMS.source` that reads from the correct place.\n\n### `PMS.source(readFnName, options)`\n\nCreates a new [source stream](https://github.com/pull-stream/pull-stream/blob/master/docs/spec.md#source-streams) for pulling data over `postMessage`.\n\n* `readFnName` - the same name that was passed to `PMS.sink`, allowing the source to read from the sink\n* `options` - options passed directly to `postmsg-rpc` `caller`, see [docs here](https://github.com/tableflip/postmsg-rpc#callerfuncname-options)\n    * `options.post` - function to call after read, see [docs here](https://github.com/tableflip/prepost#postfunc-postfunc--postfunc1-postfunc2-)\n\n## Contribute\n\nFeel free to dive in! [Open an issue](https://github.com/tableflip/pull-postmsg-stream/issues/new) or submit PRs.\n\n## License\n\n[MIT](LICENSE) © Alan Shaw\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftableflip%2Fpull-postmsg-stream","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftableflip%2Fpull-postmsg-stream","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftableflip%2Fpull-postmsg-stream/lists"}