{"id":16767443,"url":"https://github.com/vardius/peer-cdn","last_synced_at":"2025-03-17T02:31:27.786Z","repository":{"id":21790349,"uuid":"94043063","full_name":"vardius/peer-cdn","owner":"vardius","description":"Lightweight library providing peer to peer CDN functionality","archived":false,"fork":false,"pushed_at":"2023-03-04T03:47:41.000Z","size":31895,"stargazers_count":68,"open_issues_count":18,"forks_count":12,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-02-27T16:44:29.591Z","etag":null,"topics":["cache","cdn","peer","peer-cdn"],"latest_commit_sha":null,"homepage":"https://rafallorenz.com/peer-cdn","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/vardius.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":".github/CODE_OF_CONDUCT.md","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},"funding":{"github":["vardius"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2017-06-12T01:23:37.000Z","updated_at":"2024-05-30T07:01:55.000Z","dependencies_parsed_at":"2024-10-27T11:53:26.671Z","dependency_job_id":"8abf78e1-3c7e-47a2-a69e-9d0a200116a0","html_url":"https://github.com/vardius/peer-cdn","commit_stats":{"total_commits":151,"total_committers":2,"mean_commits":75.5,"dds":"0.052980132450331174","last_synced_commit":"79efa6a40ec51e611fa112bd710045b4bc746e92"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vardius%2Fpeer-cdn","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vardius%2Fpeer-cdn/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vardius%2Fpeer-cdn/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vardius%2Fpeer-cdn/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vardius","download_url":"https://codeload.github.com/vardius/peer-cdn/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243837011,"owners_count":20355813,"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":["cache","cdn","peer","peer-cdn"],"created_at":"2024-10-13T06:09:10.021Z","updated_at":"2025-03-17T02:31:25.756Z","avatar_url":"https://github.com/vardius.png","language":"JavaScript","funding_links":["https://github.com/sponsors/vardius"],"categories":[],"sub_categories":[],"readme":"# peer-cdn\n\n[![Build Status](https://travis-ci.org/vardius/peer-cdn.svg?branch=master)](https://travis-ci.org/vardius/peer-cdn)\n[![codecov](https://codecov.io/gh/vardius/peer-cdn/branch/master/graph/badge.svg)](https://codecov.io/gh/vardius/peer-cdn)\n[![npm version](https://img.shields.io/npm/v/peer-cdn.svg)](https://www.npmjs.com/package/peer-cdn)\n[![npm downloads](https://img.shields.io/npm/dm/peer-cdn.svg)](https://www.npmjs.com/package/peer-cdn)\n[![license](https://img.shields.io/github/license/vardius/peer-cdn.svg)](LICENSE.md)\n\n\u003cimg align=\"right\" height=\"180px\" src=\"website/src/static/img/logo.png\" alt=\"logo\" /\u003e\n\nLightweight library providing peer to peer CDN functionality\n\n📖 ABOUT\n==================================================\nContributors:\n\n* [Rafał Lorenz](https://rafallorenz.com)\n\nWant to contribute ? Feel free to send pull requests!\n\nHave problems, bugs, feature ideas?\nWe are using the github [issue tracker](https://github.com/vardius/peer-cdn/issues) to manage them.\n\n## 📚 Documentation\n\nFor **documentation** (_including examples_), **visit [rafallorenz.com/peer-cdn](https://rafallorenz.com/peer-cdn)**\n\n🚏 HOW TO USE\n==================================================\n\n## Installation\n```bash\n$ npm install peer-cdn\n```\n\n## Basic example\n\n### main.js\n\n```js\n\"use strict\";\n\nimport { PeerPlugin } from \"peer-cdn\";\n\nif (\"serviceWorker\" in navigator) {\n  // since sw does not support WebRTC yet\n  // this is workaround to use it\n  // we use PeerPlugin on client side\n  const peerPlugin = new PeerPlugin({\n    cacheName: CachePlugin.peerFetch + 1,\n    timeoutAfter: 3000,\n    servers: {\n      iceServers: [\n        {\n          url: \"stun:74.125.142.127:19302\",\n        },\n      ],\n    },\n    constraints: {\n      ordered: true,\n    },\n  });\n\n  // Set up a listener for messages posted from the service worker.\n  // The service worker is set to post a message to specific client only\n  // so you should see this message event fire once.\n  // You can force it to fire again by visiting this page in an Incognito window.\n  navigator.serviceWorker.addEventListener(\"message\", function (event) {\n    const request = new Request(event.data.url);\n    // mock sw event wrapping request with object\n    const middleware = peerPlugin.getMiddleware({ request });\n\n    // run get method of a created middleware\n    middleware\n      .get()\n      .then(function (response) {\n        // return response to a service worker\n        event.ports[0].postMessage(response);\n      })\n      .catch(function (error) {\n        // return response to a service worker\n        event.ports[0].postMessage(null);\n      });\n  });\n\n  navigator.serviceWorker\n    .register(\"sw.js\")\n    .then(function (registration) {\n      // Registration was successful\n      console.log(\n        \"ServiceWorker registration successful with scope: \",\n        registration.scope\n      );\n    })\n    .catch(function (error) {\n      console.error(\"Service Worker Error\", error);\n    });\n}\n```\n\n### sw.js\n\n```js\n// import peer-cdn into service worker\nself.importScripts(\"https://github.com/vardius/peer-cdn/blob/v1.0.5-beta/dist/index.js\");\n\nconst { CachePlugin, DelegatePlugin, NetworkPlugin, strategies: { ordered }} = PeerCDN;\n\nconst cachePlugin = new CachePlugin({ version: 1 });\n// since sw does not support WebRTC yet we use PeerPlugin on client side \n// and we delegate request to it with DelegatePlugin\nconst delegatePlugin = new DelegatePlugin({ timeoutAfter: 5000 });\nconst networkPlugin = new NetworkPlugin();\n\nconst cdn = new PeerCDN();\n\ncdn.GET(\"/css/main.css\", ordered,\n    cachePlugin.getMiddleware,\n    delegatePlugin.getMiddleware,\n    networkPlugin.getMiddleware\n);\n\n// We need to register service worker events\n// cdn.register() will add listeners for install, activate and fetch\n// gaining required control\ncdn.register();\n```\n\n📜 [License](LICENSE.md)\n-------\n\nThis package is released under the MIT license. See the complete license in the package\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvardius%2Fpeer-cdn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvardius%2Fpeer-cdn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvardius%2Fpeer-cdn/lists"}