{"id":16441851,"url":"https://github.com/chuchencheng/wsmock-js","last_synced_at":"2025-03-21T04:33:42.957Z","repository":{"id":32418071,"uuid":"130361547","full_name":"ChuChencheng/wsmock-js","owner":"ChuChencheng","description":"Mock WebSocket in the browser without a server.","archived":false,"fork":false,"pushed_at":"2022-12-10T20:33:15.000Z","size":2445,"stargazers_count":6,"open_issues_count":17,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-17T21:42:19.137Z","etag":null,"topics":["mock","websocket"],"latest_commit_sha":null,"homepage":null,"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/ChuChencheng.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-04-20T12:51:12.000Z","updated_at":"2025-01-23T06:37:27.000Z","dependencies_parsed_at":"2023-01-14T21:15:19.169Z","dependency_job_id":null,"html_url":"https://github.com/ChuChencheng/wsmock-js","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChuChencheng%2Fwsmock-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChuChencheng%2Fwsmock-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChuChencheng%2Fwsmock-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ChuChencheng%2Fwsmock-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ChuChencheng","download_url":"https://codeload.github.com/ChuChencheng/wsmock-js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244738894,"owners_count":20501931,"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":["mock","websocket"],"created_at":"2024-10-11T09:15:35.942Z","updated_at":"2025-03-21T04:33:42.651Z","avatar_url":"https://github.com/ChuChencheng.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# wsmock-js\n\n[![npm](https://img.shields.io/npm/v/wsmock-js.svg)](https://www.npmjs.com/package/wsmock-js)\n[![Build Status](https://travis-ci.org/ChuChencheng/wsmock-js.svg?branch=master)](https://travis-ci.org/ChuChencheng/wsmock-js)\n\nMock WebSocket in the browser without a server.\n\n# Getting-started\n\n## Install\n\nyarn:\n\n`yarn add wsmock-js --dev`\n\nwith \u0026lt;script\u0026gt; tag:\n\n`\u003cscript src=\"wsmock.min.js\"\u003e\u003c/script\u003e`\n\n## Define mock settings\n\n```javascript\nimport wsm from 'wsmock-js'\n\nwsm.mock({\n  url: 'ws://some.mock.url',\n  sendInterval: 'onreceive',\n  receiver (data) { // 'data' is sent by webSocket.send in browser\n    console.log(data)\n  },\n  sender () { // Simulating server send\n    this.response = 'This is a message sent by server.'\n  },\n})\n```\n\nThen just use WebSocket as usual.\n\n# API\n\n```javascript\n/**\n * Add a new mock setting.\n */\nwsm.mock({\n  // [String|RegExp] Mock url. Note: Url validation will not proceed if WHATWG URL API is not supported by browser (e.g. IE).\n  url: /wss:\\/\\/xxx\\.(xxxx|regexp)\\.xxx/,\n\n  /** \n   * [Array|Number|String] Define when server would send a message to the browser. \n   * [Array]: A set of numbers representing interval time.\n   * [Number]: Interval time.\n   * [String]: 'onreceive', server send message imediately once receive data from the browser.\n   */\n  sendInterval: 1000,\n\n  // [Function] Simulate receive method invoked by server.\n  receiver (data) {\n    \n  },\n\n  // [Function] Simulate send method invoked by server.\n  // * Note: You'd better not use an arrow function in case that 'this' does not point to setting object.\n  sender () {\n    this.response = 'This is a message sent by server.'\n  },\n})\n\n/**\n * Global settings of wsmock-js\n */\nwsm.config({\n  // [Number] Default: '100', time (ms) cost of connection.\n  CONNECTING_TIME: 100,\n\n  // [Number] Default: '100', time (ms) cost of disconnection.\n  CLOSING_TIME: 100,\n\n  // [Number] Default: '1 * 1024 * 1024', send rate, bytes per second\n  SEND_RATE: 1 * 1024 * 1024,\n})\n```\n\n# Attention\n\n**THIS MODULE IS USED TO MOCK WEBSOCKET BEHAVIORS IN DEVELOPMENT**\n\n**DO NOT USE IT IN PRODUCTION**\n\n# Todo\n\n* [x] Mock url regular expression support\n* [ ] Socket.io support?\n* [ ] Better test cases\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchuchencheng%2Fwsmock-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchuchencheng%2Fwsmock-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchuchencheng%2Fwsmock-js/lists"}