{"id":18863795,"url":"https://github.com/alexzhang1030/mche","last_synced_at":"2025-04-14T13:07:23.155Z","repository":{"id":231366104,"uuid":"781608024","full_name":"alexzhang1030/mche","owner":"alexzhang1030","description":"WebRTC \u0026 WebSocket Message Channel Helpers","archived":false,"fork":false,"pushed_at":"2025-04-07T02:48:04.000Z","size":600,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-10T09:11:18.475Z","etag":null,"topics":["typescript","webrtc","websocket"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/alexzhang1030.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":"2024-04-03T17:50:54.000Z","updated_at":"2025-04-07T02:48:03.000Z","dependencies_parsed_at":"2024-04-03T18:56:43.421Z","dependency_job_id":"78909294-e24a-443b-b741-5fa69d77a9e2","html_url":"https://github.com/alexzhang1030/mche","commit_stats":null,"previous_names":["alexzhang1030/mche"],"tags_count":41,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexzhang1030%2Fmche","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexzhang1030%2Fmche/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexzhang1030%2Fmche/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexzhang1030%2Fmche/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexzhang1030","download_url":"https://codeload.github.com/alexzhang1030/mche/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248190544,"owners_count":21062285,"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":["typescript","webrtc","websocket"],"created_at":"2024-11-08T04:38:34.312Z","updated_at":"2025-04-14T13:07:22.637Z","avatar_url":"https://github.com/alexzhang1030.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mche\n\n**M**essage **C**hannel **He**lpers\n\n\u003ca href=\"https://www.npmjs.com/package/mche\" target=\"_blank\" rel=\"noopener noreferrer\"\u003e\u003cimg src=\"https://badgen.net/npm/v/mche\" alt=\"NPM Version\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://www.npmjs.com/package/mche\" target=\"_blank\" rel=\"noopener noreferrer\"\u003e\u003cimg src=\"https://badgen.net/npm/dt/mche\" alt=\"NPM Downloads\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/alexzhang1030/mche/blob/main/LICENSE\" target=\"_blank\" rel=\"noopener noreferrer\"\u003e\u003cimg src=\"https://badgen.net/github/license/alexzhang1030/mche\" alt=\"License\" /\u003e\u003c/a\u003e\n\nThis is a library that provides some utilities that helps you to communicate data between different devices(in browser).\n\nIt's simple if you want to build a collaboration application by using `mche`.\n\nWe provide first-class support to `WebRTC` and `WebSocket`.\n\n\u003e ⚠️ WARNING: this project is not stable yet, please use it carefully. Expect breaking changes.\n\n## Installation\n\n```bash\npnpm i mche\n```\n\n## Options\n\nYou can choose `WebRTC` or `WebSocket` to communicate with other peers.\n\n```ts\ninterface MCHelperOptionsBase {\n  /**\n   * The ID of the peer.\n   */\n  id: string\n\n  /**\n   * Whether to print debug information.\n   * - `'verbose'`: print all debug information\n   * - `true`: print connection information\n   *\n   * @default false\n   */\n  debug?: boolean | 'verbose'\n\n  /**\n   * Room id.\n   *\n   * Same room id will be able to communicate with each other.\n   */\n  roomId: string\n}\n\ninterface MCHelperOptionsWebRTC extends MCHelperOptionsBase {\n  mode: 'webrtc'\n\n  /**\n   * The URL of the signaling server or ws instance.\n   * @example \"wss://example.com:8080\"\n   */\n  signalingServerUrlOrWsInstance: string | WebSocket\n\n  /**\n   * ICE servers.\n   * @default\n   * [\n   *  { urls: 'stun:stun.l.google.com:19302', }\n   * ]\n   */\n  iceServers?: RTCIceServer[]\n}\n\ninterface MCHelperOptionsWebSocket extends MCHelperOptionsBase {\n  mode: 'websocket'\n\n  /**\n   * The URL or ws instance.\n   * @example \"wss://example.com:8080\"\n   */\n  urlOrWsInstance: string | WebSocket\n}\n\ntype MCHelperOptions = MCHelperOptionsWebRTC | MCHelperOptionsWebSocket\n```\n\n## Usage\n\n```ts\nimport { MCHelper } from 'mche'\n\nconst mch = new MCHelper({\n  // ...options\n})\n\nmche.onMessageChannelReady(() =\u003e {\n  // MessageChannel is ready...\n})\n\nmch.broadcast('hello')\n\nmch.onBroadcast((data) =\u003e {\n  console.log(data)\n})\n\n// Call close if you want to close the connection.\nmch.close()\n```\n\n### Signaling Server\n\nYou can use this [signaling server example](https://github.com/alexzhang1030/mche-signaler). Or write your own signaling server.\n\n#### Utilities\n\n```ts\nimport { withHandleMetaEvent } from 'mche/server'\n\nconst {\n  getHeartbeatResponse,\n  isHeartbeatRequestParsed,\n  getMetaCloseResponse,\n  getMetaRegisterAcceptResponse,\n  getMetaRegisterResponse,\n  getMetaRegisterEventPayload,\n  isMetaRegisterEvent,\n  tryParseMetaEvent,\n} = withHandleMetaEvent()\n```\n\nYou can use these functions to implement your own signaling server.\n\nBut recommended to checkout the [signaling server example](https://github.com/alexzhang1030/mche-signaler)\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexzhang1030%2Fmche","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexzhang1030%2Fmche","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexzhang1030%2Fmche/lists"}