All Projects → vardius → peer-cdn

vardius / peer-cdn

Licence: MIT license
Lightweight library providing peer to peer CDN functionality

Programming Languages

javascript
184084 projects - #8 most used programming language
CSS
56736 projects
HTML
75241 projects

Projects that are alternatives of or similar to peer-cdn

Ios P2p Engine
Let your viewers become your unlimitedly scalable CDN.
Stars: ✭ 31 (-45.61%)
Mutual labels:  cdn, peer
p2p-cdn-sdk-android
Free p2p cdn android github sdk to reduce video streaming costs of live and on demand video using webrtc by upto 90% and improve scalability by 6x - 🚀 Vadootv 🚀
Stars: ✭ 39 (-31.58%)
Mutual labels:  cdn, peer
Android P2p Engine
Let your viewers become your unlimitedly scalable CDN.
Stars: ✭ 70 (+22.81%)
Mutual labels:  cdn, peer
Hlsjs P2p Engine
Let your viewers become your unlimitedly scalable CDN.
Stars: ✭ 759 (+1231.58%)
Mutual labels:  cdn, peer
P2p Cdn Sdk Javascript
Free p2p cdn github javascript sdk to reduce video streaming costs of live and on demand video using webrtc by upto 90% and improve scalability by 6x - 🚀 Vadootv 🚀
Stars: ✭ 158 (+177.19%)
Mutual labels:  cdn, peer
findcdn
findCDN is a tool created to help accurately identify what CDN a domain is using.
Stars: ✭ 64 (+12.28%)
Mutual labels:  cdn
mos-tls-tunnel
Archived. Check this out https://github.com/IrineSistiana/simple-tls
Stars: ✭ 21 (-63.16%)
Mutual labels:  cdn
ipx
High performance, secure and easy to use image proxy based on Sharp and libvips.
Stars: ✭ 683 (+1098.25%)
Mutual labels:  cdn
wepy-plugin-resources-cdn
上传图片到云存储wepy plugin
Stars: ✭ 38 (-33.33%)
Mutual labels:  cdn
valist
Web3-native software distribution. Publish and install executables, Docker images, WebAssembly, and more. Powered by Ethereum, IPFS, and Filecoin.
Stars: ✭ 107 (+87.72%)
Mutual labels:  cdn
workbox-cdn
Workbox Unofficial CDN and standalone NPM package.
Stars: ✭ 27 (-52.63%)
Mutual labels:  cdn
2nfm
Share your screen and computer's audio via WebRTC!
Stars: ✭ 29 (-49.12%)
Mutual labels:  peer
MCW-Media-AI
MCW Media AI
Stars: ✭ 22 (-61.4%)
Mutual labels:  cdn
CDN-Ansible
Welcome to github repository for Visual Cloud Delivery Network. This repository will provide the Ansible playbooks for installing the components of Visual Cloud Delivery Network.
Stars: ✭ 20 (-64.91%)
Mutual labels:  cdn
cdn
🚀 ✈️ 🚄 free CDN for everyone who wants to speed his website freely!😄
Stars: ✭ 16 (-71.93%)
Mutual labels:  cdn
builds
All surveyjs libraries and Editor builds
Stars: ✭ 15 (-73.68%)
Mutual labels:  cdn
do-spaces-action
📦Upload directories/files to DigitalOcean Spaces via GitHub Actions. Supports package/library versioning.
Stars: ✭ 30 (-47.37%)
Mutual labels:  cdn
BeechatNetwork
Open source, peer-to-peer, radio communication messaging.
Stars: ✭ 37 (-35.09%)
Mutual labels:  peer
school21
Как подготовиться к бассйну Школы 21: изучаем терминал, vim, работаем с gcc, norminette, git, пишем первую программу на Си.
Stars: ✭ 41 (-28.07%)
Mutual labels:  peer
binarium
Binarium cryptocurrency is the first one protected from ASICs
Stars: ✭ 14 (-75.44%)
Mutual labels:  peer

peer-cdn

Build Status codecov npm version npm downloads license

logo

Lightweight library providing peer to peer CDN functionality

📖 ABOUT

Contributors:

Want to contribute ? Feel free to send pull requests!

Have problems, bugs, feature ideas? We are using the github issue tracker to manage them.

📚 Documentation

For documentation (including examples), visit rafallorenz.com/peer-cdn

🚏 HOW TO USE

Installation

$ npm install peer-cdn

Basic example

main.js

"use strict";

import { PeerPlugin } from "peer-cdn";

if ("serviceWorker" in navigator) {
  // since sw does not support WebRTC yet
  // this is workaround to use it
  // we use PeerPlugin on client side
  const peerPlugin = new PeerPlugin({
    cacheName: CachePlugin.peerFetch + 1,
    timeoutAfter: 3000,
    servers: {
      iceServers: [
        {
          url: "stun:74.125.142.127:19302",
        },
      ],
    },
    constraints: {
      ordered: true,
    },
  });

  // Set up a listener for messages posted from the service worker.
  // The service worker is set to post a message to specific client only
  // so you should see this message event fire once.
  // You can force it to fire again by visiting this page in an Incognito window.
  navigator.serviceWorker.addEventListener("message", function (event) {
    const request = new Request(event.data.url);
    // mock sw event wrapping request with object
    const middleware = peerPlugin.getMiddleware({ request });

    // run get method of a created middleware
    middleware
      .get()
      .then(function (response) {
        // return response to a service worker
        event.ports[0].postMessage(response);
      })
      .catch(function (error) {
        // return response to a service worker
        event.ports[0].postMessage(null);
      });
  });

  navigator.serviceWorker
    .register("sw.js")
    .then(function (registration) {
      // Registration was successful
      console.log(
        "ServiceWorker registration successful with scope: ",
        registration.scope
      );
    })
    .catch(function (error) {
      console.error("Service Worker Error", error);
    });
}

sw.js

// import peer-cdn into service worker
self.importScripts("https://github.com/vardius/peer-cdn/blob/v1.0.5-beta/dist/index.js");

const { CachePlugin, DelegatePlugin, NetworkPlugin, strategies: { ordered }} = PeerCDN;

const cachePlugin = new CachePlugin({ version: 1 });
// since sw does not support WebRTC yet we use PeerPlugin on client side 
// and we delegate request to it with DelegatePlugin
const delegatePlugin = new DelegatePlugin({ timeoutAfter: 5000 });
const networkPlugin = new NetworkPlugin();

const cdn = new PeerCDN();

cdn.GET("/css/main.css", ordered,
    cachePlugin.getMiddleware,
    delegatePlugin.getMiddleware,
    networkPlugin.getMiddleware
);

// We need to register service worker events
// cdn.register() will add listeners for install, activate and fetch
// gaining required control
cdn.register();

📜 License

This package is released under the MIT license. See the complete license in the package

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].