Catalog npm
Back to packageRELEASE DETAILS

0.0.7

npm

@0xgg/korona

**Korona = Kill Corona (virus)**, to memorate those who fight against the corona virus bravely in 2020. 仅已此库纪念 2020 年那些勇敢与新冠状病毒抗争的人们。

Published3 Aug 2022
Direct dependencies13
Transitive dependenciesNot calculated

README

Current package documentation

Korona

Korona = Kill Corona (virus), to memorate those who fight against the corona virus bravely in 2020.
仅已此库纪念 2020 年那些勇敢与新冠状病毒抗争的人们。

Minimal library to quickly construct decentralized p2p network

Installation

$ npm install @0xgg/korona

Demo

Simple Korona P2P Chat application:

https://0xgg.github.io/korona/

Usages

Check the index.html for example usages.

import { Korona, randomId } from "@0xgg/korona";

// Initialize the Korona P2P network
const peer = new Korona({
  peerId = randomId(), // The peerId, default to `randomId()`
  roomId = "public-rrom", // The roomId, default to `undefined`. If specified, then the peer will try to join the PubSub room. The peer might become the PubSub room host if there is no host yet.
  peerJSOptions: {
    // Follows https://peerjs.com/docs/#peer-options
  },
  maxPeers: 5, // Max number of peer connections that your peer can have
});

// Get ready to be used
peer.on("open", async (peerId) => {
  // When another peer just connected to you and tries to sync data with you,
  // you send some data back.
  peer.on("sync", async (send, peerId) => {
    return send({
      // ... data that you want to send
    });
  });

  // When a new peer joined the P2P network
  peer.on("peerJoined", async (peerId) => {
    console.log(`${peerId} joined`);
  });

  // When a peer left the P2P network
  peer.on("peerLeft", async (peerId) => {
    console.log(`${peerId} left`);
  });

  // When your peer gets disconnnected from the server but keep the connections alive in the P2P network. Will not be able to accept new peer connections.
  peer.on("disconnected", async () => {
    // Do something
  });

  // Emitted when the peer is destroyed and can no longer accept or create any new connections. At this time, the peer's connections will all be closed.
  peer.on("close", async () => {
    // Do something
  });

  // When there is peer error: https://peerjs.com/docs/#peeron-error
  peer.on("error", async (error) => {
    // Do something
  });

  // When you receive data from other peers
  peer.on("data", async (data: any) => {
    // Do something
  });

  // When the PubSub host changed,
  peer.on("pubsubHostChanged", async () => {
    // Do something
  });

  // Join the P2P network that other peer lives in
  await peer.requestConnection("target-peer-id");

  // Broadcast the data to all other peers in the P2P network
  await peer.broadcast({
    // Data goes here
  });

  // Send data to specific peer by id
  await peer.send("target-peer-id", {
    // Data goes here
  });
});

References

License

MIT

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 13

Native requirements
13 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
peerjs
Environment
{
  "local_name": "peerjs",
  "alias": false,
  "peer_metadata": null
}
^1.4.6runtime
typed-emitter
Environment
{
  "local_name": "typed-emitter",
  "alias": false,
  "peer_metadata": null
}
^2.1.0runtime
@rollup/plugin-json
Environment
{
  "local_name": "@rollup/plugin-json",
  "alias": false,
  "peer_metadata": null
}
^4.1.0development
@rollup/plugin-node-resolve
Environment
{
  "local_name": "@rollup/plugin-node-resolve",
  "alias": false,
  "peer_metadata": null
}
^13.3.0development
@rollup/plugin-typescript
Environment
{
  "local_name": "@rollup/plugin-typescript",
  "alias": false,
  "peer_metadata": null
}
^3.0.0development
@types/node
Environment
{
  "local_name": "@types/node",
  "alias": false,
  "peer_metadata": null
}
^13.7.0development
@types/peerjs
Environment
{
  "local_name": "@types/peerjs",
  "alias": false,
  "peer_metadata": null
}
^1.1.0development
http-server
Environment
{
  "local_name": "http-server",
  "alias": false,
  "peer_metadata": null
}
^14.1.1development
husky
Environment
{
  "local_name": "husky",
  "alias": false,
  "peer_metadata": null
}
^8.0.1development
rollup
Environment
{
  "local_name": "rollup",
  "alias": false,
  "peer_metadata": null
}
^2.77.2development
rollup-plugin-polyfill-node
Environment
{
  "local_name": "rollup-plugin-polyfill-node",
  "alias": false,
  "peer_metadata": null
}
^0.10.2development
tslib
Environment
{
  "local_name": "tslib",
  "alias": false,
  "peer_metadata": null
}
^2.4.0development
typescript
Environment
{
  "local_name": "typescript",
  "alias": false,
  "peer_metadata": null
}
^4.7.4development

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "integrity": "sha512-LliU1Z5vKgByosOEQdPwfToQiT5IG3ZHGjNzkCTSuqBUWt4PrO6GSUS0ZAKy6/WBl8G2Ilzm94ANhCyFrrqDHA==",
  "shasum": "0ed1d416fb787a491e3bbf535d7ae7592ec9b321",
  "tarball": "https://registry.npmjs.org/@0xgg/korona/-/korona-0.0.7.tgz",
  "fileCount": 86,
  "unpackedSize": 355054,
  "signatures": [
    {
      "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA",
      "sig": "MEUCIQCEHQNYYD7GGiwBBd/LZNduh2CDk1+F141GmR7E4drpYgIgYGrRn810NpKaQmiO+wRI3lGGzQ6unYctQPF20i9YtqU="
    }
  ],
  "npm-signature": "-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJi6p0LACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpcCQ/+MdF+40kL59JxL9s3LKP85b/4ih1QSEEHWli4QVtkgYsdJgtT\r\nkHaDLvoh8sHHig9vp9pNWJWXJmasLcA4GYvU7B1iuIhJqB5jHeKAqKO3qJFY\r\nxtvxk8FEM9Gme4CQkCgE/8mJ0aSXTGMtNgyjOHsirQLArh7LkqydzUD+P6c2\r\noksArFAoW0zLe9t6biEzjNq378CuzJlbEuzCfJ5NGC9Gu/peihmb8Kt8hrd7\r\nZMQpWBjWfp8yW2wF2CoHCtCL2C2LO4UDYbuCj9Koh34127iImygSEdhe3uMW\r\nz4NH55dbS0L7diIHBhjdnKoOpV4z5pEDOomL/x9diPdO5wQnKn+hPj36Xibb\r\nYFNlqGIPe0w6AzbextkPr2QSkn446D6KSMyVQex5YfxnQUMmFIi1TItIlH7Z\r\nVWaeFNcnMaWCCMoiOlJ629mr9JMvxRMSM6Yr5BsT28koH7MTmR6X//LSdTWt\r\nnwkSa8ZVEeBVer9ixBoqfB6o493fCx1BdvewERz5LlJzOd+Aws+spOEeNmlk\r\nYck3gajsuT9PCv1K1NiwOlHKxRAlJOM8F4SJEpFog4rmA2jzoUdjMNWulGn6\r\n9Xziq8SGp3Fckk5oyNYhYi81wiXW3k1Kq6ypRX8m+u1aQSHdF9bPuOO/YXoQ\r\nxl1fU+20JQvGjdm4GbrDZvnvk+O9tveTA5g=\r\n=vkxD\r\n-----END PGP SIGNATURE-----\r\n"
}

Repository

PENDING
0xgg/korona

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 21 Oct, 08:55 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:d9792069b6bcea4a7f2d65ddfc1c9b2b4872fcbd0cd8ce500911e57162489aa4

Other collected versions

0.0.63 Aug0.0.51 Aug0.0.41 Aug0.0.322 Jun0.0.222 Jun0.0.123 FebView all collected versions →