{"id":15517111,"url":"https://github.com/macku/trainmanjs","last_synced_at":"2025-04-23T04:28:01.132Z","repository":{"id":57378928,"uuid":"85691449","full_name":"macku/trainmanjs","owner":"macku","description":"TrainmanJS - Cross-Origin Communication Library","archived":false,"fork":false,"pushed_at":"2019-07-13T04:54:21.000Z","size":30,"stargazers_count":16,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-17T19:18:11.371Z","etag":null,"topics":["child-frame","communication","cross-origin","eventemitter","events","frame","iframe","postmessage","postmessaging","trainman","trainmanjs"],"latest_commit_sha":null,"homepage":"","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/macku.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":"2017-03-21T10:58:24.000Z","updated_at":"2023-03-11T12:20:29.000Z","dependencies_parsed_at":"2022-09-02T21:20:59.500Z","dependency_job_id":null,"html_url":"https://github.com/macku/trainmanjs","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/macku%2Ftrainmanjs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/macku%2Ftrainmanjs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/macku%2Ftrainmanjs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/macku%2Ftrainmanjs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/macku","download_url":"https://codeload.github.com/macku/trainmanjs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250369687,"owners_count":21419259,"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":["child-frame","communication","cross-origin","eventemitter","events","frame","iframe","postmessage","postmessaging","trainman","trainmanjs"],"created_at":"2024-10-02T10:11:38.847Z","updated_at":"2025-04-23T04:28:01.115Z","avatar_url":"https://github.com/macku.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TrainmanJS\n\n[![npm version](https://img.shields.io/npm/v/trainmanjs.svg)](https://www.npmjs.com/package/trainmanjs)\n[![npm dependencies](https://img.shields.io/david/macku/trainmanjs.svg)](https://david-dm.org/macku/trainmanjs)\n[![npm dev dependencies](https://img.shields.io/david/dev/macku/trainmanjs.svg)](https://david-dm.org/macku/trainmanjs?type=dev)\n[![Build Status](https://travis-ci.org/macku/trainmanjs.svg?branch=master)](https://travis-ci.org/macku/trainmanjs)\n[![Coverage Status](https://s3.amazonaws.com/assets.coveralls.io/badges/coveralls_100.svg)](https://coveralls.io/github/macku/trainmanjs?branch=master)\n[![Greenkeeper badge](https://badges.greenkeeper.io/macku/trainmanjs.svg)](https://greenkeeper.io/)\n\nTrainmanJS is [Cross-Origin Communication Library](https://en.wikipedia.org/wiki/Cross-origin_resource_sharing). It's a\nwrapper for the native [`postMessage`](https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage) API.\n\nIt allows you to send bidirectional **Topics** and **Messages** between the **iframes** and wrapper (parent) window.\n\n[![Trainman](http://www.hotflick.net/flicks/2003_The_Matrix_Revolutions/fhd003TMR_Bruce_Spence_002.jpg)](http://matrix.wikia.com/wiki/The_Trainman)\n\n***The Trainman** is an exile who created and operates Mobil Avenue and is a servant of another exile program known as the Merovingian.*\n\nsource: http://matrix.wikia.com/wiki/The_Trainman\n\n## Features\n\n - Topics and messages\n  \n   You can listen to different kind of topics and message to it. You have control to which frame you would like to send\n   a message. What is also important, the parent frame knows exactly which child frame did send the message. Thanks to\n   that you can omit some topics from particular recipients inside your topic listener.\n \n - Lazy loading\n \n   Thanks to the queuing mechanism and buffer you can start sending messages immediately.\n   You can send a message from the wrapper (parent) window to the child iframe even it's still loading.\n   Queued messages will be delivered once the connection is established.\n   \n - Reconnection\n \n   When the child frame will reload itself, Trainman will try to reconnect with it. During the reconnection, Trainman\n   will queue messages inside his buffer. Queued messages will be delivered once the connection is established again.\n   \n - Bulk operation (upcoming)\n   \n   Post a message to all child frames at once. Don't need to specify an exact recipient. You can use the **'*'** symbol\n   for sending a message to all of the connect children frames.\n    \n - Debug mode\n   \n   Easily turn on and off logging mechanism. Thanks to that you can debug your code and application in a much more simple\n   way. You can track and check whole Trainman and Passenger communication.\n\n - F2F (upcoming)\n\n   Frame-to-frame direct communication. Allow to send and proxy messages directly between the child frames.\n\n\n## How to install\n\n### NPM and Yarn\n\nYou can install the library using **NPM**:\n\n```bash\nnpm install trainmanjs -S\n// or\nyarn add trainmanjs\n```\n\nNext, you can import **TrainmanJS** module into your app:\n\n```js\nimport Trainman from 'trainmnanjs';\n```\n\nFor the child pages (frames) you should import **Passenger** class:\n\n```js\nimport { Passenger } from 'trainmnanjs';\n````\n\n### Using CDN\n\nYou can also use the **CDN** service ex. [unpkg.com](https://unpkg.com/trainmanjs@0.5.0) or [npm-cdn.herrokuapp.com](http://npm-cdn.herokuapp.com/trainmanjs@0.5.0/lib/trainmanjs.js)\n\n```html\n\u003cscript src=\"https://unpkg.com/trainmanjs\"\u003e\u003c/script\u003e\n\n\u003c!-- or --\u003e\n\n\u003cscript src=\"http://npm-cdn.herokuapp.com/trainmanjs@0.5.0/lib/trainmanjs.js\"\u003e\u003c/script\u003e\n```\n\nThen you can access the **Trainman** and **Passenger** from the injected module:\n\n```js\n(function(module) {\n  const Trainman = module.Trainman;\n  const Passenger = module.Passenger;\n})(window.trainmanjs);\n```\n\n## How to use it\nTBA\n\n## Examples\n\n### Simple Example\n1. [Check simple example](https://rawgit.com/macku/trainmanjs/master/examples/simple/index.html) how to use Trainman\n2. [Here you can find the source code](/examples/simple/) for the above example\n\n### Re-connection and Debug Mode\n1. [Reconnection example](https://rawgit.com/macku/trainmanjs/master/examples/reconnect/index.html)\n2. [Here you can find the source code](/examples/reconnect/) for the above example\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmacku%2Ftrainmanjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmacku%2Ftrainmanjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmacku%2Ftrainmanjs/lists"}