Giter Club home page Giter Club logo

peer-data's Introduction

PeerData

Build Status npm version npm downloads license

logo

PeerData is a library for bidirectional peer-to-peer transfers of arbitrary data using RTCDataChannel. Simple WebRTC wrapper providing data channel abstraction.

WebRTC needs a messaging service to set up and maintain a WebRTC call.

The sender and receiver RTCPeerConnections run in web pages on different devices, and we need a way for them to communicate metadata. For this, we use a signaling server: a server that can pass messages between WebRTC clients (peers).

PeerDataServer - An ready to use example of signaling server on Node using socket.io.

πŸ“– 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-data

🚏 HOW TO USE

  1. Chat Example
  2. React Chat Example
  3. React Hook

Installation

$ npm install peer-data

Basic example

import PeerData, { EventDispatcher, SocketChannel } from 'peer-data';

const constraints = {ordered: true};
const servers = {
  iceServers: [
    {urls: "stun:stun.1.google.com:19302"}
  ]
};

const dispatcher = new EventDispatcher();
const peerData = new PeerData(dispatcher, servers, constraints);
const signaling = new SocketChannel(dispatcher, 'http://localhost:8080');

const room = peerData.connect('test-room');

room.on("participant", participant => {
  participant.on("message", payload => console.log("message", payload));

  participant.send('Hi mate! this is private message.');
})

For how to disconnect, close connection and handle errors please check documentation.

πŸ“œ License

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

peer-data's People

Contributors

dependabot[bot] avatar vardius avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

peer-data's Issues

require is not defined

I'm not sure, if the npm package is supposed to be usable as JavaScript module, but if I use

<script type="module" src="node_modules/peer-data/dist/index.es.js"></script>

I get

Uncaught ReferenceError: require is not definedat SocketChannel.ts:5

Is this a bug or do I misunderstand how index.es.js is supposed to be used? πŸ˜…

connectionState missing in types

WebRTC types does not have connectionState property defined on RTCPeerConnection object.

Need to find solution to fix it, or w8 for types update.
semantic error TS2339 Property 'connectionState' does not exist on type 'RTCPeerConnection'.

type error in example

The example on the website

import PeerData, { EventDispatcher, SocketChannel } from 'peer-data';

const servers = {
  iceServers: [
    {url: "stun:stun.1.google.com:19302"}
  ]
};

const dispatcher = new EventDispatcher();
const peerData = new PeerData(dispatcher, servers);
const signaling = new SocketChannel(dispatcher, 'http://localhost:8080');

room.on("participant", participant => {
  participant.on("message", payload => console.log("message", payload));

  participant.send('Hi mate! this is private message.');
})

compiles with errors in TypeScript 3.9.3

src/index.ts:10:43 - error TS2345: Argument of type '{ iceServers: { url: string; }[]; }' is not assignable to parameter of type 'RTCConfiguration'.
  Types of property 'iceServers' are incompatible.
    Type '{ url: string; }[]' is not assignable to type 'RTCIceServer[]'.
      Property 'urls' is missing in type '{ url: string; }' but required in type 'RTCIceServer'.

10 const peerData = new PeerData(dispatcher, servers);
                                             ~~~~~~~

  node_modules/typescript/lib/lib.dom.d.ts:1291:5
    1291     urls: string | string[];
             ~~~~
    'urls' is declared here.

src/index.ts:13:1 - error TS2304: Cannot find name 'room'.

13 room.on("participant", participant => {
   ~~~~

minimal example

I'd really appreciate a minimal running example how to send data P2P using peer-data and peer-data-server libraries (basic use case). The README.md mentions how to use the library with different frame works. The website shows an example without explanation what it does or what to expect: Should I get output on the console if I open the page twice? The same applies to the Basic Example in the documentation.

Error on PeerDataProvider

Hi Vardius,

Great package!
I'm using the "PeerDataProvider" , just as described in React Chat demo. It's working fine on Localhost, but when hosted in Azure I get the error:
react_devtools_backend.js:6 TypeError: Cannot read property 'register' of undefined
at new (SocketChannel.ts:13)
at useSignaling.tsx:10
at o (PeerDataProvider.tsx:14)
at qc (react-dom.production.min.js:153)
at mo (react-dom.production.min.js:261)
at fs (react-dom.production.min.js:246)
at os (react-dom.production.min.js:246)
at Jo (react-dom.production.min.js:239)
at react-dom.production.min.js:123
at t.unstable_runWithPriority (scheduler.production.min.js:19)

This is the code of the Provider:
<PeerDataProvider
servers={{
iceServers: [
{
urls: ["stun:stun.1.google.com:19302", "stun:74.125.142.127:19302"],
},
{
urls: "turn:turn.bistri.com:80",
credential: "homeo",
username: "homeo",
},
],
}}
constraints={{ ordered: true }}
signaling={{
url:
process.env.REACT_APP_PROXY_SERVER, //https://mecureserver.azurewebsites.net/ (Using peer-server)
}}
>

What I'm missing ?

Kid regards,

Paul

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.