{"id":16227960,"url":"https://github.com/tborychowski/poster","last_synced_at":"2025-04-08T04:42:35.764Z","repository":{"id":145624298,"uuid":"93640194","full_name":"tborychowski/poster","owner":"tborychowski","description":"2-way postMessage","archived":false,"fork":false,"pushed_at":"2018-06-13T13:38:34.000Z","size":19,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-14T03:23:30.756Z","etag":null,"topics":["javascript","postmessage"],"latest_commit_sha":null,"homepage":null,"language":"HTML","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tborychowski.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-06-07T13:47:20.000Z","updated_at":"2022-01-13T16:59:21.000Z","dependencies_parsed_at":"2023-06-29T01:46:00.286Z","dependency_job_id":null,"html_url":"https://github.com/tborychowski/poster","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tborychowski%2Fposter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tborychowski%2Fposter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tborychowski%2Fposter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tborychowski%2Fposter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tborychowski","download_url":"https://codeload.github.com/tborychowski/poster/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247779796,"owners_count":20994571,"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":["javascript","postmessage"],"created_at":"2024-10-10T12:54:15.337Z","updated_at":"2025-04-08T04:42:35.747Z","avatar_url":"https://github.com/tborychowski.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# poster\n2-way postMessage\n\n\n## API\n\n#### initialisation\n```js\n/**\n * Poster\n * @param target - DOM node of the target:\n *                - if it's a parent app - target should be the iframe to which messages are sent\n *                - if initialisation is inside the iframe - the target would usually be the top/parent window\n * @param onMessageReceivedCallback - function that will be called when a message is received FROM the target\n */\nconst poster = new Poster(target, onMessageReceivedCallback);\n\n/**\n * onMessageReceivedCallback\n * @param actionName - or channel; any string will do\n * @param params - can be a primitive, or a [serialisable](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm) object that will be passed along with the message\n * @param responseCallback [optional] - if the received message expects a callback - this function should be called\n */\nfunction onMessageReceivedCallback (actionName, params, responseCallback) { }\n```\n\n#### sending messages\n```js\n/**\n * poster.send\n * @param actionName - or channel; any string will do\n * @param params - can be a primitive, or a [serialisable](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm) object that will be passed along with the message\n * @param responseCallback [optional] - if a callback is needed - the passed function will be called, once the receiver responds to this message\n */\nposter.send(actionName, params, responseCallback);\n```\n\n## Example usage\n\n**index.html**\n```js\nconst p = new Poster(document.getElementById('frame'), (action, params, cb) =\u003e {\n    console.log('parent: onmessage', action, params);\n    \n    setTimeout(() =\u003e {\n        cb({ response: 'callback from parent' });\n    }, 1000);\n});\n\n\n\np.send('parent-frame', { param: 'param one' }, msg =\u003e {\n    console.log('parent: callback message', msg);\n});\n```\n\n\n**frame.html**\n```js\nconst p = new Poster(window.top, (action, params, cb) =\u003e {\n    console.log('frame: onmessage', action, params);\n    \n    setTimeout(() =\u003e {\n        cb({ response: 'callback from frame' });\n    }, 1000);\n});\n\n\n\np.send('parent-frame', { param: 'param one' }, msg =\u003e {\n    console.log('parent: callback message', msg);\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftborychowski%2Fposter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftborychowski%2Fposter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftborychowski%2Fposter/lists"}