{"id":18889769,"url":"https://github.com/scottlogic/comlink-openfin","last_synced_at":"2025-10-13T13:15:27.586Z","repository":{"id":73352976,"uuid":"317484656","full_name":"ScottLogic/comlink-openfin","owner":"ScottLogic","description":"ComLink endpoint to use OpenFin IAB as a transport","archived":false,"fork":false,"pushed_at":"2020-12-09T08:35:50.000Z","size":19,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":29,"default_branch":"main","last_synced_at":"2025-05-24T03:41:40.429Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ScottLogic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2020-12-01T09:08:33.000Z","updated_at":"2020-12-14T09:00:44.000Z","dependencies_parsed_at":null,"dependency_job_id":"f6de11f4-4238-42ef-84bc-6fd7221ad1ca","html_url":"https://github.com/ScottLogic/comlink-openfin","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ScottLogic/comlink-openfin","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ScottLogic%2Fcomlink-openfin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ScottLogic%2Fcomlink-openfin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ScottLogic%2Fcomlink-openfin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ScottLogic%2Fcomlink-openfin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ScottLogic","download_url":"https://codeload.github.com/ScottLogic/comlink-openfin/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ScottLogic%2Fcomlink-openfin/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279015299,"owners_count":26085683,"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","status":"online","status_checked_at":"2025-10-13T02:00:06.723Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-11-08T07:50:49.567Z","updated_at":"2025-10-13T13:15:27.555Z","avatar_url":"https://github.com/ScottLogic.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# comlink-openfin\r\n\r\nComLink (https://github.com/GoogleChromeLabs/comlink) is a great way to simplify interacting with web workers or iFrames that otherwise require managing messages via [postMessage](https://developer.mozilla.org/en-US/docs/Web/API/Worker/postMessage). Using ComLink, a [Proxy](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy) is created on one side of a [MessageChannel](https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel) that can interact with an API on the other end of the channel as if it were a local, asynchronous API.\r\n\r\n![ComLink handles messaging between the front-end and web workers](./comlink.svg)\r\n\r\n[OpenFin](https://openfin.co/) builds on [Electron](https://www.electronjs.org/) and provides its own messaging channel (the Inter-Application Bus or IAB) that works between (and within) OpenFin applications allowing for cross-application integration and communication. It's a powerful mechanism with the same problems as web workers: the need to manage transceiving messages between the applications.\r\n\r\nAs ComLink already provides a simple mechanism for exposing an API over a message channel, this package adds a ComLink-compatible endpoint to do the same message transceiving via the OpenFin IAB. Using the comlink-openfin endpoint makes integrating different OpenFin applications easier by making an API available in one application directly accessible from a different application.\r\n\r\n![ComLink-OpenFin handles messaging between OpenFin applications](./comlink-openfin.svg)\r\n\r\nUsing the endpoint requires using the single exported function to construct it:\r\n\r\n```\r\nopenfinEndpoint(topic: string, remote?: fin.Identity): Comlink.Endpoint\r\n```\r\n\r\n- `topic`: The IAB topic name to send/receive messages using - this should be unique and follow OpenFin guidelines\r\n- `remote`: An optional OpenFin application uuid for the other end (sender or receiver) to enforce direct sender/receiver communication. If not specified, messages are broadcast to all topic listeners and received from any application on the same topic.\r\n\r\n## The exposed API\r\n\r\nHere we expose an API from one OpenFin application. Comlink and the comlink-openfin endpoint will handle the IAB messages as well as calling the API and returning any responses.\r\n\r\n```\r\nimport * as Comlink from \"comlink\";\r\nimport { openfinEndpoint } from \"comlink-openfin\";\r\n\r\nconst api: Api = {\r\n  callMe: (a: string): string =\u003e `Received \"${a}\"`;\r\n};\r\n\r\nComlink.expose(api, openfinEndpoint(\"Topic name\"));\r\n// If this was in a web worker, the call would be:\r\n//   Comlink.expose(api);\r\n```\r\n\r\n## The API client\r\n\r\nThis snippet, in a separate OpenFin application from above, creates the local proxy that will provide access to the other application's API. The common topic name allows the two applications (running on the same desktop) to communicate. As a result, the call to callMe (changed to async by ComLink) will automatically send a message from this application to the other application over the IAB and await the response, also returned via the IAB. The result is code like below - remote.callMe is called in this application but run in the other application.\r\n\r\n```\r\nimport * as Comlink from \"comlink\";\r\nimport { openfinEndpoint } from \"comlink-openfin\";\r\n\r\nconst remote = Comlink.wrap\u003cApi\u003e(openfinEndpoint(\"Topic name\"));\r\n// If the above was to call a web worker, the code would be:\r\n//   const worker = new Worker(\"worker.js\");\r\n//   const remote = Comlink.wrap\u003cApi\u003e(worker);\r\n\r\nconst response = await remote.callMe(\"My message\");\r\n```\r\n\r\n## Caveats\r\n\r\nComlink is designed for a single sender/receiver pair. Although specifying an OpenFin identity for the sender/receiver is optional, subscribing more than one sender/receiver using the same recipient is unlikely to work well (and will probably result in an infinite loop of malformed messages going back and forth between sender and receiver).\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscottlogic%2Fcomlink-openfin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscottlogic%2Fcomlink-openfin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscottlogic%2Fcomlink-openfin/lists"}