{"id":15578373,"url":"https://github.com/block-core/blockcore-ws","last_synced_at":"2026-01-23T09:16:48.660Z","repository":{"id":245749003,"uuid":"819120675","full_name":"block-core/blockcore-ws","owner":"block-core","description":"Blockcore-ws is a WebSocket library designed to provide an easy and seamless way to implement WebSocket communication in various environments.","archived":false,"fork":false,"pushed_at":"2024-06-24T16:14:31.000Z","size":8,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-02-09T19:15:59.496Z","etag":null,"topics":["blockcore","browser","browsers","node","websocket","ws"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@blockcore/ws","language":"JavaScript","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/block-core.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":"2024-06-23T20:47:08.000Z","updated_at":"2024-06-24T16:16:23.000Z","dependencies_parsed_at":null,"dependency_job_id":"69f7d6b6-40ac-4700-b01f-f01833125778","html_url":"https://github.com/block-core/blockcore-ws","commit_stats":{"total_commits":6,"total_committers":3,"mean_commits":2.0,"dds":"0.33333333333333337","last_synced_commit":"176eb4e4128c367ce1ee8f4b309675e1c652ad37"},"previous_names":["block-core/blockcore-ws"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/block-core%2Fblockcore-ws","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/block-core%2Fblockcore-ws/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/block-core%2Fblockcore-ws/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/block-core%2Fblockcore-ws/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/block-core","download_url":"https://codeload.github.com/block-core/blockcore-ws/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239056335,"owners_count":19574428,"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":["blockcore","browser","browsers","node","websocket","ws"],"created_at":"2024-10-02T19:09:51.178Z","updated_at":"2026-01-23T09:16:43.627Z","avatar_url":"https://github.com/block-core.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"### Blockcore WebSocket (blockcore-ws) 🌐\n\n**Blockcore WebSocket (blockcore-ws)** is a WebSocket library designed to provide an easy and seamless way to implement WebSocket communication in various environments. It supports both Node.js and browser environments, making it versatile for different use cases.\n\n#### Features ✨\n- 🚀 Easy to use API\n- 🌍 Supports both Node.js and browser environments\n- 💡 Lightweight and efficient\n\n### Installation 📦\n\nTo install the `blockcore-ws` library, use the following npm command:\n\n```sh\nnpm install @blockcore/ws\n```\n\n### Usage 🚀\n\n#### Node.js Example 🖥️\n\nHere is an example of how to use `blockcore-ws` in a Node.js environment:\n\n1. Create a file named `app.js` and add the following code:\n\n   ```js\n   import WebSocket from '@blockcore/ws';\n\n   const ws = new WebSocket('wss://echo.websocket.org');\n\n   ws.on('open', function open() {\n     console.log('connected');\n     ws.send(Date.now());\n   });\n\n   ws.on('close', function close() {\n     console.log('disconnected');\n   });\n\n   ws.on('message', function incoming(data) {\n     console.log(`Roundtrip time: ${Date.now() - data} ms`);\n     ws.send(Date.now());\n   });\n   ```\n\n2. Ensure your `package.json` includes `\"type\": \"module\"` to use ES modules:\n\n   ```json\n   {\n     \"name\": \"your-project-name\",\n     \"version\": \"1.0.0\",\n     \"description\": \"\",\n     \"main\": \"app.js\",\n     \"type\": \"module\",\n     \"scripts\": {\n       \"start\": \"node app.js\"\n     },\n     \"dependencies\": {\n       \"@blockcore/ws\": \"^0.0.1\"\n     }\n   }\n   ```\n\n3. Install dependencies and run the example:\n\n   ```sh\n   npm install\n   npm start\n   ```\n\n#### Browser Example 🌐\n\nTo use `blockcore-ws` in a browser environment, follow these steps:\n\n1. Create an HTML file, `index.html`, and include a script to run the WebSocket code:\n\n   ```html\n   \u003c!DOCTYPE html\u003e\n   \u003chtml lang=\"en\"\u003e\n   \u003chead\u003e\n       \u003cmeta charset=\"UTF-8\"\u003e\n       \u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"\u003e\n       \u003ctitle\u003eBlockcore WebSocket Example\u003c/title\u003e\n   \u003c/head\u003e\n   \u003cbody\u003e\n       \u003cscript type=\"module\"\u003e\n           import WebSocket from './path/to/blockcore-ws/browser.js';\n\n           const ws = new WebSocket('wss://echo.websocket.org');\n\n           ws.onopen = () =\u003e {\n               console.log('connected');\n               ws.send(Date.now());\n           };\n\n           ws.onclose = () =\u003e {\n               console.log('disconnected');\n           };\n\n           ws.onmessage = (event) =\u003e {\n               console.log(`Roundtrip time: ${Date.now() - event.data} ms`);\n               ws.send(Date.now());\n           };\n       \u003c/script\u003e\n   \u003c/body\u003e\n   \u003c/html\u003e\n   ```\n\n2. Serve the HTML file using a local server. You can use `http-server` or any other local server tool:\n\n   ```sh\n   npm install -g http-server\n   http-server\n   ```\n\n3. Open the served HTML file in your browser to see the WebSocket in action.\n\n### Running Examples 🛠️\n\n#### Webpack Example 📦\n\nThe `blockcore-ws` library includes a Webpack example to demonstrate how to bundle and use the library with Webpack.\n\n1. Navigate to the example directory:\n\n   ```sh\n   cd path/to/blockcore-ws/example/webpack\n   ```\n\n2. Ensure your `webpack.config.js` is set up to use ES modules:\n\n   ```js\n   import path from 'path';\n\n   export default {\n     context: path.resolve(),\n     entry: {\n       app: path.join(path.resolve(), './app.js')\n     },\n     target: 'web',\n     output: {\n       path: path.resolve(),\n       filename: '[name].output.js',\n     }\n   };\n   ```\n\n3. Install dependencies and build the project:\n\n   ```sh\n   npm install\n   npm run build\n   ```\n\n4. Serve the output file using a local server and open it in a browser:\n\n   ```sh\n   http-server\n   ```\n\nWith these instructions, you should be able to install, run, and use the `blockcore-ws` library effectively in both Node.js and browser environments. Happy coding! 🎉","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblock-core%2Fblockcore-ws","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fblock-core%2Fblockcore-ws","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fblock-core%2Fblockcore-ws/lists"}